user can only change roles and delete users with roles below his role

main
alex 2023-06-25 16:15:29 +02:00
parent ce692dc5a0
commit 8b6f59b0f0
1 changed files with 71 additions and 57 deletions

View File

@ -73,7 +73,16 @@ export default function AllUsers() {
{hasPermission( {hasPermission(
webSocketContext.User.Permissions, webSocketContext.User.Permissions,
Constants.PERMISSIONS.ALL_USERS.ACTION.CHANGE_ROLE Constants.PERMISSIONS.ALL_USERS.ACTION.CHANGE_ROLE
) && ( ) &&
(webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).SortingOrder <
webSocketContext.AllRoles.find(
(role) => role.Id === record._roleId
).SortingOrder ||
webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).Master) && (
<Popconfirm <Popconfirm
title="Change role to" title="Change role to"
okText="Change" okText="Change"
@ -97,11 +106,24 @@ export default function AllUsers() {
value={selectedRoleId} value={selectedRoleId}
onChange={(e) => setSelectedRoleId(e)} onChange={(e) => setSelectedRoleId(e)}
> >
{webSocketContext.AllRoles.map((role) => ( {webSocketContext.AllRoles.map((role) => {
if (
webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).Master ||
webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).SortingOrder < role.SortingOrder
) {
return (
<Select.Option key={role.Id}> <Select.Option key={role.Id}>
{role.DisplayName} {role.DisplayName}
</Select.Option> </Select.Option>
))} );
}
return null;
})}
</Select> </Select>
} }
> >
@ -120,27 +142,19 @@ export default function AllUsers() {
</Popconfirm> </Popconfirm>
)} )}
{console.log(
webSocketContext.User.RoleId,
webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).SortingOrder,
webSocketContext.AllRoles.find(
(role) => role.Id === record._roleId
).SortingOrder
)}
{hasPermission( {hasPermission(
webSocketContext.User.Permissions, webSocketContext.User.Permissions,
Constants.PERMISSIONS.ALL_USERS.ACTION.DELETE_USER Constants.PERMISSIONS.ALL_USERS.ACTION.DELETE_USER
) && ) &&
webSocketContext.AllRoles.find( (webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId (role) => role.Id === webSocketContext.User.RoleId
).SortingOrder < ).SortingOrder <
webSocketContext.AllRoles.find( webSocketContext.AllRoles.find(
(role) => role.Id === record._roleId (role) => role.Id === record._roleId
).SortingOrder && ( ).SortingOrder ||
webSocketContext.AllRoles.find(
(role) => role.Id === webSocketContext.User.RoleId
).Master) && (
<Popconfirm <Popconfirm
placement="top" placement="top"
okText="Delete user" okText="Delete user"