Skip to content

Commit

Permalink
DBP-1028 Hide the Administrator role from users with a different role (
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncolincap authored Nov 19, 2024
1 parent e60d2fe commit f5758af
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/javascript/components/users/user/forms/UpdateUserForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Form methods={methods} onSubmit={updateUserAPI.mutate}>
<FormControl field={fields.name} type="text" />
Expand All @@ -77,10 +83,10 @@ export default function UpdateUserForm({ user }) {
Object.keys(locales || {}).map((code) => <Option key={code} value={code}>{locales[code]}</Option>)
}
</FormSelect>
{(canUpdateRole && roles) && (
{(canUpdateRole && filteredRoles) && (
<FormSelect field={fields.role_id} variant="dropdown">
{
roles.map((role) => <Option key={role.id} value={role.id}>{role.name}</Option>)
filteredRoles.map((role) => <Option key={role.id} value={role.id}>{role.name}</Option>)
}
</FormSelect>
)}
Expand Down

0 comments on commit f5758af

Please sign in to comment.