Skip to content

Commit 0821f65

Browse files
authored
Fix that ensures only users with right permissions see Available Users in the workspaces tab (#1404)
1 parent 644e3fc commit 0821f65

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

web_ui/src/pages/user-management/users/workspace-users/available-workspace-users.component.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ describe('AvailableWorkspaceUsers', () => {
152152
);
153153
});
154154

155-
it('does not render the Add action when user lacks permission', async () => {
155+
it('does not render the Available users section when user lacks permission', async () => {
156156
renderAvailableWorkspaceUsers({ activeUserRoles: onlyOrgContributorRoles, manageUsersRoles: true });
157157

158158
expect(
159-
await screen.findByRole('heading', { name: /available users to add to this workspace/i })
160-
).toBeInTheDocument();
159+
screen.queryByRole('heading', { name: /available users to add to this workspace/i })
160+
).not.toBeInTheDocument();
161161
expect(screen.queryByRole('button', { name: /add u2@intel.com to workspace/i })).not.toBeInTheDocument();
162162
});
163163

web_ui/src/pages/user-management/users/workspace-users/available-workspace-users.component.tsx

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,58 +84,58 @@ export const AvailableWorkspaceUsers = ({ workspaceId, activeUser }: AvailableWo
8484
};
8585

8686
const AddContributorAction = ({ user }: { user: User }) => (
87-
<HasPermission
88-
operations={[OPERATION.ADD_USER_TO_WORKSPACE]}
89-
resources={[{ type: RESOURCE_TYPE.WORKSPACE, id: workspaceId }]}
87+
<ActionButton
88+
aria-label={`Add ${user.email} to workspace`}
89+
onPress={() => handleAddUserWithRole(user, USER_ROLE.WORKSPACE_CONTRIBUTOR)}
90+
id={`${user.id}-add-to-workspace`}
9091
>
91-
<ActionButton
92-
aria-label={`Add ${user.email} to workspace`}
93-
onPress={() => handleAddUserWithRole(user, USER_ROLE.WORKSPACE_CONTRIBUTOR)}
94-
id={`${user.id}-add-to-workspace`}
95-
>
96-
{updateUserRoleMutation.isPending || updateMemberRoleMutation.isPending ? (
97-
<Loading mode={'inline'} size={'S'} />
98-
) : (
99-
<Add />
100-
)}
101-
</ActionButton>
102-
</HasPermission>
92+
{updateUserRoleMutation.isPending || updateMemberRoleMutation.isPending ? (
93+
<Loading mode={'inline'} size={'S'} />
94+
) : (
95+
<Add />
96+
)}
97+
</ActionButton>
10398
);
10499

105100
if (availableUsers.length === 0) {
106101
return <></>;
107102
}
108103

109104
return (
110-
<Flex direction={'column'} gap={'size-200'}>
111-
<Heading level={3}>Available users to add to this workspace</Heading>
112-
<View>
113-
<UsersTable
114-
tableId={'available-workspace-users-table-id'}
115-
isFetchingNextPage={isFetchingNextPage}
116-
isLoading={isLoading}
117-
totalCount={orgTotal}
118-
users={availableUsers}
119-
hasFilters={false}
120-
activeUser={activeUser}
121-
getNextPage={async () => {
122-
// Load more from both lists to keep difference accurate
123-
await Promise.all([getNextOrgPage(), getNextWsPage()]);
124-
}}
125-
usersQueryParams={{}}
126-
setUsersQueryParams={() => {}}
127-
UserActions={({ user }) => <AddContributorAction user={user} />}
128-
ignoredColumns={[
129-
USERS_TABLE_COLUMNS.LAST_LOGIN,
130-
USERS_TABLE_COLUMNS.REGISTRATION_STATUS,
131-
USERS_TABLE_COLUMNS.ROLES,
132-
]}
133-
resourceId={workspaceId}
134-
workspaces={workspaces}
135-
isProjectUsersTable={false}
136-
organizationId={organizationId}
137-
/>
138-
</View>
139-
</Flex>
105+
<HasPermission
106+
operations={[OPERATION.ADD_USER_TO_WORKSPACE]}
107+
resources={[{ type: RESOURCE_TYPE.WORKSPACE, id: workspaceId }]}
108+
>
109+
<Flex direction={'column'} gap={'size-200'}>
110+
<Heading level={3}>Available users to add to this workspace</Heading>
111+
<View>
112+
<UsersTable
113+
tableId={'available-workspace-users-table-id'}
114+
isFetchingNextPage={isFetchingNextPage}
115+
isLoading={isLoading}
116+
totalCount={orgTotal}
117+
users={availableUsers}
118+
hasFilters={false}
119+
activeUser={activeUser}
120+
getNextPage={async () => {
121+
// Load more from both lists to keep difference accurate
122+
await Promise.all([getNextOrgPage(), getNextWsPage()]);
123+
}}
124+
usersQueryParams={{}}
125+
setUsersQueryParams={() => {}}
126+
UserActions={({ user }) => <AddContributorAction user={user} />}
127+
ignoredColumns={[
128+
USERS_TABLE_COLUMNS.LAST_LOGIN,
129+
USERS_TABLE_COLUMNS.REGISTRATION_STATUS,
130+
USERS_TABLE_COLUMNS.ROLES,
131+
]}
132+
resourceId={workspaceId}
133+
workspaces={workspaces}
134+
isProjectUsersTable={false}
135+
organizationId={organizationId}
136+
/>
137+
</View>
138+
</Flex>
139+
</HasPermission>
140140
);
141141
};

0 commit comments

Comments
 (0)