Skip to content

Commit

Permalink
fix: Accessible ouMode per program protection level [2.38-DHIS2-11755] (
Browse files Browse the repository at this point in the history
dhis2#9075)

* fix: OuMode validation in event query

* chore: More readable error messages.

* chore: Code formatting

* fix: Accessible ouMode per program protection level

* Revert "fix: Accessible ouMode per program protection level"

This reverts commit edc2703.

* fix: Accessible ouMode per program protection level

* fix: OuMode validation in event query
  • Loading branch information
abyot authored Oct 20, 2021
1 parent 7a29e75 commit bbaa9c4
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ private List<OrganisationUnit> getOrganisationUnits( EventSearchParams params, U
case CAPTURE:
organisationUnits = getCaptureOrgUnits( user );
break;
case SELECTED:
organisationUnits = getSelectedOrgUnits( params );
break;
default:
organisationUnits = getAccessibleOrgUnits( params, user );
break;
Expand Down Expand Up @@ -889,6 +892,16 @@ private List<OrganisationUnit> getChildrenOrgUnits( EventSearchParams params )
.map( BaseIdentifiableObject::getUid ).collect( Collectors.toList() ) );
}

private List<OrganisationUnit> getSelectedOrgUnits( EventSearchParams params )
{
if ( params.getOrgUnit() == null )
{
throw new IllegalQueryException( "Organisation unit is required to use SELECTED scope. " );
}

return Collections.singletonList( params.getOrgUnit() );
}

private List<OrganisationUnit> getDescendantOrgUnits( EventSearchParams params )
{
if ( params.getOrgUnit() == null )
Expand Down Expand Up @@ -917,11 +930,16 @@ private List<OrganisationUnit> getAccessibleOrgUnits( EventSearchParams params,
throw new IllegalQueryException( "User is required to use ACCESSIBLE scope." );
}

Set<OrganisationUnit> orgUnits = user.getTeiSearchOrganisationUnitsWithFallback();
Set<OrganisationUnit> orgUnits = user.getOrganisationUnits();

if ( params.getProgram() != null && params.getProgram().isWithoutRegistration() )
if ( params.getProgram() != null )
{
orgUnits = user.getDataViewOrganisationUnitsWithFallback();
orgUnits = user.getTeiSearchOrganisationUnitsWithFallback();

if ( params.getProgram().isClosed() )
{
orgUnits = user.getOrganisationUnits();
}
}

return organisationUnitService.getOrganisationUnitsWithChildren( orgUnits.stream()
Expand Down

0 comments on commit bbaa9c4

Please sign in to comment.