Skip to content

Commit

Permalink
fixing team member access to comments (#2000)
Browse files Browse the repository at this point in the history
* updates on engagement publish

* update email template

* adding action drop down

* updated changes for User Management

* access user details page for users without a role

* updating variable name

* updating the schema

* updating as per review comments

* updating schema

* adding changes for clone and delete

* fixing linting

* update

* fix for report setting on analytics

* fixing lint

* fixing update on submission

* fixing linting

* updating rejection email arguments

* fixing team member access to comments

* updating conversion to integer
  • Loading branch information
VineetBala-AOT authored Aug 11, 2023
1 parent d89c0a3 commit 9766fa9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CommentListingContext } from './CommentListingContext';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { useAppSelector } from 'hooks';
import { USER_ROLES } from 'services/userService/constants';
import { USER_GROUP } from 'models/user';

const Submissions = () => {
const {
Expand All @@ -32,7 +33,7 @@ const Submissions = () => {
pageInfo,
loading,
} = useContext(CommentListingContext);
const { roles } = useAppSelector((state) => state.user);
const { roles, userDetail, assignedEngagements } = useAppSelector((state) => state.user);
const { state } = useLocation();
const [isExporting, setIsExporting] = useState(false);
const [isAdvancedSearchOpen, setIsAdvancedSearchOpen] = useState(Boolean(state));
Expand Down Expand Up @@ -60,7 +61,11 @@ const Submissions = () => {
label: 'ID',
allowSort: true,
renderCell: (row) => {
if (roles.includes(USER_ROLES.REVIEW_COMMENTS)) {
if (
roles.includes(USER_ROLES.REVIEW_COMMENTS) ||
(assignedEngagements.includes(Number(survey.engagement_id)) &&
userDetail.groups?.includes('/' + USER_GROUP.TEAM_MEMBER.value))
) {
return (
<MuiLink component={Link} to={`/surveys/${Number(row.survey_id)}/submissions/${row.id}/review`}>
{row.id}
Expand Down
9 changes: 7 additions & 2 deletions met-web/src/components/comments/admin/textListing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { getSubmissionPage } from 'services/submissionService';
import { SurveySubmission } from 'models/surveySubmission';
import { formatDate } from 'components/common/dateHelper';
import { USER_ROLES } from 'services/userService/constants';
import { USER_GROUP } from 'models/user';

const CommentTextListing = () => {
const { roles } = useAppSelector((state) => state.user);
const { roles, userDetail, assignedEngagements } = useAppSelector((state) => state.user);
const badgeStyle: React.CSSProperties = {
padding: 0,
margin: 0,
Expand Down Expand Up @@ -90,7 +91,11 @@ const CommentTextListing = () => {
label: 'ID',
allowSort: true,
renderCell: (row) => {
if (roles.includes(USER_ROLES.REVIEW_COMMENTS)) {
if (
roles.includes(USER_ROLES.REVIEW_COMMENTS) ||
(assignedEngagements.includes(Number(row.engagement_id)) &&
userDetail.groups?.includes('/' + USER_GROUP.TEAM_MEMBER.value))
) {
return (
<MuiLink component={Link} to={`/surveys/${Number(row.survey_id)}/submissions/${row.id}/review`}>
{row.id}
Expand Down
2 changes: 2 additions & 0 deletions met-web/src/models/surveySubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SurveySubmission {
notify_email?: boolean;
comments?: Comment[];
staff_note: StaffNote[];
engagement_id: number;
}

export interface PublicSubmission {
Expand All @@ -33,5 +34,6 @@ export const createDefaultSubmission = (): SurveySubmission => {
reviewed_by: '',
comment_status_id: 1,
staff_note: [],
engagement_id: 0,
};
};
5 changes: 4 additions & 1 deletion met-web/src/routes/AuthGate.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import { useAppSelector } from 'hooks';
import { useLocation, Navigate, Outlet } from 'react-router-dom';
import { USER_GROUP } from 'models/user';

const AuthGate = ({ allowedRoles }: { allowedRoles: string[] }) => {
const permissions = useAppSelector((state) => state.user.roles);
const userGroups = useAppSelector((state) => state.user.userDetail.groups);
const location = useLocation();

const scopesMap: { [scope: string]: boolean } = {};
allowedRoles.forEach((scope) => {
scopesMap[scope] = true;
});

return permissions.some((permission) => scopesMap[permission]) ? (
return permissions.some((permission) => scopesMap[permission]) ||
userGroups?.includes('/' + USER_GROUP.TEAM_MEMBER.value) ? (
<Outlet />
) : (
<Navigate to="/unauthorized" state={{ from: location }} replace />
Expand Down
1 change: 1 addition & 0 deletions met-web/src/services/userService/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface UserDetail {
email_verified?: boolean;
preferred_username?: string;
user?: User;
groups?: string[];
}

export interface UserAuthentication {
Expand Down

0 comments on commit 9766fa9

Please sign in to comment.