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

Check for approved access request #1069

Conversation

JR40159
Copy link
Member

@JR40159 JR40159 commented Feb 5, 2024

No description provided.

request.metadata.overview.entities.some((entity) => entities.includes(entity)),
)
async hasApprovedAccessRequest(user: UserDoc, model: ModelDoc) {
const accessRequests = await getModelAccessRequestsForUser(user, model.id)
Copy link
Member

Choose a reason for hiding this comment

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

I would expect this to be a service function, not in a connector.

Also, the implementation is a little odd. I wouldn't tend to handle the edge case of no access requests. The speed increase likely isn't worth the complexity?

const accessRequests = await getModelAccessRequestsForUser(user, model.id)
return await hasApprovedAccessRequestReview(accessRequests.map((accessRequest) => accessRequest.id))

If you did want to keep the check, I'd expect something like:

const accessRequests = await getModelAccessRequestsForUser(user, model.id)

if (accessRequests.length === 0) {
  return false
}

const ids = accessRequests.map(request => request.id)
return hasApprovedAccessRequestReview(ids)

Copy link
Member Author

@JR40159 JR40159 Feb 6, 2024

Choose a reason for hiding this comment

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

"I would expect this to be a service function, not in a connector." - This was mainly done because the previous implementation made the same decision to make this function in the connector rather than a service. Additionally, it's unclear to me which service this function would belong to as uses both access requests and reviews to make the decision.

"The speed increase likely isn't worth the complexity?" - The complexity to me seems very minimal considering it's a single if statement to avoid an unnecessary database query, I'd happy to reverse the if statement.

@@ -80,6 +80,9 @@ export async function getFilesByModel(user: UserDoc, modelId: string) {

export async function getFilesByIds(user: UserDoc, modelId: string, fileIds: string[]) {
const model = await getModelById(user, modelId)
if (fileIds.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

If you're going to add edge case checks like this, they should probably be at the top of the function. Did you put it down here so that we're still checking model authorisation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

@@ -188,6 +188,18 @@ export async function sendReviewResponseNotification(review: ReviewDoc, user: Us
}
}

export async function getApprovedAccessRequestReviews(accessRequestIds: string[]) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't really getApprovedAccessRequestReviews. get implies you're returning something. Instead I'd name this checkAccessRequestsApproved.

@JR40159 JR40159 marked this pull request as ready for review February 9, 2024 12:53
@JR40159 JR40159 merged commit b7353be into main Feb 9, 2024
16 checks passed
@JR40159 JR40159 deleted the feature/BAI-1132-access-requests-should-be-approved-before-providing-access-to-model-binaries branch February 9, 2024 13:32
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.

2 participants