Skip to content

Commit

Permalink
fix: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Jan 8, 2025
1 parent a2032c3 commit 63fe07b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,22 @@ public String getStoredPath() {
return path;
}

/** Do not set directly, managed by persistence layer. */
/**
* Note that the {@code path} is mapped with the "property access" mode. Do not set directly, this
* property is managed by the persistence layer.
*/
public void setPath(String path) {
this.path = path;
}

/**
* Note that the {@code path} is mapped with the "property access" mode. This method is for unit
* testing purposes only.
*/
public void updatePath() {
setPath(getPath());
}

/**
* Used by persistence layer. Purpose is to have a column for use in database queries. For
* application use see {@link OrganisationUnit#getLevel()} which has better performance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void setUp() {

ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
ouA.getPath();
ouB.getPath();
ouA.updatePath();
ouB.updatePath();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void shouldHaveAccessWhenProgramOpenAndSearchAccessAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(OPEN);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

user.setTeiSearchOrganisationUnits(Set.of(orgUnit));

Expand All @@ -67,7 +67,7 @@ void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(OPEN);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

assertFalse(
trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit),
Expand All @@ -77,7 +77,7 @@ void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() {
@Test
void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() {
User user = new User();
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

user.setTeiSearchOrganisationUnits(Set.of(orgUnit));

Expand All @@ -89,7 +89,7 @@ void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() {
@Test
void shouldNotHaveAccessWhenProgramNullAndSearchAccessNotAvailable() {
User user = new User();
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

assertFalse(
trackerAccessManager.canAccess(UserDetails.fromUser(user), null, orgUnit),
Expand All @@ -101,7 +101,7 @@ void shouldHaveAccessWhenProgramClosedAndCaptureAccessAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(CLOSED);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

user.setOrganisationUnits(Set.of(orgUnit));

Expand All @@ -115,7 +115,7 @@ void shouldNotHaveAccessWhenProgramClosedAndCaptureAccessNotAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(CLOSED);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

assertFalse(
trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit),
Expand All @@ -127,7 +127,7 @@ void shouldHaveAccessWhenProgramProtectedAndCaptureAccessAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(PROTECTED);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

user.setOrganisationUnits(Set.of(orgUnit));

Expand All @@ -141,10 +141,17 @@ void shouldNotHaveAccessWhenProgramProtectedAndCaptureAccessNotAvailable() {
User user = new User();
Program program = new Program();
program.setAccessLevel(PROTECTED);
OrganisationUnit orgUnit = new OrganisationUnit();
OrganisationUnit orgUnit = createOrgUnit();

assertFalse(
trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit),
"User should not have access to protected program");
}

private OrganisationUnit createOrgUnit() {
OrganisationUnit ou = new OrganisationUnit();
ou.setAutoFields();
ou.updatePath();
return ou;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class OperationsParamsValidatorTest {
public void setUp() {
OrganisationUnit organisationUnit = createOrgUnit("orgUnit", PARENT_ORG_UNIT_UID);
organisationUnit.setChildren(Set.of(captureScopeOrgUnit, searchScopeOrgUnit));
organisationUnit.updatePath();
}

@Test
Expand Down Expand Up @@ -389,6 +390,7 @@ void shouldReturnOrgUnitsWhenUserIsSuperButHasNoAccessToOrgUnit()
private OrganisationUnit createOrgUnit(String name, String uid) {
OrganisationUnit orgUnit = new OrganisationUnit(name);
orgUnit.setUid(uid);
orgUnit.updatePath();
return orgUnit;
}
}

0 comments on commit 63fe07b

Please sign in to comment.