From f258a005be5ea49611482fd4644f47286f23776e Mon Sep 17 00:00:00 2001 From: simoncolincap Date: Mon, 18 Nov 2024 11:21:03 +0000 Subject: [PATCH] DBP-1028 Hide the Administrator role from users with a different role --- .../components/users/user/forms/UpdateUserForm.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/javascript/components/users/user/forms/UpdateUserForm.jsx b/app/javascript/components/users/user/forms/UpdateUserForm.jsx index 7d524695b8..2c357eed22 100644 --- a/app/javascript/components/users/user/forms/UpdateUserForm.jsx +++ b/app/javascript/components/users/user/forms/UpdateUserForm.jsx @@ -68,6 +68,12 @@ export default function UpdateUserForm({ user }) { methods.setValue('language', currentLanguage()); }, [currentLanguage()]); + // Check if the current user has a specific role + const hasSpecificRole = currentUser?.role.name === 'Administrator'; + + // Filter roles based on name and/or ID if the current user does not have the specific role + const filteredRoles = hasSpecificRole ? roles : roles?.filter(role => role.name !== 'Administrator'); + return (
@@ -77,10 +83,10 @@ export default function UpdateUserForm({ user }) { Object.keys(locales || {}).map((code) => ) } - {(canUpdateRole && roles) && ( + {(canUpdateRole && filteredRoles) && ( { - roles.map((role) => ) + filteredRoles.map((role) => ) } )}