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;
}
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));
}
Aggregations