fix(authorization): disable user list api call if not authorised [EE-5825] (#10379)

* disable user list api call if not authorised

* fix tests

* fix lint issues
pull/10388/head
Prabhat Khera 2023-09-27 10:12:30 +13:00 committed by GitHub
parent 702391cf88
commit 3ff2f64930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -83,7 +83,7 @@ for (let i = 0; i < inheritanceTests.length; i += 1) {
});
}
test('when resource is limited to specific users, show comma separated list of their names', async () => {
test('when resource is limited to specific users, show number of users', async () => {
const users = createMockUsers(10, Role.Standard);
server.use(rest.get('/api/users', (req, res, ctx) => res(ctx.json(users))));
@ -107,7 +107,7 @@ test('when resource is limited to specific users, show comma separated list of t
expect(queryByText(/Authorized users/)).toBeVisible();
await expect(findByLabelText('authorized-users')).resolves.toHaveTextContent(
restrictedToUsers.map((user) => user.Username).join(', ')
`${restrictedToUsers.length} users`
);
});

View File

@ -52,6 +52,7 @@ export function AccessControlPanel({
<AccessControlPanelDetails
resourceType={resourceType}
resourceControl={resourceControl}
isAuthorisedToFetchUsers={isAdmin || isLeaderOfAnyRestrictedTeams}
/>
{!isEditDisabled && !isEditMode && (

View File

@ -24,11 +24,13 @@ import { ResourceControlViewModel } from '../models/ResourceControlViewModel';
interface Props {
resourceControl?: ResourceControlViewModel;
resourceType: ResourceControlType;
isAuthorisedToFetchUsers?: boolean;
}
export function AccessControlPanelDetails({
resourceControl,
resourceType,
isAuthorisedToFetchUsers = false,
}: Props) {
const inheritanceMessage = getInheritanceMessage(
resourceType,
@ -41,7 +43,10 @@ export function AccessControlPanelDetails({
TeamAccesses: restrictedToTeams = [],
} = resourceControl || {};
const users = useAuthorizedUsers(restrictedToUsers.map((ra) => ra.UserId));
const users = useAuthorizedUsers(
restrictedToUsers.map((ra) => ra.UserId),
isAuthorisedToFetchUsers
);
const teams = useAuthorizedTeams(restrictedToTeams.map((ra) => ra.TeamId));
const teamsLength = teams.data ? teams.data.length : 0;