-
Notifications
You must be signed in to change notification settings - Fork 15
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
Check for approved access request #1069
Conversation
request.metadata.overview.entities.some((entity) => entities.includes(entity)), | ||
) | ||
async hasApprovedAccessRequest(user: UserDoc, model: ModelDoc) { | ||
const accessRequests = await getModelAccessRequestsForUser(user, model.id) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
backend/src/services/v2/review.ts
Outdated
@@ -188,6 +188,18 @@ export async function sendReviewResponseNotification(review: ReviewDoc, user: Us | |||
} | |||
} | |||
|
|||
export async function getApprovedAccessRequestReviews(accessRequestIds: string[]) { |
There was a problem hiding this comment.
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
.
No description provided.