diff --git a/frontend/common/types/requests.ts b/frontend/common/types/requests.ts index 7dd713129e41..171a41106881 100644 --- a/frontend/common/types/requests.ts +++ b/frontend/common/types/requests.ts @@ -824,7 +824,7 @@ export type Req = { userId: number } getUserPermissions: { - id?: number + id?: number | string userId: number | undefined level: PermissionLevel } diff --git a/frontend/web/components/EditPermissions.tsx b/frontend/web/components/EditPermissions.tsx index cf99407bd9ad..9d76a0408b96 100644 --- a/frontend/web/components/EditPermissions.tsx +++ b/frontend/web/components/EditPermissions.tsx @@ -25,7 +25,6 @@ import UserGroupList from './UserGroupList' import { PermissionLevel, Req, PermissionRoleType } from 'common/types/requests' import { useGetAvailablePermissionsQuery } from 'common/services/useAvailablePermissions' import ConfigProvider from 'common/providers/ConfigProvider' -import Icon from './icons/Icon' import { useCreateRolePermissionsMutation, useGetRoleEnvironmentPermissionsQuery, @@ -66,6 +65,12 @@ import Utils from 'common/utils/utils' import RemoveViewPermissionModal from './RemoveViewPermissionModal' import { useHistory } from 'react-router-dom' import getUserDisplayName from 'common/utils/getUserDisplayName' +import Permissions from './inspect-permissions/Permissions' +import UserAction from './UserAction' +import { + decorateUsersForSort, + userTableSorting, +} from './users-permissions/sortUsers' import Project from 'common/project' @@ -1013,6 +1018,21 @@ const EditPermissions: FC = (props) => { } = props const [tab, setTab] = useState() + const hasRbac = !!Utils.getPlansPermission('RBAC') + const inspectUserPermissions = (user: User) => { + openModal( + getUserDisplayName(user), +
+ +
, + 'p-0 side-modal', + ) + } const editUserPermissions = (user: User) => { openModal( `Edit ${Format.camelCase(level)} Permissions`, @@ -1086,125 +1106,143 @@ const EditPermissions: FC = (props) => { > - {({ isLoading, users }) => ( -
- {isLoading && !users?.length && ( -
- -
- )} - {!!users?.length && ( -
- -
- - User - Role -
- Action -
- - } - renderRow={(user) => { - const { email, first_name, id, last_name, role } = - user - const onClick = () => { - if (role !== 'ADMIN') { - editUserPermissions(user) - } - } - const matchingPermissions = permissions?.find( - (v) => v.user.id === id, - ) - - return ( - - -
- {`${first_name} ${last_name}`}{' '} - {String(id) === - String(AccountStore.getUserId()) && - '(You)'} -
-
- {email} -
-
- {role === 'ADMIN' ? ( - - - { - 'Organisation administrators have all permissions enabled.
To change the role of this user, visit Organisation Settings.' - } -
-
- ) : ( - - {matchingPermissions && - matchingPermissions.admin - ? `${Format.camelCase( - level, - )} Administrator` - : 'Regular User'} - - )} + {({ isLoading, users }) => { + const permissionsByUserId = new Map( + permissions?.map((p) => [p.user.id, p]), + ) + const sortableUsers = decorateUsersForSort(users, (user) => { + if (user.role === 'ADMIN') return 'Organisation Administrator' + if (permissionsByUserId.get(user.id)?.admin) { + return `${Format.camelCase(level)} Administrator` + } + return 'Regular User' + }) + return ( +
+ {isLoading && !users?.length && ( +
+ +
+ )} + {!!users?.length && ( +
+ +
+ + User + Role
- {role !== 'ADMIN' && ( - - )} + Action
- ) - }} - renderNoResults={ -
You have no users in this organisation.
- } - filterRow={(item: User, search: string) => { - const strToSearch = `${item.first_name} ${item.last_name} ${item.email}` - return ( - strToSearch - .toLowerCase() - .indexOf(search.toLowerCase()) !== -1 - ) - }} - /> -
- -
- -
- )} -
- )} + } + renderRow={(user) => { + const { email, first_name, id, last_name, role } = + user + const onClick = () => { + if (role !== 'ADMIN') { + editUserPermissions(user) + } + } + const matchingPermissions = permissions?.find( + (v) => v.user.id === id, + ) + + return ( + + +
+ {`${first_name} ${last_name}`}{' '} + {String(id) === + String(AccountStore.getUserId()) && + '(You)'} +
+
+ {email} +
+
+ {role === 'ADMIN' ? ( + + + { + 'Organisation administrators have all permissions enabled.
To change the role of this user, visit Organisation Settings.' + } +
+
+ ) : ( + + {matchingPermissions && + matchingPermissions.admin + ? `${Format.camelCase( + level, + )} Administrator` + : 'Regular User'} + + )} +
+ {role !== 'ADMIN' && ( + editUserPermissions(user)} + onRemove={() => {}} + onInspectPermissions={() => + inspectUserPermissions(user) + } + /> + )} +
+
+ ) + }} + renderNoResults={ +
You have no users in this organisation.
+ } + filterRow={(item: User, search: string) => { + const strToSearch = `${item.first_name} ${item.last_name} ${item.email}` + return ( + strToSearch + .toLowerCase() + .indexOf(search.toLowerCase()) !== -1 + ) + }} + /> +
+ +
+ +
+ )} +
+ ) + }} diff --git a/frontend/web/components/PanelSearch.tsx b/frontend/web/components/PanelSearch.tsx index bb3d4d90c308..d435b684cfd4 100644 --- a/frontend/web/components/PanelSearch.tsx +++ b/frontend/web/components/PanelSearch.tsx @@ -23,7 +23,7 @@ import Panel from './base/grid/Panel' import Utils from 'common/utils/utils' import { SortOrder } from 'common/types/requests' -type SortOption = { +export type SortOption = { value: string order: SortOrder default?: boolean diff --git a/frontend/web/components/UserAction.tsx b/frontend/web/components/UserAction.tsx index f365d908eb2e..2459e4c8dfe3 100644 --- a/frontend/web/components/UserAction.tsx +++ b/frontend/web/components/UserAction.tsx @@ -142,7 +142,7 @@ const UserAction: FC = ({ [close, onRemove, onEdit, onInspectPermissions], ) - if (!canEdit && !!canRemove) { + if (!canEdit && !!canRemove && !canInspectPermissions) { return (