Search in sources :

Example 16 with UserRole

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

the class CampaignFacadeEjb method deleteCampaign.

@Override
public void deleteCampaign(String campaignUuid) {
    User user = userService.getCurrentUser();
    if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.CAMPAIGN_DELETE)) {
        throw new UnsupportedOperationException(I18nProperties.getString(Strings.entityUser) + " " + user.getUuid() + " is not allowed to delete " + I18nProperties.getString(Strings.entityCampaigns).toLowerCase() + ".");
    }
    service.delete(service.getByUuid(campaignUuid));
}
Also used : User(de.symeda.sormas.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole)

Example 17 with UserRole

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

the class PathogenTestFacadeEjb method deletePathogenTest.

@Override
public void deletePathogenTest(String pathogenTestUuid) {
    User user = userService.getCurrentUser();
    if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.PATHOGEN_TEST_DELETE)) {
        throw new UnsupportedOperationException("User " + user.getUuid() + " is not allowed to delete pathogen " + "tests.");
    }
    PathogenTest pathogenTest = pathogenTestService.getByUuid(pathogenTestUuid);
    pathogenTestService.delete(pathogenTest);
    handleAssotiatedObjectChanges(pathogenTest, true);
}
Also used : User(de.symeda.sormas.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole)

Example 18 with UserRole

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

the class SampleFacadeEjb method deleteSample.

@Override
public void deleteSample(SampleReferenceDto sampleRef) {
    User user = userService.getCurrentUser();
    if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.SAMPLE_DELETE)) {
        throw new UnsupportedOperationException("User " + user.getUuid() + " is not allowed to delete samples.");
    }
    Sample sample = sampleService.getByReferenceDto(sampleRef);
    sampleService.delete(sample);
    handleAssotiatedObjectChanges(sample, true);
}
Also used : User(de.symeda.sormas.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole)

Example 19 with UserRole

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

the class SampleFacadeEjb method deleteAllSamples.

@Override
public void deleteAllSamples(List<String> sampleUuids) {
    User user = userService.getCurrentUser();
    if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.SAMPLE_DELETE)) {
        throw new UnsupportedOperationException("User " + user.getUuid() + " is not allowed to delete samples.");
    }
    long startTime = DateHelper.startTime();
    IterableHelper.executeBatched(sampleUuids, DELETED_BATCH_SIZE, batchedSampleUuids -> sampleService.deleteAll(batchedSampleUuids));
    logger.debug("deleteAllSamples(sampleUuids) finished. samplesCount = {}, {}ms", sampleUuids.size(), DateHelper.durationMillies(startTime));
}
Also used : User(de.symeda.sormas.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole)

Example 20 with UserRole

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

the class UserService method getLabUsersOfLab.

public List<User> getLabUsersOfLab(Facility facility) {
    if (facility == null || facility.getType() != FacilityType.LABORATORY) {
        throw new IllegalArgumentException("Facility needs to be a laboratory");
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(getElementClass());
    Root<User> from = cq.from(getElementClass());
    Join<User, UserRole> joinRoles = from.join(User.USER_ROLES, JoinType.LEFT);
    Predicate filter = cb.and(createDefaultFilter(cb, from), cb.equal(from.get(User.LABORATORY), facility), joinRoles.in(Arrays.asList(UserRole.LAB_USER, UserRole.EXTERNAL_LAB_USER)));
    cq.where(filter).distinct(true);
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserRole(de.symeda.sormas.api.user.UserRole) Predicate(javax.persistence.criteria.Predicate)

Aggregations

UserRole (de.symeda.sormas.api.user.UserRole)29 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Case (de.symeda.sormas.app.backend.caze.Case)5 User (de.symeda.sormas.backend.user.User)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 UserDto (de.symeda.sormas.api.user.UserDto)4 User (de.symeda.sormas.app.backend.user.User)4 Predicate (javax.persistence.criteria.Predicate)4 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)3 District (de.symeda.sormas.app.backend.region.District)3 Task (de.symeda.sormas.app.backend.task.Task)3 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)3 Set (java.util.Set)3 AuthProvider (de.symeda.sormas.api.AuthProvider)2 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)2 UserRight (de.symeda.sormas.api.user.UserRight)2 Community (de.symeda.sormas.app.backend.region.Community)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)2