Skip to content

Commit

Permalink
- DEVSU-2300
Browse files Browse the repository at this point in the history
- Set rules enforcing that admin users can add new user to all projects and groups, but managers can only add new user to non admin groups and the same projects they have
  • Loading branch information
bnguyen-bcgsc committed May 24, 2024
1 parent ef86c44 commit f51ac60
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { UserType, GroupType, UserProjectsType } from '@/common';
import snackbar from '@/services/SnackbarUtils';
import AsyncButton from '@/components/AsyncButton';
import UserAutocomplete from '@/components/UserAutocomplete';
import useSecurity from '@/hooks/useSecurity';
import useResource from '@/hooks/useResource';

import './index.scss';

Expand Down Expand Up @@ -73,6 +75,8 @@ const AddEditUserDialog = ({
const [groupOptions, setGroupOptions] = useState<GroupType[]>([]);
const [dialogTitle, setDialogTitle] = useState<string>('');
const [isApiCalling, setIsApiCalling] = useState(false);
const { userDetails } = useSecurity();
const { adminAccess } = useResource();

// Grab project and groups
useEffect(() => {
Expand All @@ -83,13 +87,20 @@ const AddEditUserDialog = ({
api.get('/user/group').request(),
]);
if (!cancelled) {
setProjectOptions(projectsResp);
setGroupOptions(groupsResp);
const nonAdminGroups = [];
groupsResp.forEach((group) => (group.name !== 'admin' ? nonAdminGroups.push(group) : null));
if (adminAccess) {
setProjectOptions(projectsResp);
setGroupOptions(groupsResp);
} else {
setProjectOptions(userDetails.projects);
setGroupOptions(nonAdminGroups);
}
}
};
getData();
return function cleanup() { cancelled = true; };
}, [editData]);
}, [adminAccess, userDetails.projects]);

// When params changed
useEffect(() => {
Expand Down

0 comments on commit f51ac60

Please sign in to comment.