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

Feature/bai 1485 manual user access #1624

Merged
merged 21 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a4509ce
wip, added manual entity input
ARADDCC002 Nov 13, 2024
4f1836c
added a new function for user info look up as non-hook. added ability…
ARADDCC002 Nov 13, 2024
d580281
updated backend to check for invalid users
ARADDCC002 Nov 13, 2024
40131db
moved manual user access form to its own component
ARADDCC002 Nov 14, 2024
c1fa402
wip
ARADDCC002 Nov 18, 2024
71d82a2
more changes from pr comments and merged main
ARADDCC002 Nov 18, 2024
7352462
wip
ARADDCC002 Nov 19, 2024
7b41a6e
updated model service to check for user auth on both update and creat…
ARADDCC002 Nov 20, 2024
39e5525
fixed an issue with config map
ARADDCC002 Nov 20, 2024
cd0d01d
addressed more pr comments and improved some of logic
ARADDCC002 Nov 20, 2024
e244ae9
improved duplicate entity checking when manually adding collaboratores
ARADDCC002 Nov 20, 2024
d7ae9a7
updated various names of components and values for manual user access
ARADDCC002 Nov 21, 2024
a8baf9f
added migration script for removing invalid users
ARADDCC002 Nov 22, 2024
5b8ad95
added a check for new collabs
ARADDCC002 Nov 25, 2024
14a1020
changes to new user auth checking error throwing
ARADDCC002 Nov 25, 2024
549b3f8
changes to new user auth checking error throwing
ARADDCC002 Nov 25, 2024
5d5e4f7
removed uneeded unit tests
ARADDCC002 Nov 25, 2024
540b126
updated collaborator validation function name
ARADDCC002 Nov 25, 2024
72eabf5
added a check so that only users are checked by auth connector
ARADDCC002 Nov 26, 2024
2fd33d6
improved entity kind check for new collaborators
ARADDCC002 Nov 26, 2024
27697e6
readded userinformation error unit tests
ARADDCC002 Nov 26, 2024
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
10 changes: 8 additions & 2 deletions frontend/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ interface UserInformationResponse {
entity: UserInformation
}

export function useGetUserInformation(dn: string) {
export function useGetUserInformation(dn: string, kind?: string) {
const { data, isLoading, error, mutate } = useSWR<UserInformationResponse, ErrorInfo>(
`/api/v2/entity/${dn}/lookup`,
`/api/v2/entity/${dn}/lookup${kind ? `?kind=${kind}` : ''}`,
fetcher,
)

Expand All @@ -63,6 +63,12 @@ export function useGetUserInformation(dn: string) {
}
}

export function getUserInformation(dn: string) {
return fetch(`/api/v2/entity/${dn}/lookup`, {
headers: { 'Content-Type': 'application/json' },
})
}

interface GetUserTokensResponse {
tokens: TokenInterface[]
}
Expand Down
70 changes: 67 additions & 3 deletions frontend/src/entry/settings/EntryAccessInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { Autocomplete, Stack, Table, TableBody, TableCell, TableHead, TableRow, TextField } from '@mui/material'
import { useListUsers } from 'actions/user'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import {
Accordion,
AccordionDetails,
AccordionSummary,
Autocomplete,
Button,
Stack,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
Typography,
} from '@mui/material'
import { getUserInformation, useListUsers } from 'actions/user'
import { debounce } from 'lodash-es'
import { SyntheticEvent, useCallback, useEffect, useMemo, useState } from 'react'
import EntityItem from 'src/entry/settings/EntityItem'
import MessageAlert from 'src/MessageAlert'
import { CollaboratorEntry, EntityObject, EntryKindKeys, Role } from 'types/types'
import { CollaboratorEntry, EntityKind, EntityObject, EntryKindKeys, Role } from 'types/types'
import { getErrorMessage } from 'utils/fetcher'
import { toSentenceCase } from 'utils/stringUtils'

type EntryAccessInputProps = {
Expand All @@ -27,6 +43,8 @@ export default function EntryAccessInput({ value, onUpdate, entryKind, entryRole
const [open, setOpen] = useState(false)
const [accessList, setAccessList] = useState<CollaboratorEntry[]>(value)
const [userListQuery, setUserListQuery] = useState('')
const [manualEntityName, setManualEntityName] = useState('')
const [errorMessage, setErrorMessage] = useState('')

const { users, isUsersLoading, isUsersError } = useListUsers(userListQuery)

Expand Down Expand Up @@ -75,6 +93,23 @@ export default function EntryAccessInput({ value, onUpdate, entryKind, entryRole
handleInputChange(event, value)
}, 500)

const handleAddEntityManuallyOnClick = useCallback(async () => {
setErrorMessage('')
if (manualEntityName !== undefined && manualEntityName !== '') {
if (accessList.find((collaborator) => collaborator.entity === `${EntityKind.USER}:${manualEntityName}`)) {
return setErrorMessage(`The requested user has already been added below.`)
}
const response = await getUserInformation(manualEntityName)
if (!response.ok) {
return setErrorMessage(await getErrorMessage(response))
}
const updatedAccessList = [...accessList]
const newAccess = { entity: `${EntityKind.USER}:${manualEntityName}`, roles: [] }
updatedAccessList.push(newAccess)
setAccessList(updatedAccessList)
}
}, [accessList, manualEntityName])

const noOptionsText = useMemo(() => {
if (userListQuery.length < 3) return 'Please enter at least three characters'
if (isUsersError?.status === 413) return 'Too many results, please refine your search'
Expand Down Expand Up @@ -113,6 +148,35 @@ export default function EntryAccessInput({ value, onUpdate, entryKind, entryRole
/>
)}
/>
<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 }}>
<Stack spacing={2} direction={{ xs: 'column', sm: 'row' }}>
<TextField
id='manual-entity-name-select'
placeholder='Joe Bloggs'
size='small'
fullWidth
label='User'
value={manualEntityName}
onChange={(e) => setManualEntityName(e.target.value)}
/>
<Button variant='contained' onClick={handleAddEntityManuallyOnClick}>
Add
</Button>
</Stack>
<MessageAlert message={errorMessage} severity='error' />
</AccordionDetails>
</Accordion>
<Table>
<TableHead>
<TableRow>
Expand Down
Loading