use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class CaseBackendTest method testTaskReassignmentAfterChangedCaseCommunity.
@Test
public void testTaskReassignmentAfterChangedCaseCommunity() throws DaoException {
CaseDao caseDao = DatabaseHelper.getCaseDao();
Case caze = TestEntityCreator.createCase();
caze.setRegion(caze.getResponsibleRegion());
caze.setDistrict(caze.getResponsibleDistrict());
caze.setCommunity(caze.getResponsibleCommunity());
caseDao.saveAndSnapshot(caze);
User user = ConfigProvider.getUser();
user.setCommunity(caze.getCommunity());
UserRole userRole = UserRole.COMMUNITY_OFFICER;
Set<UserRole> userRoles = new HashSet<>();
userRoles.add(userRole);
user.setUserRoles(userRoles);
DatabaseHelper.getUserDao().saveAndSnapshot(user);
TaskDao taskDao = DatabaseHelper.getTaskDao();
Task task = TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, user);
caze = caseDao.queryUuidBasic(caze.getUuid());
assertEquals(TestHelper.USER_UUID, caze.getSurveillanceOfficer().getUuid());
assertEquals(caze.getResponsibleRegion().getUuid(), TestHelper.REGION_UUID);
assertEquals(caze.getResponsibleDistrict().getUuid(), TestHelper.DISTRICT_UUID);
assertEquals(caze.getResponsibleCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
assertEquals(caze.getRegion().getUuid(), TestHelper.REGION_UUID);
assertEquals(caze.getDistrict().getUuid(), TestHelper.DISTRICT_UUID);
assertEquals(caze.getCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
assertEquals(caze.getHealthFacility().getUuid(), TestHelper.FACILITY_UUID);
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
// ResponsibleDistrict and ResponsibleCommunity changed,
// but District and Community still in user's jurisdiction
District secondDistrict = DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID);
Community secondCommunity = DatabaseHelper.getCommunityDao().queryUuid(TestHelper.SECOND_COMMUNITY_UUID);
caze.setResponsibleDistrict(secondDistrict);
caze.setResponsibleCommunity(secondCommunity);
caze.setDistrict(secondDistrict);
caseDao.saveAndSnapshot(caze);
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
caze = caseDao.queryUuidBasic(caze.getUuid());
assertEquals(TestHelper.SECOND_USER_UUID, caze.getSurveillanceOfficer().getUuid());
// Case not in user's jurisdiction anymore
caze.setCommunity(null);
caseDao.saveAndSnapshot(caze);
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.SECOND_USER_UUID, task.getAssigneeUser().getUuid());
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class CaseBackendTest method testEditCasePermissionWhenFacilityDoesNotMatchAndCaseNotCreatedByUser.
@Test
public void testEditCasePermissionWhenFacilityDoesNotMatchAndCaseNotCreatedByUser() {
Case caze = TestEntityCreator.createCase();
caze.setHealthFacility(null);
UserRole userRole = UserRole.HOSPITAL_INFORMANT;
Set<UserRole> userRoles = new HashSet<>();
userRoles.add(userRole);
ConfigProvider.getUser().setUserRoles(userRoles);
ConfigProvider.getUser().setHealthFacility(DatabaseHelper.getFacilityDao().queryUuid(TestHelper.FACILITY_UUID));
ConfigProvider.getUser().setUuid("");
assertFalse(CaseEditAuthorization.isCaseEditAllowed(caze));
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class CaseBackendTest method testTaskReassignmentAfterChangedCaseFacility.
@Test
public void testTaskReassignmentAfterChangedCaseFacility() throws DaoException {
CaseDao caseDao = DatabaseHelper.getCaseDao();
Case caze = TestEntityCreator.createCase();
User user = ConfigProvider.getUser();
user.setHealthFacility(caze.getHealthFacility());
UserRole userRole = UserRole.HOSPITAL_INFORMANT;
Set<UserRole> userRoles = new HashSet<>();
userRoles.add(userRole);
user.setUserRoles(userRoles);
DatabaseHelper.getUserDao().saveAndSnapshot(user);
TaskDao taskDao = DatabaseHelper.getTaskDao();
Task task = TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, user);
caze = caseDao.queryUuidBasic(caze.getUuid());
assertEquals(TestHelper.USER_UUID, caze.getSurveillanceOfficer().getUuid());
assertEquals(caze.getResponsibleRegion().getUuid(), TestHelper.REGION_UUID);
assertEquals(caze.getResponsibleDistrict().getUuid(), TestHelper.DISTRICT_UUID);
assertEquals(caze.getResponsibleCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
assertEquals(caze.getHealthFacility().getUuid(), TestHelper.FACILITY_UUID);
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
// Case not in user's jurisdiction anymore
caze.setResponsibleDistrict(DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID));
caze.setCommunity(null);
caseDao.saveAndSnapshot(caze);
caze = caseDao.queryUuidBasic(caze.getUuid());
assertEquals(TestHelper.SECOND_USER_UUID, caze.getSurveillanceOfficer().getUuid());
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
caze.setHealthFacility(null);
caseDao.saveAndSnapshot(caze);
task = taskDao.queryUuid(task.getUuid());
assertEquals(TestHelper.SECOND_USER_UUID, task.getAssigneeUser().getUuid());
}
use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.
the class UserDao method getAllInJurisdiction.
public List<User> getAllInJurisdiction() {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.eq(AbstractDomainObject.SNAPSHOT, false);
User currentUser = ConfigProvider.getUser();
// create role filters for national and regional users
List<UserRole> nationalOrRegionalRoles = UserRole.getWithJurisdictionLevels(JurisdictionLevel.NATION, JurisdictionLevel.REGION);
for (int i = 0; i < nationalOrRegionalRoles.size(); i++) {
UserRole role = nationalOrRegionalRoles.get(i);
createRoleFilter(role, where);
}
where.or(nationalOrRegionalRoles.size());
// conjunction by default, jurisdiction filter should not be empty because of combining role and jurisdiction filters by OR
// if the current user is a national one than it should see all users
Where jurisdictionFilter = where.raw("1=1");
if (currentUser.getHealthFacility() != null) {
where.and(jurisdictionFilter, where.eq(User.HEALTH_FACILITY + "_id", currentUser.getHealthFacility()));
} else if (currentUser.getPointOfEntry() != null) {
where.and(jurisdictionFilter, where.eq(User.POINT_OF_ENTRY + "_id", currentUser.getPointOfEntry()));
} else if (currentUser.getCommunity() != null) {
where.and(jurisdictionFilter, where.eq(User.COMMUNITY + "_id", currentUser.getCommunity()));
} else if (currentUser.getDistrict() != null) {
where.and(jurisdictionFilter, where.eq(User.DISTRICT + "_id", currentUser.getDistrict()));
} else if (currentUser.getRegion() != null) {
where.and(jurisdictionFilter, where.eq(User.REGION + "_id", currentUser.getRegion()));
}
// combine role filters and jurisdiction filter with OR(=> roleFilter OR jurisdictionFilter)
where.or(2);
// combine snapshot filter with AND (=> snapshot AND (role OR jurisdiction))
where.and(2);
return builder.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform getAllInJurisdiction");
throw new RuntimeException(e);
}
}
Aggregations