-
Notifications
You must be signed in to change notification settings - Fork 527
feat: sort/inspect users across permissions tables #7611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kyle-ssg
wants to merge
6
commits into
main
Choose a base branch
from
feat/permissions-table-sorting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−123
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc96cc4
feat: sort users permissions table by name and role
kyle-ssg 4f71144
perf: O(1) permission lookup when decorating users for sort
kyle-ssg da08140
feat: inspect a user's permissions from the project/environment settings
kyle-ssg 6dc8468
feat: sort organisation members table; share user sort helper
kyle-ssg 132ed54
feat: use UserAction ellipsis dropdown in project/environment permiss…
kyle-ssg 0059e76
fix(UserAction): show dropdown when only edit + inspect are available
kyle-ssg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<EditPermissionsType> = (props) => { | |
| } = props | ||
|
|
||
| const [tab, setTab] = useState() | ||
| const hasRbac = !!Utils.getPlansPermission('RBAC') | ||
| const inspectUserPermissions = (user: User) => { | ||
| openModal( | ||
| getUserDisplayName(user), | ||
| <div className='p-4'> | ||
| <Permissions | ||
| level={level} | ||
| levelId={id} | ||
| userId={user.id} | ||
| projectId={level === 'environment' ? Number(parentId) : Number(id)} | ||
| /> | ||
| </div>, | ||
| 'p-0 side-modal', | ||
| ) | ||
| } | ||
| const editUserPermissions = (user: User) => { | ||
| openModal( | ||
| `Edit ${Format.camelCase(level)} Permissions`, | ||
|
|
@@ -1086,125 +1106,143 @@ const EditPermissions: FC<EditPermissionsType> = (props) => { | |
| > | ||
| <TabItem tabLabel='Users'> | ||
| <OrganisationProvider> | ||
| {({ isLoading, users }) => ( | ||
| <div className='mt-4'> | ||
| {isLoading && !users?.length && ( | ||
| <div className='centered-container'> | ||
| <Loader /> | ||
| </div> | ||
| )} | ||
| {!!users?.length && ( | ||
| <div> | ||
| <FormGroup className='panel no-pad pl-2 pr-2 panel--nested'> | ||
| <div className={tabClassName}> | ||
| <PanelSearch | ||
| id='org-members-list' | ||
| title='Users' | ||
| className='panel--transparent' | ||
| items={users} | ||
| itemHeight={64} | ||
| header={ | ||
| <Row className='table-header'> | ||
| <Flex className='table-column px-3'>User</Flex> | ||
| <Flex className='table-column'>Role</Flex> | ||
| <div | ||
| style={{ width: '80px' }} | ||
| className='table-column text-center' | ||
| > | ||
| Action | ||
| </div> | ||
| </Row> | ||
| } | ||
| 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 ( | ||
| <Row | ||
| onClick={onClick} | ||
| space | ||
| className={`list-item${ | ||
| role === 'ADMIN' ? '' : ' clickable' | ||
| }`} | ||
| key={id} | ||
| > | ||
| <Flex className='table-column px-3'> | ||
| <div className='mb-1 font-weight-medium'> | ||
| {`${first_name} ${last_name}`}{' '} | ||
| {String(id) === | ||
| String(AccountStore.getUserId()) && | ||
| '(You)'} | ||
| </div> | ||
| <div className='list-item-subtitle'> | ||
| {email} | ||
| </div> | ||
| </Flex> | ||
| {role === 'ADMIN' ? ( | ||
| <Flex className='table-column fs-small lh-sm'> | ||
| <Tooltip | ||
| title={'Organisation Administrator'} | ||
| > | ||
| { | ||
| 'Organisation administrators have all permissions enabled.<br/>To change the role of this user, visit Organisation Settings.' | ||
| } | ||
| </Tooltip> | ||
| </Flex> | ||
| ) : ( | ||
| <Flex | ||
| onClick={onClick} | ||
| className='table-column fs-small lh-sm' | ||
| > | ||
| {matchingPermissions && | ||
| matchingPermissions.admin | ||
| ? `${Format.camelCase( | ||
| level, | ||
| )} Administrator` | ||
| : 'Regular User'} | ||
| </Flex> | ||
| )} | ||
| {({ 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 ( | ||
| <div className='mt-4'> | ||
| {isLoading && !users?.length && ( | ||
| <div className='centered-container'> | ||
| <Loader /> | ||
| </div> | ||
| )} | ||
| {!!users?.length && ( | ||
| <div> | ||
| <FormGroup className='panel no-pad pl-2 pr-2 panel--nested'> | ||
| <div className={tabClassName}> | ||
| <PanelSearch | ||
| id='org-members-list' | ||
| title='Users' | ||
| className='panel--transparent' | ||
| items={sortableUsers} | ||
| itemHeight={64} | ||
| sorting={userTableSorting} | ||
| header={ | ||
| <Row className='table-header'> | ||
| <Flex className='table-column px-3'>User</Flex> | ||
| <Flex className='table-column'>Role</Flex> | ||
| <div | ||
| style={{ width: '80px' }} | ||
| className='text-center' | ||
| className='table-column text-center' | ||
| > | ||
| {role !== 'ADMIN' && ( | ||
| <Icon | ||
| name='setting' | ||
| width={20} | ||
| fill='#656D7B' | ||
| /> | ||
| )} | ||
| Action | ||
| </div> | ||
| </Row> | ||
| ) | ||
| }} | ||
| renderNoResults={ | ||
| <div>You have no users in this organisation.</div> | ||
| } | ||
| filterRow={(item: User, search: string) => { | ||
| const strToSearch = `${item.first_name} ${item.last_name} ${item.email}` | ||
| return ( | ||
| strToSearch | ||
| .toLowerCase() | ||
| .indexOf(search.toLowerCase()) !== -1 | ||
| ) | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| <div id='select-portal' /> | ||
| </FormGroup> | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
| } | ||
| 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, | ||
| ) | ||
|
Comment on lines
+1158
to
+1160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. permissionsByUserId is already in scope here, could this be permissionsByUserId.get(id) instead of the linear find, so the row and the sort decorator share one lookup? |
||
|
|
||
| return ( | ||
| <Row | ||
| onClick={onClick} | ||
| space | ||
| className={`list-item${ | ||
| role === 'ADMIN' ? '' : ' clickable' | ||
| }`} | ||
| key={id} | ||
| > | ||
| <Flex className='table-column px-3'> | ||
| <div className='mb-1 font-weight-medium'> | ||
| {`${first_name} ${last_name}`}{' '} | ||
| {String(id) === | ||
| String(AccountStore.getUserId()) && | ||
| '(You)'} | ||
| </div> | ||
| <div className='list-item-subtitle'> | ||
| {email} | ||
| </div> | ||
| </Flex> | ||
| {role === 'ADMIN' ? ( | ||
| <Flex className='table-column fs-small lh-sm'> | ||
| <Tooltip | ||
| title={'Organisation Administrator'} | ||
| > | ||
| { | ||
| 'Organisation administrators have all permissions enabled.<br/>To change the role of this user, visit Organisation Settings.' | ||
| } | ||
| </Tooltip> | ||
| </Flex> | ||
| ) : ( | ||
| <Flex | ||
| onClick={onClick} | ||
| className='table-column fs-small lh-sm' | ||
| > | ||
| {matchingPermissions && | ||
| matchingPermissions.admin | ||
| ? `${Format.camelCase( | ||
| level, | ||
| )} Administrator` | ||
| : 'Regular User'} | ||
| </Flex> | ||
| )} | ||
| <div | ||
| style={{ width: '80px' }} | ||
| className='table-column d-flex justify-content-end' | ||
| > | ||
| {role !== 'ADMIN' && ( | ||
| <UserAction | ||
| canEdit | ||
| canRemove={false} | ||
| canInspectPermissions={hasRbac} | ||
| onEdit={() => editUserPermissions(user)} | ||
| onRemove={() => {}} | ||
| onInspectPermissions={() => | ||
| inspectUserPermissions(user) | ||
| } | ||
| /> | ||
| )} | ||
| </div> | ||
| </Row> | ||
| ) | ||
| }} | ||
| renderNoResults={ | ||
| <div>You have no users in this organisation.</div> | ||
| } | ||
| filterRow={(item: User, search: string) => { | ||
| const strToSearch = `${item.first_name} ${item.last_name} ${item.email}` | ||
| return ( | ||
| strToSearch | ||
| .toLowerCase() | ||
| .indexOf(search.toLowerCase()) !== -1 | ||
| ) | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| <div id='select-portal' /> | ||
| </FormGroup> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| }} | ||
| </OrganisationProvider> | ||
| </TabItem> | ||
| <TabItem tabLabel='Groups'> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple bare
'ADMIN'checks in this file. Worth a const/helper(
isOrgAdmin(user)orRole.ADMIN)?