-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1624 from gchq/feature/BAI-1485-manual-user-access
Feature/bai 1485 manual user access
- Loading branch information
Showing
15 changed files
with
241 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
backend/src/migrations/011_find_and_remove_invalid_users.ts
This file contains 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,44 @@ | ||
import authentication from '../connectors/authentication/index.js' | ||
import { MigrationMetadata } from '../models/Migration.js' | ||
import ModelModel from '../models/Model.js' | ||
|
||
/** | ||
* As we now do backend validation for users being added to model access lists, we | ||
* added this script to find and remove all existing users that do not pass the | ||
* "getUserInformation" call in the authentication connector. You can find a | ||
* list of removed users for all affected models by looking at the "metadata" | ||
* property of this migration's database object. | ||
**/ | ||
|
||
export async function up() { | ||
const models = await ModelModel.find({}) | ||
const metadata: MigrationMetadata[] = [] | ||
for (const model of models) { | ||
const invalidUsers: string[] = [] | ||
await Promise.all( | ||
model.collaborators.map(async (collaborator) => { | ||
if (collaborator.entity !== '') { | ||
try { | ||
await authentication.getUserInformation(collaborator.entity) | ||
} catch (err) { | ||
invalidUsers.push(collaborator.entity) | ||
} | ||
} | ||
}), | ||
) | ||
if (invalidUsers.length > 0) { | ||
const invalidUsersForModel = { modelId: model.id, invalidUsers: invalidUsers } | ||
const invalidUsersRemoved = model.collaborators.filter( | ||
(collaborator) => !invalidUsers.includes(collaborator.entity), | ||
) | ||
model.collaborators = invalidUsersRemoved | ||
await model.save() | ||
metadata.push(invalidUsersForModel) | ||
} | ||
} | ||
return metadata | ||
} | ||
|
||
export async function down() { | ||
/* NOOP */ | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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,68 @@ | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' | ||
import { Accordion, AccordionDetails, AccordionSummary, Box, Button, Stack, TextField, Typography } from '@mui/material' | ||
import { useGetUiConfig } from 'actions/uiConfig' | ||
import { FormEvent, useState } from 'react' | ||
import HelpPopover from 'src/common/HelpPopover' | ||
import Loading from 'src/common/Loading' | ||
import MessageAlert from 'src/MessageAlert' | ||
|
||
interface ManualEntityInputProps { | ||
onAddEntityManually: (entityName: string) => void | ||
errorMessage: string | ||
} | ||
|
||
export default function ManualEntityInput({ onAddEntityManually, errorMessage }: ManualEntityInputProps) { | ||
const [manualEntityName, setManualEntityName] = useState('') | ||
|
||
const { uiConfig, isUiConfigLoading, isUiConfigError } = useGetUiConfig() | ||
|
||
const handleAddEntityManuallyOnClick = (event: FormEvent<HTMLFormElement>) => { | ||
event.preventDefault() | ||
if (manualEntityName !== undefined && manualEntityName !== '') { | ||
setManualEntityName('') | ||
onAddEntityManually(manualEntityName) | ||
} | ||
} | ||
|
||
if (isUiConfigError) { | ||
return <MessageAlert message={isUiConfigError.info.message} severity='error' /> | ||
} | ||
|
||
return ( | ||
<Accordion sx={{ borderTop: 'none' }}> | ||
<AccordionSummary | ||
sx={{ pl: 0, borderTop: 'none' }} | ||
expandIcon={<ExpandMoreIcon />} | ||
aria-controls='manual-user-add-content' | ||
id='manual-user-add-header' | ||
> | ||
<Typography sx={{ mr: 1 }} component='caption'> | ||
Trouble finding a user? Click here to add them manually | ||
</Typography> | ||
</AccordionSummary> | ||
<AccordionDetails sx={{ p: 0 }}> | ||
{isUiConfigLoading && <Loading />} | ||
{!isUiConfigLoading && uiConfig && ( | ||
<Box component='form' onSubmit={handleAddEntityManuallyOnClick}> | ||
<Stack spacing={2} direction={{ xs: 'column', sm: 'row' }} alignItems='center'> | ||
<TextField | ||
size='small' | ||
fullWidth | ||
label='User' | ||
value={manualEntityName} | ||
onChange={(e) => setManualEntityName(e.target.value)} | ||
/> | ||
{uiConfig.helpPopoverText.manualEntryAccess && ( | ||
<HelpPopover>{uiConfig.helpPopoverText.manualEntryAccess}</HelpPopover> | ||
)} | ||
<Button variant='contained' type='submit' disabled={manualEntityName === ''}> | ||
Add | ||
</Button> | ||
</Stack> | ||
</Box> | ||
)} | ||
<MessageAlert message={errorMessage} severity='error' /> | ||
</AccordionDetails> | ||
</Accordion> | ||
) | ||
} |
Oops, something went wrong.