Skip to content

Fix handling assignments when removed from role#71

Open
berntjoh wants to merge 8 commits into
mainfrom
fix_handling_assignments_when_removed_from_role
Open

Fix handling assignments when removed from role#71
berntjoh wants to merge 8 commits into
mainfrom
fix_handling_assignments_when_removed_from_role

Conversation

@berntjoh

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates resource fetching and flattened-assignment deletion behavior to better handle cases where a user’s resource access should remain when a role-based assignment is removed.

Changes:

  • Add a resourcefilter (list of resource IDs) to the role resources endpoint and propagate it through the response factory into the JPA Specification.
  • Extend ResourceSpecificationBuilder to filter by specific resource IDs.
  • Adjust flattened-assignment logic/tests to avoid publishing deletion when a direct user assignment still exists for the same user/resource.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/java/no/fintlabs/resource/AssignmentResourceServiceIntegrationTest.java Updates ResourceSpecificationBuilder constructor usage and adds role resource filtering tests.
src/test/java/no/fintlabs/assignment/flattened/FlattenedAssignmentServiceIntegrationTest.java Expands deletion-related integration test coverage and verifies producer interactions.
src/main/java/no/fintlabs/resource/ResourceSpecificationBuilder.java Adds resourceIds support to the built Specification.
src/main/java/no/fintlabs/resource/ResourceResponseFactory.java Adds resourceIds parameter and passes it into ResourceSpecificationBuilder.
src/main/java/no/fintlabs/resource/ResourceController.java Adds resourcefilter to role resources endpoint and forwards it to the response factory.
src/main/java/no/fintlabs/assignment/flattened/FlattenedAssignmentService.java Refines direct-assignment lookup and accounts for direct assignments when deciding whether to publish deletions.
src/main/java/no/fintlabs/assignment/flattened/FlattenedAssignmentRepository.java Updates repository method to target direct assignments (assignmentViaRoleRef IS NULL).
Comments suppressed due to low confidence (1)

src/test/java/no/fintlabs/resource/AssignmentResourceServiceIntegrationTest.java:586

  • This test stubs authorizationUtil.getAllAuthorizedOrgUnitIDs(), but getResourcesAssignedToRole(...) only uses the passed Specification/Pageable and does not consult authorizationUtil. Removing the unused stub will make the test intent clearer.
        given(authorizationUtil.getAllAuthorizedOrgUnitIDs()).willReturn(kompavdList);

        ResourceSpecificationBuilder builder = new ResourceSpecificationBuilder(null,1L,  "ALLTYPES", null, null, null, List.of(1L,2L));
        Page<AssignmentResource> rolePage = assignmentResourceService.getResourcesAssignedToRole(1L, builder.build(), Pageable.unpaged());

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/java/no/fintlabs/resource/AssignmentResourceServiceIntegrationTest.java Outdated
Comment on lines +300 to +320
//TODO optimize query to check existence only
private boolean notExistOtherActiveFlattenedAssignmentsWithSameUserRefAndResourceRef(FlattenedAssignment flattenedAssignment) {

log.info("Checking if other active flattened assignment exists for user {} and resource {}",
flattenedAssignment.getUserRef(),
flattenedAssignment.getResourceRef()
);

List<FlattenedAssignment> otherActiveAssignments = flattenedAssignmentRepository.findByAssignmentViaRoleRefNotAndUserRefAndResourceRefAndAssignmentTerminationDateIsNull(
flattenedAssignment.getAssignmentViaRoleRef(),
flattenedAssignment.getUserRef(),
flattenedAssignment.getResourceRef()
);

Optional<FlattenedAssignment> optionalFlattenedAssignment = flattenedAssignmentRepository.
findByAssignmentViaRoleRefIsNullAndUserRefAndResourceRefAndAssignmentTerminationDateIsNull(
flattenedAssignment.getUserRef(),
flattenedAssignment.getResourceRef()
);
optionalFlattenedAssignment.ifPresent(otherActiveAssignments::add);

@berntjoh berntjoh May 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chadaj I think it should be left as it is for now. When the new table for flattened assignments to Entra is in place this code will be changed removed I think. We may have a huddle about this on monday 18.

Comment on lines +531 to +532
given(authorizationUtil.getAllAuthorizedOrgUnitIDs()).willReturn(kompavdList);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chadaj I removed the test stubs as suggested by CoPilot.

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