-
Notifications
You must be signed in to change notification settings - Fork 3
fix: allow users with a systemRole.grant = true to update user roles #2515
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
base: stage
Are you sure you want to change the base?
Changes from all commits
e842866
6cd3f8d
f3c17e1
3d2b7b3
18fac4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ import { useZestyStore } from 'store'; | |
| import { useRouter } from 'next/router'; | ||
| import { Users } from 'views/accounts'; | ||
| import { ErrorMsg, SuccessMsg } from 'components/accounts'; | ||
| import * as helpers from 'utils'; | ||
| import InstanceContainer from 'components/accounts/instances/InstanceContainer'; | ||
|
|
||
| export { default as getServerSideProps } from 'lib/accounts/protectedRouteGetServerSideProps'; | ||
|
|
@@ -138,10 +137,17 @@ export default function UsersPage() { | |
| } | ||
| }, [router.isReady]); | ||
|
|
||
| const isInstanceOwner = helpers.isInstanceOwner( | ||
| instanceUserWithRoles, | ||
| userInfo, | ||
| ); | ||
| const canUpdateUsers = React.useMemo(() => { | ||
| if (!userInfo || !instanceUserWithRoles?.length) { | ||
| return false; | ||
| } | ||
|
|
||
| const updateUsersPermission = instanceUserWithRoles.find( | ||
| (user) => user.ZUID === userInfo.ZUID, | ||
| )?.role?.systemRole?.grant; | ||
|
|
||
| return updateUsersPermission || userInfo.staff; | ||
| }, [instanceUserWithRoles, userInfo]); | ||
|
finnar-bin marked this conversation as resolved.
Comment on lines
+140
to
+150
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. Two small issues with this memoized value:
|
||
|
|
||
| const filteredUsers = instanceUserWithRoles?.filter((e) => { | ||
| const name = `${e?.firstName?.toLowerCase() || '-'} ${ | ||
|
|
@@ -155,7 +161,7 @@ export default function UsersPage() { | |
| deleteUserRole, | ||
| instanceRoles, | ||
| createInvite, | ||
| isOwner: isInstanceOwner, | ||
| canUpdateUsers, | ||
| instanceZUID: zuid, | ||
| loading, | ||
| search, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ const CustomTable = ({ | |
| handleUpdateRole, | ||
| handleDeleteRole, | ||
| instanceRoles, | ||
| isOwner, | ||
| canUpdateUsers, | ||
| loading, | ||
| }) => { | ||
| const ROWS = data?.map((e) => { | ||
|
|
@@ -120,7 +120,7 @@ const CustomTable = ({ | |
| handleUpdateRole(val); | ||
| }; | ||
|
|
||
| const role = isOwner | ||
| const role = canUpdateUsers | ||
|
finnar-bin marked this conversation as resolved.
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. Heads-up on a residual gap: |
||
| ? RoleSwitcher({ | ||
| role: e.role.name, | ||
| handleOnChange, | ||
|
|
@@ -189,7 +189,10 @@ const CustomTable = ({ | |
| }, | ||
| ]; | ||
| const actionOwner = [ | ||
| { title: 'Delete User', action: isOwner ? handleDeleteUser : null }, | ||
| { | ||
| title: 'Delete User', | ||
| action: canUpdateUsers ? handleDeleteUser : null, | ||
| }, | ||
| { | ||
| title: 'Email', | ||
| action: () => window.open(`mailto:${params.row.email}`), | ||
|
|
@@ -205,7 +208,7 @@ const CustomTable = ({ | |
| </Button> | ||
| } | ||
| id={'actions'} | ||
| items={isOwner ? actionOwner : action} | ||
| items={canUpdateUsers ? actionOwner : action} | ||
| colorInvert={false} | ||
| /> | ||
| </> | ||
|
|
@@ -276,7 +279,7 @@ const Index = ({ | |
| deleteUserRole, | ||
| instanceRoles, | ||
| createInvite, | ||
| isOwner, | ||
| canUpdateUsers, | ||
| instanceZUID, | ||
| loading, | ||
| search, | ||
|
|
@@ -347,7 +350,7 @@ const Index = ({ | |
| handleUpdateRole={handleUpdateRole} | ||
| handleDeleteRole={handleDeleteRole} | ||
| instanceRoles={instanceRoles} | ||
| isOwner={isOwner} | ||
| canUpdateUsers={canUpdateUsers} | ||
| loading={loading} | ||
| /> | ||
| </Grid> | ||
|
|
@@ -357,7 +360,7 @@ const Index = ({ | |
| data={pendingUsers} | ||
| instanceRoles={instanceRoles} | ||
| respondToInvite={respondToInvite} | ||
| isOwner={isOwner} | ||
| canUpdateUsers={canUpdateUsers} | ||
| loading={loading} | ||
| /> | ||
| </Grid> | ||
|
|
@@ -369,7 +372,7 @@ export const Users = React.memo(Index); | |
| const PendingTable = ({ | ||
| data, | ||
| instanceRoles, | ||
| // isOwner, | ||
| // canUpdateUsers, | ||
|
finnar-bin marked this conversation as resolved.
finnar-bin marked this conversation as resolved.
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. This commented-out destructure can be removed. The parent passes |
||
| loading, | ||
| respondToInvite, | ||
| }) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.