1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 05:45:22 +02:00

fix(permissions): non admin access to view users [EE-5825] (#10352)

* fix non admin access to view users

* review comments and fix tests
This commit is contained in:
Prabhat Khera 2023-09-25 09:08:26 +13:00 committed by GitHub
parent 13c48ab961
commit 3c4660bbf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 11 deletions

View file

@ -8,7 +8,6 @@ import { UserId } from '@/portainer/users/types';
import { TeamId } from '@/react/portainer/users/teams/types';
import { useTeams } from '@/react/portainer/users/teams/queries';
import { useUsers } from '@/portainer/users/queries';
import { useCurrentUser } from '@/react/hooks/useUser';
import { pluralize } from '@/portainer/helpers/strings';
import { Link } from '@@/Link';
@ -31,8 +30,6 @@ export function AccessControlPanelDetails({
resourceControl,
resourceType,
}: Props) {
const { isAdmin } = useCurrentUser();
const inheritanceMessage = getInheritanceMessage(
resourceType,
resourceControl
@ -44,10 +41,7 @@ export function AccessControlPanelDetails({
TeamAccesses: restrictedToTeams = [],
} = resourceControl || {};
const users = useAuthorizedUsers(
restrictedToUsers.map((ra) => ra.UserId),
isAdmin
);
const users = useAuthorizedUsers(restrictedToUsers.map((ra) => ra.UserId));
const teams = useAuthorizedTeams(restrictedToTeams.map((ra) => ra.TeamId));
const teamsLength = teams.data ? teams.data.length : 0;
@ -62,8 +56,8 @@ export function AccessControlPanelDetails({
)} you are not part of`;
}
const userMessage = isAdmin
? (users.data && users.data.join(', ')) || ''
const userMessage = users.data
? users.data.join(', ')
: `${restrictedToUsers.length} ${pluralize(
restrictedToUsers.length,
'user'

View file

@ -18,7 +18,7 @@ export function ListView() {
<>
<PageHeader title="Teams" breadcrumbs={[{ label: 'Teams management' }]} />
{usersQuery.data && teamsQuery.data && (
{isAdmin && usersQuery.data && teamsQuery.data && (
<CreateTeamForm users={usersQuery.data} teams={teamsQuery.data} />
)}