From 7300a0e1078b52e8e1da305167451fee35bf80b7 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 24 Jun 2023 20:22:41 +0200 Subject: [PATCH] permission handling --- src/Components/AppRoutes/index.js | 5 +- src/Components/SideMenu/index.js | 8 +- src/Pages/AdminArea/Roles/index.js | 145 +++++++++++++++++------------ src/utils.js | 3 +- 4 files changed, 94 insertions(+), 67 deletions(-) diff --git a/src/Components/AppRoutes/index.js b/src/Components/AppRoutes/index.js index 298351c..432dcb3 100644 --- a/src/Components/AppRoutes/index.js +++ b/src/Components/AppRoutes/index.js @@ -52,9 +52,10 @@ export default function AppRoutes() { {hasOnePermission( webSocketContext.User.Permissions, - Constants.PERMISSIONS.ADMIN_AREA.ROLES.ADD_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.CREATE_NEW_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.UPDATE_ROLE, - Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE + Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN ) && } />} {hasPermission( diff --git a/src/Components/SideMenu/index.js b/src/Components/SideMenu/index.js index 8d5e883..f697f41 100644 --- a/src/Components/SideMenu/index.js +++ b/src/Components/SideMenu/index.js @@ -85,9 +85,10 @@ export default function SideMenu({ userSession, setUserSession }) { if ( hasOnePermission( webSocketContext.User.Permissions, - Constants.PERMISSIONS.ADMIN_AREA.ROLES.ADD_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.CREATE_NEW_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.UPDATE_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN, Constants.PERMISSIONS.ADMIN_AREA.LOGS ) ) { @@ -101,9 +102,10 @@ export default function SideMenu({ userSession, setUserSession }) { if ( hasOnePermission( webSocketContext.User.Permissions, - Constants.PERMISSIONS.ADMIN_AREA.ROLES.ADD_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.CREATE_NEW_ROLE, Constants.PERMISSIONS.ADMIN_AREA.ROLES.UPDATE_ROLE, - Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE + Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN ) ) { adminArea.children.push({ diff --git a/src/Pages/AdminArea/Roles/index.js b/src/Pages/AdminArea/Roles/index.js index 570bbac..d5adbbf 100644 --- a/src/Pages/AdminArea/Roles/index.js +++ b/src/Pages/AdminArea/Roles/index.js @@ -15,6 +15,7 @@ import { MyAvatar, SentMessagesCommands, WebSocketContext, + hasPermission, } from "../../../utils"; import { ArrowDownOutlined, @@ -120,23 +121,28 @@ export default function AdminAreaRoles() { /> ))} -
- onCreateNewRoleClick()} + {hasPermission( + webSocketContext.User.Permissions, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.CREATE_NEW_ROLE + ) && ( +
- - -
+ onCreateNewRoleClick()} + > + + +
+ )} ); } @@ -361,54 +367,71 @@ function Role({ treeData, role, webSocketContext, notificationApi }) { key: "2", extra: editMode ? ( - {role.Master || getUsersInRole().length > 0 ? ( - - ) : ( - } - onConfirm={() => onDeleteClick()} - > - - - - - )} + {hasPermission( + webSocketContext.User.Permissions, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE + ) ? ( + role.Master || getUsersInRole().length > 0 ? ( + + ) : ( + } + onConfirm={() => onDeleteClick()} + > + + + + + ) + ) : null} - {role.SortingOrder === 0 ? ( - - ) : ( - - onMoveUpClick()} /> + {hasPermission( + webSocketContext.User.Permissions, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN + ) ? ( + <> + {role.SortingOrder === 0 ? ( + + ) : ( + + onMoveUpClick()} /> + + )} + {role.SortingOrder === getMaxRoleSortingOrder() ? ( + + ) : ( + + onMoveDownClick()} /> + + )} + + ) : null} + + {hasPermission( + webSocketContext.User.Permissions, + Constants.PERMISSIONS.ADMIN_AREA.ROLES.UPDATE_ROLE + ) && ( + + onSaveClick()} /> )} - {role.SortingOrder === getMaxRoleSortingOrder() ? ( - - ) : ( - - onMoveDownClick()} /> - - )} - - - onSaveClick()} /> - onCloseClick()} /> diff --git a/src/utils.js b/src/utils.js index 46cfd88..4507996 100644 --- a/src/utils.js +++ b/src/utils.js @@ -59,9 +59,10 @@ export const Constants = { }, ADMIN_AREA: { ROLES: { - ADD_ROLE: "admin_area.roles.add_role", + CREATE_NEW_ROLE: "admin_area.roles.create_new_role", UPDATE_ROLE: "admin_area.roles.update_role", DELETE_ROLE: "admin_area.roles.delete_role", + MOVE_ROLE_UP_DOWN: "admin_area.roles.move_role_up_down", }, LOGS: "admin_area.logs", },