-
Notifications
You must be signed in to change notification settings - Fork 2
Consider a copilot to have "full access" to a challenge (PM-2654) #6
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
Conversation
| * @param {Array} resources resources of current user for specified challenge id | ||
| */ | ||
| async function checkAccess (currentUserResources) { | ||
| const copilotRoleIds = await getCopilotResourceRoleIds() |
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.
[performance]
Consider caching the result of getCopilotResourceRoleIds() if it is expected to be called frequently. This could improve performance by reducing database queries.
| */ | ||
| async function checkAccess (currentUserResources) { | ||
| const copilotRoleIds = await getCopilotResourceRoleIds() | ||
| const hasCopilotRole = _.some(currentUserResources, r => copilotRoleIds.includes(r.roleId)) |
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.
[💡 performance]
The use of _.some with includes is correct, but ensure that currentUserResources and copilotRoleIds are not excessively large, as this could impact performance. If they are, consider optimizing the data structure or approach.
| }) | ||
|
|
||
| it('copilot can manage resources without full access flags', async () => { | ||
| const originalRole = await helper.getById('ResourceRole', copilotRoleId) |
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.
[correctness]
The test case modifies the ResourceRole to have no full access flags and then attempts to create a resource with a user that might not have the necessary permissions. Ensure that the test setup accurately reflects the intended permissions and that the test case is valid under the new role configuration.
| await assertResource(createdResource.id, createdResource) | ||
| } finally { | ||
| if (createdResource && createdResource.id) { | ||
| await prisma.resource.deleteMany({ |
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.
[💡 maintainability]
Consider using delete instead of deleteMany if you are certain that only one resource will be deleted. This can prevent accidental deletion of multiple resources if the query conditions are not as expected.
No description provided.