Skip to content

Conversation

@jmgasper
Copy link
Contributor

@jmgasper jmgasper commented Nov 1, 2025

No description provided.

@jmgasper jmgasper merged commit f1440b6 into master Nov 1, 2025
4 checks passed
* @returns {Promise<Array<String>>} Array of restricted role IDs
*/
async function getRestrictedRoleIds () {
if (restrictedRoleIdsCache) {
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The caching mechanism for restrictedRoleIdsCache does not account for changes in the database. If roles are updated externally, the cache might become stale. Consider implementing a cache invalidation strategy or a mechanism to refresh the cache periodically.

*/
async function checkAccess (currentUserResources) {
const copilotRoleIds = await getCopilotResourceRoleIds()
const hasCopilotRole = _.some(currentUserResources, r => copilotRoleIds.includes(r.roleId))
Copy link

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 to check for copilot roles could be replaced with Array.prototype.some for better readability and performance, as native methods are generally faster.

)
}
// Check if user already has a restricted role (Manager, Copilot, Reviewer, etc.)
const existingRestrictedRole = _.find(userResources, r => restrictedRoleIds.includes(r.roleId))
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The error message construction using RESTRICTED_ROLE_NAMES assumes that the list will not change. If roles are added or removed, the message might become inaccurate. Consider dynamically constructing the message based on the actual roles retrieved from the database.

// Check if user is trying to assign a restricted role and already has submitter role
if (isCreated) {
if (restrictedRoleIds.includes(resource.roleId)) {
const existingSubmitterRole = _.find(userResources, r => r.roleId === config.SUBMITTER_RESOURCE_ROLE_ID)
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The logic for checking if a user is trying to assign a restricted role while already having a submitter role is duplicated in multiple places. Consider refactoring this logic into a separate function to improve maintainability and reduce code duplication.

})

it('copilot can manage resources without full access flags', async () => {
const originalRole = await helper.getById('ResourceRole', copilotRoleId)
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
Consider adding error handling for the helper.getById call. If this call fails or returns an unexpected result, it could cause the test to behave unpredictably.

should.equal(createdResource.memberHandle.toLowerCase(), entity.memberHandle.toLowerCase())
await assertResource(createdResource.id, createdResource)
} finally {
if (createdResource && createdResource.id) {
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The cleanup logic in the finally block is crucial for maintaining test isolation. Ensure that any errors during the prisma.resource.deleteMany call are logged or handled to avoid silent failures.

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