Skip to content

Commit

Permalink
#2804: Replace direct usage of user roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Marin authored and ChristopherRiedel committed Mar 15, 2022
1 parent d874e30 commit 80d8208
Show file tree
Hide file tree
Showing 74 changed files with 733 additions and 539 deletions.
Expand Up @@ -138,4 +138,5 @@ List<ContactFollowUpDto> getContactFollowUpList(
void updateCompleteness(String uuid);

void updateExternalData(@Valid List<ExternalDataDto> externalData) throws ExternalDataUpdateException;

}
Expand Up @@ -485,7 +485,7 @@ public interface Captions {
String caseFilterWithDifferentRegion = "caseFilterWithDifferentRegion";
String caseFilterWithExtendedQuarantine = "caseFilterWithExtendedQuarantine";
String caseFilterWithoutGeo = "caseFilterWithoutGeo";
String caseFilterWithoutResponsibleOfficer = "caseFilterWithoutResponsibleOfficer";
String caseFilterWithoutResponsibleUser = "caseFilterWithoutResponsibleUser";
String caseFilterWithReducedQuarantine = "caseFilterWithReducedQuarantine";
String caseFollowupVisitsView = "caseFollowupVisitsView";
String CaseHospitalization = "CaseHospitalization";
Expand Down
Expand Up @@ -42,7 +42,7 @@ public interface Descriptions {
String descCaseFilterRelatedToEvent = "descCaseFilterRelatedToEvent";
String descCaseFilterWithExtendedQuarantine = "descCaseFilterWithExtendedQuarantine";
String descCaseFilterWithoutGeo = "descCaseFilterWithoutGeo";
String descCaseFilterWithoutResponsibleOfficer = "descCaseFilterWithoutResponsibleOfficer";
String descCaseFilterWithoutResponsibleUser = "descCaseFilterWithoutResponsibleUser";
String descCaseFilterWithReducedQuarantine = "descCaseFilterWithReducedQuarantine";
String descCommunityFilter = "descCommunityFilter";
String descContactIncludeContactsFromOtherJurisdictions = "descContactIncludeContactsFromOtherJurisdictions";
Expand Down
Expand Up @@ -81,6 +81,7 @@ public class UserDto extends EntityDto {
private LocationDto address;

private Set<UserRole> userRoles;
private Set<UserRight> userRights;

private RegionReferenceDto region;
private DistrictReferenceDto district;
Expand Down Expand Up @@ -176,6 +177,14 @@ public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}

public Set<UserRight> getUserRights() {
return userRights;
}

public void setUserRights(Set<UserRight> userRights) {
this.userRights = userRights;
}

@Override
public String toString() {
return UserReferenceDto.buildCaption(firstName, lastName, userRoles);
Expand Down
18 changes: 7 additions & 11 deletions sormas-api/src/main/java/de/symeda/sormas/api/user/UserFacade.java
Expand Up @@ -50,9 +50,9 @@ public interface UserFacade {

UserDto getByUserName(String userName);

List<UserReferenceDto> getUsersByRegionAndRoles(RegionReferenceDto regionRef, UserRole... assignableRoles);
List<UserReferenceDto> getUsersByRegionAndRights(RegionReferenceDto regionRef, UserRight... userRights);

List<UserReferenceDto> getUsersByRegionsAndRoles(List<RegionReferenceDto> regionRefs, UserRole... assignableRoles);
List<UserReferenceDto> getUsersByRegionsAndRights(List<RegionReferenceDto> regionRefs, UserRight... userRights);

List<UserReferenceDto> getUsersWithSuperiorJurisdiction(UserDto user);

Expand All @@ -64,19 +64,17 @@ public interface UserFacade {

/**
* @param district
* @param includeSupervisors
* independent from the district
* @param userRoles
* roles of the users by district
* @param userRights
* rights of the users by district
* @return
*/
List<UserReferenceDto> getUserRefsByDistrict(DistrictReferenceDto district, boolean includeSupervisors, UserRole... userRoles);
List<UserReferenceDto> getUserRefsByDistrict(DistrictReferenceDto district, UserRight... userRights);

List<UserReferenceDto> getUserRefsByDistricts(List<DistrictReferenceDto> districts, boolean includeSupervisors, UserRole... userRoles);
List<UserReferenceDto> getUserRefsByDistricts(List<DistrictReferenceDto> districts, UserRight... userRights);

List<UserReferenceDto> getAllUserRefs(boolean includeInactive);

List<UserDto> getUsersByAssociatedOfficer(UserReferenceDto associatedOfficer, UserRole... userRoles);
List<UserDto> getUsersByAssociatedOfficer(UserReferenceDto associatedOfficer, UserRight... userRights);

List<String> getAllUuids();

Expand Down Expand Up @@ -107,6 +105,4 @@ public interface UserFacade {
List<UserReferenceDto> getUsersHavingTravelEntryInJurisdiction(TravelEntryReferenceDto travelEntryReferenceDto);

List<UserReferenceWithTaskNumbersDto> getAssignableUsersWithTaskNumbers(@NotNull TaskContextIndex taskContextIndex);

List<UserReferenceDto> getUsersByRegionAndRight(RegionReferenceDto region, UserRight userRight);
}
18 changes: 18 additions & 0 deletions sormas-api/src/main/java/de/symeda/sormas/api/user/UserRight.java
Expand Up @@ -231,6 +231,11 @@ public enum UserRight {
ADMIN,
ADMIN_SUPERVISOR
),
CASE_RESPONSIBLE(
SURVEILLANCE_SUPERVISOR,
ADMIN_SUPERVISOR,
SURVEILLANCE_OFFICER
),
IMMUNIZATION_VIEW(
ADMIN,
NATIONAL_USER,
Expand Down Expand Up @@ -592,6 +597,9 @@ public enum UserRight {
ADMIN,
ADMIN_SUPERVISOR
),
CONTACT_RESPONSIBLE(
CONTACT_OFFICER
),
MANAGE_EXTERNAL_SYMPTOM_JOURNAL(
NATIONAL_USER,
CONTACT_SUPERVISOR,
Expand Down Expand Up @@ -816,6 +824,10 @@ public enum UserRight {
NATIONAL_USER,
ADMIN_SUPERVISOR
),
EVENT_RESPONSIBLE(
SURVEILLANCE_SUPERVISOR,
SURVEILLANCE_OFFICER
),
EVENTPARTICIPANT_ARCHIVE(
ADMIN
),
Expand Down Expand Up @@ -1568,6 +1580,12 @@ public enum UserRight {
),
EXTERNAL_VISITS(
REST_EXTERNAL_VISITS_USER
),
DEV_MODE(
ADMIN
),
FILTERED_GRID_BULK_ACTION(
ADMIN
);
//@formatter:on

Expand Down
15 changes: 14 additions & 1 deletion sormas-api/src/main/java/de/symeda/sormas/api/user/UserRole.java
Expand Up @@ -35,6 +35,7 @@
/**
* These are also used as user groups in the server realm
*/
@Deprecated
public enum UserRole
implements
StatisticsGroupingKey {
Expand Down Expand Up @@ -209,7 +210,7 @@ public enum UserRole
POE_NATIONAL_USER(false, false, false, true, JurisdictionLevel.NATION, Collections.emptyList(), Collections.emptyList()),
IMPORT_USER(false, false, false, false, JurisdictionLevel.NONE, Collections.emptyList(), Collections.emptyList()),
REST_EXTERNAL_VISITS_USER(false, false, false, false, JurisdictionLevel.NATION, Collections.emptyList(), Collections.emptyList()),
REST_USER(false, false, false, false, JurisdictionLevel.NONE, Collections.emptyList(), Collections.emptyList()),
REST_USER(false, false, false, false, JurisdictionLevel.NATION, Collections.emptyList(), Collections.emptyList()),
SORMAS_TO_SORMAS_CLIENT(false, false, false, false, JurisdictionLevel.NATION, Collections.emptyList(), Collections.emptyList()),
BAG_USER(false, false, false, false, JurisdictionLevel.NONE, Collections.emptyList(), Collections.emptyList());

Expand Down Expand Up @@ -282,14 +283,17 @@ public String toShortString() {
return I18nProperties.getEnumCaptionShort(this);
}

@Deprecated
public boolean isSupervisor() {
return supervisor;
}

@Deprecated
public boolean hasAssociatedOfficer() {
return hasAssociatedOfficer;
}

@Deprecated
public boolean isPortHealthUser() {
return portHealthUser;
}
Expand Down Expand Up @@ -427,6 +431,7 @@ public static JurisdictionLevel getJurisdictionLevel(Collection<UserRole> roles)
return laboratoryJurisdictionPresent ? JurisdictionLevel.LABORATORY : JurisdictionLevel.NONE;
}

@Deprecated
public static boolean isSupervisor(Collection<UserRole> roles) {

for (UserRole role : roles) {
Expand All @@ -437,6 +442,8 @@ public static boolean isSupervisor(Collection<UserRole> roles) {
return false;
}

//TODO: #2804
@Deprecated
public static boolean hasAssociatedOfficer(Collection<UserRole> roles) {

for (UserRole role : roles) {
Expand All @@ -447,6 +454,8 @@ public static boolean hasAssociatedOfficer(Collection<UserRole> roles) {
return false;
}

//TODO: #2804
@Deprecated
public static boolean hasOptionalHealthFacility(Collection<UserRole> roles) {

for (UserRole role : roles) {
Expand All @@ -457,6 +466,8 @@ public static boolean hasOptionalHealthFacility(Collection<UserRole> roles) {
return false;
}

@Deprecated
//TODO: #2804
public static boolean isPortHealthUser(Collection<UserRole> roles) {

for (UserRole role : roles) {
Expand All @@ -467,6 +478,8 @@ public static boolean isPortHealthUser(Collection<UserRole> roles) {
return false;
}

//TODO: #2804
@Deprecated
public static boolean isLabUser(Collection<UserRole> roles) {
return roles.contains(UserRole.LAB_USER) || roles.contains(UserRole.EXTERNAL_LAB_USER);
}
Expand Down
2 changes: 1 addition & 1 deletion sormas-api/src/main/resources/captions.properties
Expand Up @@ -328,7 +328,7 @@ caseFilterPortHealthWithoutFacility=Only port health cases without a facility
caseFilterCasesWithCaseManagementData=Only cases with case management data
caseFilterWithDifferentRegion=Show duplicates with differing regions
caseFilterExcludeSharedCases=Exclude cases shared from other jurisdictions
caseFilterWithoutResponsibleOfficer=Only cases without responsible officer
caseFilterWithoutResponsibleUser=Only cases without responsible user
caseFilterWithExtendedQuarantine=Only cases with extended quarantine
caseFilterWithReducedQuarantine=Only cases with reduced quarantine
caseFilterOnlyQuarantineHelpNeeded=Help needed in quarantine
Expand Down
2 changes: 1 addition & 1 deletion sormas-api/src/main/resources/descriptions.properties
Expand Up @@ -67,7 +67,7 @@ descCaseFilterWithoutGeo = Only list cases that don't have address or report geo
descCaseFilterPortHealthWithoutFacility = Only list cases that origin from a point of entry and have not yet been referred to a facility
descCaseFilterCasesWithCaseManagementData = Only list cases that have at least one prescription, treatment or clinical visit
descCaseFilterExcludeSharedCases = Exclude all cases that do not originally belong to your jurisdiction, but have been shared with you by other users
descCaseFilterWithoutResponsibleOfficer = Only list cases that don't have responsible surveillance officer
descCaseFilterWithoutResponsibleUser = Only list cases that don't have responsible surveillance user
descCaseFilterWithExtendedQuarantine = Only list cases whose quarantine period has been extended
descContactOnlyWithExtendedQuarantine = Only list contacts whose quarantine period has been extended
descCaseFilterWithReducedQuarantine = Only list cases whose quarantine period has been reduced
Expand Down
Binary file modified sormas-api/src/main/resources/doc/SORMAS_Data_Dictionary.xlsx
Binary file not shown.
Binary file modified sormas-api/src/main/resources/doc/SORMAS_User_Rights.xlsx
Binary file not shown.
3 changes: 3 additions & 0 deletions sormas-api/src/main/resources/enum.properties
Expand Up @@ -1272,6 +1272,7 @@ UserRight.CASE_INVESTIGATE = Edit case investigation status
UserRight.CASE_SEE_ARCHIVED = View archived cases
UserRight.CASE_TRANSFER = Transfer cases to another region/district/facility
UserRight.CASE_REFER_FROM_POE = Refer case from point of entry
UserRight.CASE_RESPONSIBLE = Can be responsible for a case
UserRight.CASE_VIEW = View existing cases
UserRight.CONTACT_ASSIGN = Assign contacts to officers
UserRight.CONTACT_CLASSIFY = Edit contact classification
Expand All @@ -1281,6 +1282,7 @@ UserRight.CONTACT_IMPORT = Import contacts
UserRight.CONTACT_DELETE = Delete contacts from the system
UserRight.CONTACT_EDIT = Edit existing contacts
UserRight.CONTACT_EXPORT = Export contacts from SORMAS
UserRight.CONTACT_RESPONSIBLE = Can be responsible for a contact
UserRight.CONTACT_SEE_ARCHIVED = View archived contacts
UserRight.CONTACT_VIEW = View existing contacts
UserRight.CONTACT_ARCHIVE = Archive cntacts
Expand All @@ -1291,6 +1293,7 @@ UserRight.EVENT_ARCHIVE = Archive events
UserRight.EVENT_CREATE = Create new events
UserRight.EVENT_EDIT = Edit existing events
UserRight.EVENT_EXPORT = Export events from SORMAS
UserRight.EVENT_RESPONSIBLE = Can be responsible for an event
UserRight.EVENT_SEE_ARCHIVED = View archived events
UserRight.EVENT_VIEW = View existing events
UserRight.EVENTPARTICIPANT_CREATE = Create new event participants
Expand Down
Expand Up @@ -44,21 +44,13 @@ public void testUserRolesCombinationValidity() {
UserRole.POE_NATIONAL_USER,
UserRole.REST_EXTERNAL_VISITS_USER);

assertValidRolesCombination(
UserRole.NATIONAL_USER,
UserRole.LAB_USER);
assertValidRolesCombination(UserRole.NATIONAL_USER, UserRole.LAB_USER);

assertValidRolesCombination(
UserRole.ADMIN,
UserRole.LAB_USER);
assertValidRolesCombination(UserRole.ADMIN, UserRole.LAB_USER);

assertInvalidRolesCombination(
UserRole.LAB_USER,
UserRole.EXTERNAL_LAB_USER);
assertInvalidRolesCombination(UserRole.LAB_USER, UserRole.EXTERNAL_LAB_USER);

assertInvalidRolesCombination(
UserRole.NATIONAL_USER,
UserRole.EXTERNAL_LAB_USER);
assertInvalidRolesCombination(UserRole.NATIONAL_USER, UserRole.EXTERNAL_LAB_USER);

assertValidRolesCombination(
UserRole.SURVEILLANCE_SUPERVISOR,
Expand All @@ -68,12 +60,8 @@ public void testUserRolesCombinationValidity() {
UserRole.STATE_OBSERVER,
UserRole.POE_SUPERVISOR);

assertValidRolesCombination(
UserRole.SURVEILLANCE_OFFICER,
UserRole.CASE_OFFICER,
UserRole.CONTACT_OFFICER,
UserRole.DISTRICT_OBSERVER);

assertValidRolesCombination(UserRole.SURVEILLANCE_OFFICER, UserRole.CASE_OFFICER, UserRole.CONTACT_OFFICER, UserRole.DISTRICT_OBSERVER);

assertValidRolesCombination(UserRole.HOSPITAL_INFORMANT);

assertValidRolesCombination(UserRole.COMMUNITY_INFORMANT, UserRole.IMPORT_USER);
Expand All @@ -84,18 +72,17 @@ public void testUserRolesCombinationValidity() {
}

@Test
public void testUserRolesJurisdiction(){
public void testUserRolesJurisdiction() {

assertJurisdictionForRoles(JurisdictionLevel.NONE, UserRole.ADMIN, UserRole.REST_USER);
assertJurisdictionForRoles(JurisdictionLevel.NONE, UserRole.ADMIN);
assertJurisdictionForRoles(JurisdictionLevel.NATION, UserRole.ADMIN, UserRole.REST_USER, UserRole.NATIONAL_CLINICIAN);
assertJurisdictionForRoles(JurisdictionLevel.DISTRICT, UserRole.ADMIN, UserRole.REST_USER, UserRole.DISTRICT_OBSERVER);
assertJurisdictionForRoles(JurisdictionLevel.NATION, UserRole.NATIONAL_USER, UserRole.LAB_USER);
assertJurisdictionForRoles(JurisdictionLevel.DISTRICT, UserRole.ADMIN, UserRole.DISTRICT_OBSERVER);
assertJurisdictionForRoles(JurisdictionLevel.NATION, UserRole.NATIONAL_USER, UserRole.LAB_USER, UserRole.REST_USER, UserRole.ADMIN);
assertJurisdictionForRoles(JurisdictionLevel.REGION, UserRole.CASE_SUPERVISOR);
assertJurisdictionForRoles(JurisdictionLevel.LABORATORY, UserRole.LAB_USER);
assertJurisdictionForRoles(JurisdictionLevel.LABORATORY, UserRole.ADMIN, UserRole.LAB_USER);
}


private void assertJurisdictionForRoles(final JurisdictionLevel jurisdictionLevel, final UserRole... userRoles) {
Assert.assertEquals(jurisdictionLevel, UserRole.getJurisdictionLevel(Arrays.asList(userRoles)));
}
Expand Down
10 changes: 10 additions & 0 deletions sormas-backend/pom.xml
Expand Up @@ -267,5 +267,15 @@

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Expand Up @@ -38,7 +38,7 @@
import de.symeda.sormas.api.event.EventActionExportDto;
import de.symeda.sormas.api.event.EventActionIndexDto;
import de.symeda.sormas.api.event.EventCriteria;
import de.symeda.sormas.api.user.UserRole;
import de.symeda.sormas.api.user.JurisdictionLevel;
import de.symeda.sormas.api.utils.SortProperty;
import de.symeda.sormas.backend.action.transformers.EventActionIndexDtoReasultTransformer;
import de.symeda.sormas.backend.common.AdoServiceWithUserFilter;
Expand Down Expand Up @@ -104,7 +104,8 @@ public Predicate createUserFilter(CriteriaBuilder cb, CriteriaQuery cq, From<?,

// National users can access all actions in the system
User currentUser = getCurrentUser();
if (currentUser.hasAnyUserRole(UserRole.NATIONAL_USER, UserRole.NATIONAL_CLINICIAN, UserRole.NATIONAL_OBSERVER, UserRole.REST_USER)) {
final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
if (jurisdictionLevel == JurisdictionLevel.NATION || jurisdictionLevel == JurisdictionLevel.NONE) {
return null;
}

Expand Down

0 comments on commit 80d8208

Please sign in to comment.