Skip to content
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

fix: block user from removing own admin roles #987

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,8 @@
},
"userRoles": {
"title": "Assigned Catena-X Portal Roles",
"changeRoleBtn": "Change Portal Role"
"changeRoleBtn": "Change Portal Role",
"errorMsg": "Sie sind nicht berechtigt, Ihre eigenen Rollen zu ändern. Bitte wenden Sie sich an einen anderen Unternehmens- oder IT-Administrator."
evegufy marked this conversation as resolved.
Show resolved Hide resolved
}
},
"global": {
Expand Down
3 changes: 2 additions & 1 deletion src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,8 @@
},
"userRoles": {
"title": "Assigned Catena-X Portal Roles",
"changeRoleBtn": "Change Portal Role"
"changeRoleBtn": "Change Portal Role",
"errorMsg": "You are not authorized to change your own admin roles. Please contact another Company Admin or IT Admin"
evegufy marked this conversation as resolved.
Show resolved Hide resolved
}
},
"global": {
Expand Down
16 changes: 16 additions & 0 deletions src/components/overlays/EditPortalRoles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DialogActions,
DialogContent,
DialogHeader,
Typography,
} from '@catena-x/portal-shared-components'
import {
type AppRole,
Expand All @@ -40,6 +41,7 @@ import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import { OVERLAYS } from 'types/Constants'
import './style.scss'
import UserService from 'services/UserService'

export default function EditPortalRoles({ id }: { id: string }) {
const { t } = useTranslation()
Expand Down Expand Up @@ -112,6 +114,14 @@ export default function EditPortalRoles({ id }: { id: string }) {
assignedRoles.length === selectedRoles.length &&
assignedRoles.every((value) => selectedRoles.includes(value)))

const disabledCheckbox = (currentRole: AppRole) => {
const allAdminRoles = allRoles.filter((item) => item.role.includes('Admin'))
evegufy marked this conversation as resolved.
Show resolved Hide resolved

return UserService.getUsername() === id
? allAdminRoles.indexOf(currentRole) !== -1
evegufy marked this conversation as resolved.
Show resolved Hide resolved
: false
}

return (
<>
<div className="roles-heading">
Expand All @@ -132,6 +142,7 @@ export default function EditPortalRoles({ id }: { id: string }) {
allRoles.map((role) => (
<li key={role.roleId}>
<Checkbox
disabled={disabledCheckbox(role)}
label={role.role}
checked={selectedRoles.indexOf(role.role) !== -1}
onChange={(e) => {
Expand All @@ -142,6 +153,11 @@ export default function EditPortalRoles({ id }: { id: string }) {
))}
</ul>
</div>
{UserService.getUsername() === id && (
<Typography variant="body3" sx={{ mt: 3 }}>
{t('shared.userRoles.errorMsg')}
</Typography>
)}
</DialogContent>

<DialogActions>
Expand Down
Loading