-
Notifications
You must be signed in to change notification settings - Fork 71
Introduce Access History for Group/Role Access Requests #304
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
4 commits
Select commit
Hold shift + click to select a range
4c07a79
Add user access history and role-based alternatives to group access r…
tonydelanuez 5a9daf2
Generalize access history component for user/group and role/group req…
tonydelanuez 5b9873d
Remove RoleSuggestions for followup PR
tonydelanuez cc0625a
Update src/components/AccessHistory.tsx
tonydelanuez 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
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,95 @@ | ||
| import React from 'react'; | ||
| import Paper from '@mui/material/Paper'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import Box from '@mui/material/Box'; | ||
| import {OktaUserGroupMember, RoleGroupMap} from '../api/apiSchemas'; | ||
| import AccessHistoryTable from './AccessHistoryTable'; | ||
| import InfoOutlined from '@mui/icons-material/InfoOutlined'; | ||
| import Accordion from '@mui/material/Accordion'; | ||
| import AccordionSummary from '@mui/material/AccordionSummary'; | ||
| import AccordionDetails from '@mui/material/AccordionDetails'; | ||
| import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
|
|
||
| type AccessAuditEntry = OktaUserGroupMember | RoleGroupMap; | ||
|
|
||
| type SubjectType = 'user' | 'role'; | ||
|
|
||
| interface AccessHistoryProps { | ||
| subjectType: SubjectType; | ||
| subjectName: string; | ||
| groupName: string; | ||
| auditHistory: AccessAuditEntry[]; | ||
| alternativeRoleMappings?: RoleGroupMap[]; | ||
| } | ||
|
|
||
| export default function AccessHistory({ | ||
| subjectType, | ||
| subjectName, | ||
| groupName, | ||
| auditHistory, | ||
| alternativeRoleMappings, | ||
| }: AccessHistoryProps) { | ||
| const currentAccess = auditHistory.filter( | ||
| (audit) => audit.ended_at == null || (audit.ended_at && new Date(audit.ended_at) > new Date()), | ||
| ); | ||
| const pastAccess = auditHistory.filter((audit) => audit.ended_at != null && new Date(audit.ended_at) <= new Date()); | ||
| // Info card for empty state | ||
| if (currentAccess.length === 0 && pastAccess.length === 0) { | ||
| return ( | ||
| <Box> | ||
| <Paper sx={{p: 2, mt: 1, display: 'flex', alignItems: 'center', gap: 2, backgroundColor: 'background.default'}}> | ||
| <Box sx={{display: 'flex', alignItems: 'center'}}> | ||
| <InfoOutlined color="info" sx={{fontSize: 36, mr: 2}} /> | ||
| </Box> | ||
| <Box> | ||
| <Typography variant="subtitle1" sx={{fontWeight: 600}}> | ||
| No prior access history | ||
| </Typography> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| {subjectType === 'user' | ||
| ? `This user has never had access to this group. Approving this request will grant access for the first time.` | ||
| : `This role has never had access to this group. Approving this request will grant access for the first time.`} | ||
| </Typography> | ||
| </Box> | ||
| </Paper> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box> | ||
| <Accordion defaultExpanded sx={{mt: 1}}> | ||
| <AccordionSummary expandIcon={<ExpandMoreIcon />}> | ||
| <Typography variant="h6" sx={{fontWeight: 600}}> | ||
| {`${subjectName} Access History to ${groupName}`} | ||
| </Typography> | ||
| </AccordionSummary> | ||
| <AccordionDetails> | ||
| {/* Current Access Section */} | ||
| <Typography variant="subtitle1" color="success.main" sx={{mb: 1, fontWeight: 500}}> | ||
| {`Current Access${currentAccess.length > 0 ? ` (${currentAccess.length} active membership${currentAccess.length !== 1 ? 's' : ''})` : ''}`} | ||
| </Typography> | ||
| <AccessHistoryTable | ||
| accessEntries={currentAccess as any} | ||
| highlightColor="success" | ||
| showEndedBy={false} | ||
| emptyMessage="No current access" | ||
| /> | ||
| <hr /> | ||
| {/* Past Access Section */} | ||
| <Box sx={{mt: 2}}> | ||
| <Typography variant="subtitle1" color="text.secondary" sx={{mb: 1, fontWeight: 500}}> | ||
| {`Past Access${pastAccess.length > 0 ? ` (${pastAccess.length} previous membership${pastAccess.length !== 1 ? 's' : ''})` : ''}`} | ||
| </Typography> | ||
| <AccessHistoryTable | ||
| accessEntries={pastAccess as any} | ||
| highlightColor="danger" | ||
| showEndedBy={true} | ||
| emptyMessage="No previous access" | ||
| /> | ||
| </Box> | ||
| </AccordionDetails> | ||
| </Accordion> | ||
| </Box> | ||
| ); | ||
| } | ||
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,132 @@ | ||
| import React from 'react'; | ||
| import {Link as RouterLink} from 'react-router-dom'; | ||
|
|
||
| import Link from '@mui/material/Link'; | ||
| import Table from '@mui/material/Table'; | ||
| import TableBody from '@mui/material/TableBody'; | ||
| import TableCell from '@mui/material/TableCell'; | ||
| import TableHead from '@mui/material/TableHead'; | ||
| import TableRow from '@mui/material/TableRow'; | ||
| import TablePagination from '@mui/material/TablePagination'; | ||
| import Typography from '@mui/material/Typography'; | ||
|
|
||
| import {OktaUserGroupMember, RoleGroupMap} from '../api/apiSchemas'; | ||
| import {displayUserName} from '../helpers'; | ||
| import Started from './Started'; | ||
| import Ending from './Ending'; | ||
| import InlineReason from './InlineReason'; | ||
| import AccessMethodChip from './AccessMethodChip'; | ||
| import TablePaginationActions from './actions/TablePaginationActions'; | ||
|
|
||
| // Accept both OktaUserGroupMember[] and RoleGroupMap[] | ||
| type AccessAuditEntry = OktaUserGroupMember | RoleGroupMap; | ||
|
|
||
| interface AccessHistoryTableProps { | ||
| accessEntries: AccessAuditEntry[]; | ||
| highlightColor: 'success' | 'danger'; | ||
| showEndedBy: boolean; | ||
| emptyMessage?: string; | ||
| } | ||
|
|
||
| export default function AccessHistoryTable({ | ||
| accessEntries, | ||
| highlightColor, | ||
| showEndedBy, | ||
| emptyMessage, | ||
| }: AccessHistoryTableProps) { | ||
| const [page, setPage] = React.useState(0); | ||
| const rowsPerPage = 20; | ||
| const handleChangePage = (event: unknown, newPage: number) => { | ||
| setPage(newPage); | ||
| }; | ||
|
|
||
| const columns = [ | ||
| 'Access Type', | ||
| 'Method', | ||
| 'Started', | ||
| 'Ending', | ||
| showEndedBy ? 'Removed by' : 'Added by', | ||
| 'Access Reason', | ||
| ]; | ||
|
|
||
| if (accessEntries.length === 0) { | ||
| return ( | ||
| <Typography variant="body2" color="text.secondary" align="center" sx={{my: 2}}> | ||
| {emptyMessage} | ||
| </Typography> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Table size="small" aria-label="access history"> | ||
| <TableHead> | ||
| <TableRow> | ||
| {columns.map((col) => ( | ||
| <TableCell key={col}>{col}</TableCell> | ||
| ))} | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {accessEntries.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((access) => ( | ||
| <TableRow | ||
| key={access.id} | ||
| sx={{ | ||
| backgroundColor: highlightColor, | ||
| }}> | ||
| <TableCell>{access.is_owner ? 'Owner' : 'Member'}</TableCell> | ||
| <TableCell> | ||
| <AccessMethodChip roleGroupMapping={(access as any).role_group_mapping} /> | ||
| </TableCell> | ||
| <TableCell> | ||
| <Started memberships={[access as any]} /> | ||
| </TableCell> | ||
| <TableCell> | ||
| <Ending memberships={[access as any]} /> | ||
| </TableCell> | ||
| <TableCell> | ||
| {showEndedBy ? ( | ||
| (access as any).ended_actor ? ( | ||
| <Link | ||
| to={`/users/${(access as any).ended_actor?.email?.toLowerCase?.()}`} | ||
| sx={{textDecoration: 'none', color: 'inherit'}} | ||
| component={RouterLink}> | ||
| {displayUserName((access as any).ended_actor)} | ||
| </Link> | ||
| ) : ( | ||
| 'System' | ||
| ) | ||
| ) : (access as any).created_actor ? ( | ||
| <Link | ||
| to={`/users/${(access as any).created_actor?.email?.toLowerCase?.()}`} | ||
| sx={{textDecoration: 'none', color: 'inherit'}} | ||
| component={RouterLink}> | ||
| {displayUserName((access as any).created_actor)} | ||
| </Link> | ||
| ) : ( | ||
| 'System' | ||
| )} | ||
| </TableCell> | ||
| <TableCell> | ||
| {(access as any).created_reason ? ( | ||
| <InlineReason reason={(access as any).created_reason} /> | ||
| ) : ( | ||
| <InlineReason /> | ||
| )} | ||
| </TableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| <TablePagination | ||
| component="div" | ||
| count={accessEntries.length} | ||
| page={page} | ||
| onPageChange={handleChangePage} | ||
| ActionsComponent={TablePaginationActions} | ||
| rowsPerPage={rowsPerPage} | ||
| rowsPerPageOptions={[]} | ||
| /> | ||
| </> | ||
| ); | ||
| } |
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,27 @@ | ||
| import React from 'react'; | ||
| import Chip from '@mui/material/Chip'; | ||
| import {useNavigate} from 'react-router-dom'; | ||
| import {RoleGroupMap} from '../api/apiSchemas'; | ||
|
|
||
| interface AccessMethodChipProps { | ||
| roleGroupMapping?: RoleGroupMap | null; | ||
| } | ||
|
|
||
| export default function AccessMethodChip({roleGroupMapping}: AccessMethodChipProps) { | ||
| const navigate = useNavigate(); | ||
|
|
||
| if (!roleGroupMapping) { | ||
| return <Chip label="Direct" color="primary" size="small" />; | ||
| } | ||
|
|
||
| return ( | ||
| <Chip | ||
| label={roleGroupMapping.role_group?.name} | ||
| variant="outlined" | ||
| color="primary" | ||
| size="small" | ||
| onClick={() => navigate(`/roles/${roleGroupMapping.role_group?.name}`)} | ||
| sx={{cursor: 'pointer'}} | ||
| /> | ||
| ); | ||
| } |
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,34 @@ | ||
| import React from 'react'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import Box from '@mui/material/Box'; | ||
|
|
||
| interface InlineReasonProps { | ||
| reason?: string; | ||
| } | ||
|
|
||
| export default function InlineReason({reason}: InlineReasonProps) { | ||
| if (!reason) { | ||
| return ( | ||
| <Typography variant="body2" color="text.secondary"> | ||
| No reason given | ||
| </Typography> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box sx={{maxWidth: 300}}> | ||
| <Typography | ||
| variant="body2" | ||
| sx={{ | ||
| wordBreak: 'break-word', | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| display: '-webkit-box', | ||
| WebkitLineClamp: 3, | ||
| WebkitBoxOrient: 'vertical', | ||
| }}> | ||
| {reason} | ||
| </Typography> | ||
| </Box> | ||
| ); | ||
| } |
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.