Fix handling assignments when removed from role#71
Conversation
… into fix_handling_assignments_when_removed_from_role # Conflicts: # src/main/java/no/fintlabs/assignment/flattened/FlattenedAssignmentRepository.java
There was a problem hiding this comment.
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 JPASpecification. - Extend
ResourceSpecificationBuilderto 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(), butgetResourcesAssignedToRole(...)only uses the passedSpecification/Pageableand does not consultauthorizationUtil. 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.
| //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); | ||
|
|
There was a problem hiding this comment.
@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.
| given(authorizationUtil.getAllAuthorizedOrgUnitIDs()).willReturn(kompavdList); | ||
|
|
There was a problem hiding this comment.
@chadaj I removed the test stubs as suggested by CoPilot.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
No description provided.