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.
[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.
[💡 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.
[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.
[💡 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.