Skip to content

chore: Refactor relationship validations [DHIS2-20158]#23866

Merged
muilpp merged 3 commits into
masterfrom
DHIS2-20158-relationships
May 13, 2026
Merged

chore: Refactor relationship validations [DHIS2-20158]#23866
muilpp merged 3 commits into
masterfrom
DHIS2-20158-relationships

Conversation

@muilpp

@muilpp muilpp commented May 11, 2026

Copy link
Copy Markdown
Contributor

This is the last PR of the Tracker Access Manager refactor.
This one includes:
Refactoring the Relationship methods in TrackerAccessManager from List<String> to List<ErrorMessage>.
Stopping SecurityRelationshipValidator from always emitting a single blanket E4020 and instead forwards the actual per check error codes from canCreate/canDelete.
Introducing E4019 (missing RelationshipType read access)
Renaming E4020’s message to correctly refer to “RelationshipType”.
Fixing two test bugs (wrong user injection and duplicate word in a test name), and adds unit tests for E4019.

@muilpp
muilpp marked this pull request as ready for review May 11, 2026 13:17
@muilpp
muilpp requested a review from a team as a code owner May 11, 2026 13:17
.toList();
return canUpdate(user, event, event.getOrganisationUnit(), event.getAttributeOptionCombo());
}
if (item.getSingleEvent() != null) return canCreate(user, item.getSingleEvent());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why here are we using canCreate and not canUpdate?

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.

No reason. They are effectively the same thing, as the org unit and cat combo are not updated when validating relationships.
Anyway, I'll use canUpdate instead, just to be consistent with how we do it for tracker events.

* @return No errors if the user has capture scope access and write access to the TET.
*/
List<ErrorMessage> canCreate(@Nonnull UserDetails user, TrackedEntity trackedEntity);
List<ErrorMessage> canCreate(UserDetails user, TrackedEntity trackedEntity);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Following https://github.com/dhis2/wow-backend/blob/master/guides/code-guide.md#nullability--immutability, I would use @Nonnull annotation in all the places that makes sense in the interface (and then in the implementation)

@enricocolasante
enricocolasante requested a review from a team May 12, 2026 06:55
@sonarqubecloud

Copy link
Copy Markdown

@muilpp
muilpp requested a review from teleivo May 12, 2026 14:39
@muilpp
muilpp merged commit d409d36 into master May 13, 2026
21 of 22 checks passed
@muilpp
muilpp deleted the DHIS2-20158-relationships branch May 13, 2026 08:55
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.

3 participants