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

Conversation

ARADDCC002
Copy link
Member

No description provided.

@@ -319,6 +322,18 @@ export async function updateModel(user: UserInterface, modelId: string, modelDif
if (modelDiff.settings?.mirror?.destinationModelId && modelDiff.settings?.mirror?.sourceModelId) {
throw BadReq('You cannot select both mirror settings simultaneously.')
}
if (modelDiff.collaborators) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pull this functionality out into its own function? It would be useful to reuse this logic in create model as well

@@ -319,6 +322,18 @@ export async function updateModel(user: UserInterface, modelId: string, modelDif
if (modelDiff.settings?.mirror?.destinationModelId && modelDiff.settings?.mirror?.sourceModelId) {
throw BadReq('You cannot select both mirror settings simultaneously.')
}
if (modelDiff.collaborators) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add tests for this! :)

if (modelDiff.collaborators) {
const invalidUsers = []
modelDiff.collaborators.forEach(async (collaborator) => {
const userInformation = await authentication.getUserInformation(collaborator.entity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should throw an error if the user can't be found. It's a bit difficult as this uses our connectors and the implementation could be anything but hopefully the typing of getUserInformation() can enforce that it can't just return nothing

@@ -335,6 +342,39 @@ export async function updateModel(user: UserInterface, modelId: string, modelDif
return model
}

async function checkCollaboratorAuthorisation(collaborators: CollaboratorEntry[]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the name of this to validateCollaborators as this function isn't related to authorisation?

throw BadReq('Collaborator name must be a valid string')
}
try {
await authentication.getUserInformation(collaborator.entity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it would be good to only do this check on just the collaborators that have been added to save having to make repeated external calls for entities that have already been validated. However, this would mean having to do a DB call to get the existing collaborators array so you could diff it with this one

@@ -16,7 +16,8 @@ export default function ManualEntityInput({ onAddEntityManually, errorMessage }:

const { uiConfig, isUiConfigLoading, isUiConfigError } = useGetUiConfig()

const handleAddEntityManuallyOnClick = async () => {
const handleAddEntityManuallyOnClick = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not always clear what behaviour we're trying to prevent when doing this sort of thing. Can we add a brief comment to explain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stops the page from refreshing when you submit the form

@@ -195,6 +195,10 @@ module.exports = {
text: '',
startTimestamp: '',
},

helpPopoverText: {
manualEntryAccess: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some generic info that could provide some help?

throw BadReq('Collaborator name must be a valid string')
}
try {
await authentication.getUserInformation(collaborator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will only work for users. If the new UI functionality only works for users and not groups, I'm happy that checking the validity of groups is out of scope for this. However, the collaborator you are checking here must be a user.

await authentication.getUserInformation(collaborator)
} catch (err) {
if (err instanceof Error && err.name === 'Not Found') {
throw NotFound(`Unable to find user ${collaborator}`, { err })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any point in catching a not found, then throwing a not found. I thought we might want to catch a not found and then throw a bad request. If we do want to throw a not found here, I don't think this catch is required and whatever gets thrown by getUserInformation() should just propagate up.

@@ -335,6 +342,53 @@ export async function updateModel(user: UserInterface, modelId: string, modelDif
return model
}

export async function checkCollaboratorAuthorisation(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't check authorisation, could we change the name to something like validateCollaborators

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you shouldn't need to export it as it should only be used from within this file?

Copy link
Member

@JR40159 JR40159 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for a release.

@ARADDCC002 ARADDCC002 merged commit e2d0623 into main Nov 27, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants