Skip to content

Commit

Permalink
feat: allow agency (super) admin to view all agencies e.g. no tenant …
Browse files Browse the repository at this point in the history
…filter is applied (currently we add a isNotNull)
  • Loading branch information
patric-dosch-vi committed Mar 18, 2024
1 parent ab3488f commit f50171a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public void deleteAgency(Long agencyId) {
this.appointmentService.deleteAgency(agency);
}

/**
* Returns all agencies for the provided tenant ID.
*
* @param tenantId the provided tenantId
*/
public List<Agency> getAgenciesByTenantId(Long tenantId) {
return this.agencyTenantUnawareRepository.findByTenantId(tenantId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ protected Predicate[] createSearchAgenciesWithKeywordFilterPredicate(
agencyAdminFilterPredicate(criteriaBuilder, root)};
}

protected Predicate tenantPredicate(CriteriaBuilder criteriaBuilder,
Root<Agency> root) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get(TENANT_ID_SEARCH_FIELD),
TenantContext.getCurrentTenant()));
protected Predicate tenantPredicate(CriteriaBuilder criteriaBuilder, Root<Agency> root) {
if (authenticatedUser.isAgencySuperAdmin()) {
return criteriaBuilder.isNotNull(root.get(TENANT_ID_SEARCH_FIELD));
} else {
return criteriaBuilder.and(
criteriaBuilder.equal(
root.get(TENANT_ID_SEARCH_FIELD), TenantContext.getCurrentTenant()));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,30 @@ public void setUp() {
void searchAgency_Should_FindAllAgenciesForGivenTenant() {
// given, when
var agencySearchResult = agencyAdminSearchTenantSupportService.searchAgencies("", 1, 10, new Sort());

// then
assertThat(agencySearchResult.getTotal()).isEqualTo(2);
assertThat(agencySearchResult.getEmbedded())
.isNotEmpty()
.hasSize(2)
.extracting("embedded.id").containsOnly(1735L, 1737L);
}

@Test
void searchAgency_Should_FindAllAgenciesForAllTenants_WhenUserIsSuperAdmin() {
// given
when(authenticatedUser.isAgencySuperAdmin()).thenReturn(true);
when(securityHeaderSupplier.getKeycloakAndCsrfHttpHeaders()).thenReturn(new HttpHeaders());

// when
var agencySearchResult = agencyAdminSearchTenantSupportService.searchAgencies("", 1, 1138, new Sort());

// then
assertThat(agencySearchResult.getEmbedded()).isNotEmpty();
assertThat(agencySearchResult.getEmbedded()).hasSize(2);
assertThat(agencySearchResult.getEmbedded()).extracting("embedded.id").containsOnly(1735L, 1737L);
assertThat(agencySearchResult.getTotal()).isEqualTo(3);
assertThat(agencySearchResult.getEmbedded())
.isNotEmpty()
.hasSize(3)
.extracting("embedded.id").contains(1735L, 1737L, 1738L);
}

@Test
Expand All @@ -78,8 +98,11 @@ void searchAgency_Should_FindOnlyAgenciesManagedByTheAdminAndInTheTenant_WhenUse
var agencySearchResult = agencyAdminSearchTenantSupportService.searchAgencies("", 1, 10, new Sort());

// then
assertThat(agencySearchResult.getEmbedded()).hasSize(1);
assertThat(agencySearchResult.getEmbedded()).extracting("embedded.id").containsOnly(1735L);
assertThat(agencySearchResult.getTotal()).isEqualTo(1);
assertThat(agencySearchResult.getEmbedded())
.isNotEmpty()
.hasSize(1)
.extracting("embedded.id").containsOnly(1735L);
}

@Test
Expand All @@ -105,4 +128,4 @@ private AdminAgencyResponseDTO getAdminAgencies(Long... agencyIds) {
}
return adminAgencyResponseDTO;
}
}
}
5 changes: 3 additions & 2 deletions src/test/resources/database/AgencyDatabase.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,10 @@ INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AG
INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE) VALUES (1732, null, 'Hospice Test', '', '20255', 'Hamburg', 0, 18, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null);
INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE) VALUES (1733, null, 'Regional Test', '', '45879', 'Gelsenkirchen', 0, 19, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null);
INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE) VALUES (1734, null, 'Ohne Postcoderanges', '', '45879', 'Gelsenkirchen', 0, 19, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null);
INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE, COUNSELLING_RELATIONS) VALUES (1735, 1, 'With tenant id', '', '45879', 'Freiburg', 0, 20, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null, 'PARENTAL_COUNSELLING,RELATIVE_COUNSELLING');

-- insert agencies with demographics
INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE, COUNSELLING_RELATIONS)
VALUES (1735, 1, 'With tenant id', '', '45879', 'Freiburg', 0, 20, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null, 'PARENTAL_COUNSELLING,RELATIVE_COUNSELLING');

INSERT INTO AGENCY (ID, TENANT_ID, NAME, DESCRIPTION, POSTCODE, CITY, IS_TEAM_AGENCY, CONSULTING_TYPE, IS_OFFLINE, URL, IS_EXTERNAL, ID_OLD, CREATE_DATE, UPDATE_DATE, DELETE_DATE, AGE_FROM, AGE_TO, GENDERS)
VALUES (1736, null, 'With demographics 1', '', '45879', 'Gelsenkirchen with Demographics', 0, 19, 0, null, 0, null, '2020-05-11 10:33:40', '2020-05-11 10:33:40', null, 15, 100, 'MALE');

Expand Down

0 comments on commit f50171a

Please sign in to comment.