-
Notifications
You must be signed in to change notification settings - Fork 159
[frontend] RBAC creation of roles screen #3695
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7e3d59a
[frontend] RBAC creation of roles screen
camrrx 3359eb9
[frontend] RBAC creation of roles screen
camrrx 0b8dce0
[frontend] RBAC creation of roles screen
camrrx 4424c8b
[frontend] RBAC creation of roles screen
camrrx af11696
[frontend] RBAC creation of roles screen
camrrx 54c5b88
[frontend] RBAC creation of roles screen
camrrx 3206d68
[frontend] RBAC creation of roles screen
camrrx 773427f
[frontend] RBAC creation of roles screen
camrrx ea70673
[frontend] RBAC creation of roles screen
camrrx 15b615c
[backend] RBAC creation of roles screen
camrrx 9246d5c
[backend] RBAC creation of roles screen
camrrx c17e3a0
[frontend] RBAC creation of roles screen
camrrx 3670828
[frontend] RBAC creation of roles screen
camrrx 0c8150e
[frontend] RBAC creation of roles screen
camrrx 92210ec
[frontend] RBAC creation of roles screen
camrrx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
openbas-api/src/main/java/io/openbas/migration/V4_10__List_Widget_config_update.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Dispatch } from 'redux'; | ||
|
||
import type { RoleCreateInput } from '../../admin/components/settings/roles/RoleForm'; | ||
import { delReferential, getReferential, postReferential, putReferential, simplePostCall } from '../../utils/Action'; | ||
import { type RoleOutput, type SearchPaginationInput } from '../../utils/api-types'; | ||
import * as schema from '../Schema'; | ||
|
||
const ROLES_URI = '/api/roles'; | ||
export const searchRoles = (paginationInput: SearchPaginationInput) => { | ||
const data = paginationInput; | ||
const uri = `${ROLES_URI}/search`; | ||
return simplePostCall(uri, data); | ||
}; | ||
|
||
export const fetchRoles = () => (dispatch: Dispatch): Promise<RoleOutput[]> => { | ||
const uri = `${ROLES_URI}`; | ||
return getReferential(schema.arrayOfRoles, uri)(dispatch); | ||
}; | ||
|
||
export const deleteRole = (roleId: RoleOutput['role_id']) => (dispatch: Dispatch) => { | ||
const uri = `${ROLES_URI}/${roleId}`; | ||
return delReferential(uri, 'roles', roleId)(dispatch); | ||
}; | ||
|
||
export const createRole = (data: RoleCreateInput) => (dispatch: Dispatch) => { | ||
const uri = `${ROLES_URI}`; | ||
return postReferential(schema.role, uri, data)(dispatch); | ||
}; | ||
|
||
export const updateRole = (roleId: RoleOutput['role_id'], data: RoleCreateInput) => (dispatch: Dispatch) => { | ||
const uri = `${ROLES_URI}/${roleId}`; | ||
return putReferential(schema.role, uri, data)(dispatch); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
openbas-front/src/admin/components/settings/groups/GroupManageRoles.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { SecurityOutlined } from '@mui/icons-material'; | ||
import { Box, Button, Checkbox, Divider } from '@mui/material'; | ||
import { useTheme } from '@mui/material/styles'; | ||
import { type FC, useEffect, useState } from 'react'; | ||
|
||
import { fetchRoles } from '../../../../actions/roles/roles-actions'; | ||
import Drawer from '../../../../components/common/Drawer'; | ||
import { useFormatter } from '../../../../components/i18n'; | ||
import { type RoleOutput } from '../../../../utils/api-types'; | ||
import { useAppDispatch } from '../../../../utils/hooks'; | ||
|
||
interface GroupManageRolesProps { | ||
initialState: string[]; | ||
open: boolean; | ||
onClose: () => void; | ||
onSubmit: (roleIds: string[]) => void; | ||
} | ||
|
||
const GroupManageRoles: FC<GroupManageRolesProps> = ( | ||
{ | ||
initialState, | ||
open, | ||
onClose, | ||
onSubmit, | ||
}, | ||
) => { | ||
const { t } = useFormatter(); | ||
const theme = useTheme(); | ||
const dispatch = useAppDispatch(); | ||
|
||
const [roles, setRoles] = useState<RoleOutput[]>([]); | ||
const [selectedRoleIds, setSelectedRoleIds] = useState<string[]>(initialState); | ||
|
||
const handleToggleRole = (roleId: string) => { | ||
setSelectedRoleIds(prev => | ||
prev.includes(roleId) | ||
? prev.filter(id => id !== roleId) | ||
: [...prev, roleId], | ||
); | ||
}; | ||
|
||
const fetchRolesToLoad = () => { | ||
return dispatch(fetchRoles()) | ||
.then((result: { entities: { roles: Record<string, RoleOutput> } }) => { | ||
const rolesArray = Object.values(result.entities.roles); | ||
setRoles(rolesArray); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (open) { | ||
fetchRolesToLoad(); | ||
} | ||
}, [open]); | ||
|
||
const handleClose = () => { | ||
setRoles([]); | ||
onClose(); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
onSubmit(selectedRoleIds); | ||
handleClose(); | ||
}; | ||
|
||
return ( | ||
<Drawer | ||
open={open} | ||
handleClose={onClose} | ||
title={t('Manage the roles of this group')} | ||
> | ||
<Box> | ||
{roles.map(role => ( | ||
<div key={role.role_id}> | ||
<Box display="flex" alignItems="center" gap={theme.spacing(2)} justifyContent="space-between"> | ||
<div style={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: theme.spacing(1), | ||
}} | ||
> | ||
<SecurityOutlined /> | ||
<p>{role.role_name}</p> | ||
</div> | ||
<Checkbox | ||
checked={selectedRoleIds.includes(role.role_id)} | ||
onChange={() => handleToggleRole(role.role_id)} | ||
/> | ||
</Box> | ||
<Divider /> | ||
</div> | ||
))} | ||
|
||
<div style={{ | ||
float: 'right', | ||
marginTop: theme.spacing(2), | ||
}} | ||
> | ||
<Button variant="contained" style={{ marginRight: theme.spacing(1) }} onClick={onClose}> | ||
{t('Cancel')} | ||
</Button> | ||
<Button variant="contained" color="secondary" onClick={handleSubmit}> | ||
{t('Update')} | ||
</Button> | ||
</div> | ||
</Box> | ||
</Drawer> | ||
); | ||
}; | ||
|
||
export default GroupManageRoles; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.