Search in sources :

Example 1 with UserRoleConfigDto

use of de.symeda.sormas.api.user.UserRoleConfigDto in project SORMAS-Project by hzi-braunschweig.

the class UserRoleConfigFacadeEjb method toDto.

public static UserRoleConfigDto toDto(UserRoleConfig source) {
    if (source == null) {
        return null;
    }
    UserRoleConfigDto target = new UserRoleConfigDto();
    DtoHelper.fillDto(target, source);
    target.setUserRole(source.getUserRole());
    target.setUserRights(new HashSet<UserRight>(source.getUserRights()));
    return target;
}
Also used : UserRight(de.symeda.sormas.api.user.UserRight) UserRoleConfigDto(de.symeda.sormas.api.user.UserRoleConfigDto)

Example 2 with UserRoleConfigDto

use of de.symeda.sormas.api.user.UserRoleConfigDto in project SORMAS-Project by hzi-braunschweig.

the class UserRoleConfigFacadeEjbTest method testGetEffectiveUserRights.

@Test
public void testGetEffectiveUserRights() {
    // 1. no role configured -> use defaults
    Set<UserRight> supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR);
    assertThat(supervisorRights, is(UserRole.SURVEILLANCE_SUPERVISOR.getDefaultUserRights()));
    UserRoleConfigDto userRoleConfig = UserRoleConfigDto.build(UserRole.SURVEILLANCE_SUPERVISOR);
    userRoleConfig = getUserRoleConfigFacade().saveUserRoleConfig(userRoleConfig);
    // 2. role configured with no rights
    supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR);
    assertThat(supervisorRights, is(IsEmptyCollection.empty()));
    // 3. role configured with a few rights
    userRoleConfig.getUserRights().add(UserRight.CASE_CREATE);
    userRoleConfig.getUserRights().add(UserRight.CASE_EDIT);
    userRoleConfig = getUserRoleConfigFacade().saveUserRoleConfig(userRoleConfig);
    supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR);
    assertThat(supervisorRights, is(new HashSet<UserRight>(Arrays.asList(UserRight.CASE_CREATE, UserRight.CASE_EDIT))));
    // 4. combine configured and default rights
    Set<UserRight> mixedUserRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR, UserRole.NATIONAL_OBSERVER);
    Set<UserRight> expectedUserRights = new HashSet<UserRight>(Arrays.asList(UserRight.CASE_CREATE, UserRight.CASE_EDIT));
    expectedUserRights.addAll(UserRole.NATIONAL_OBSERVER.getDefaultUserRights());
    assertThat(mixedUserRights, is(expectedUserRights));
}
Also used : UserRight(de.symeda.sormas.api.user.UserRight) UserRoleConfigDto(de.symeda.sormas.api.user.UserRoleConfigDto) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Aggregations

UserRight (de.symeda.sormas.api.user.UserRight)2 UserRoleConfigDto (de.symeda.sormas.api.user.UserRoleConfigDto)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1