Search in sources :

Example 56 with UserAuthorityGroup

use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.

the class UserRoleController method removeUserFromRole.

@DeleteMapping("/{id}/users/{userId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeUserFromRole(@PathVariable(value = "id") String pvId, @PathVariable("userId") String pvUserId, @CurrentUser User currentUser, HttpServletResponse response) throws WebMessageException {
    UserAuthorityGroup userAuthorityGroup = userService.getUserAuthorityGroup(pvId);
    if (userAuthorityGroup == null) {
        throw new WebMessageException(notFound("UserRole does not exist: " + pvId));
    }
    User user = userService.getUser(pvUserId);
    if (user == null) {
        throw new WebMessageException(notFound("User does not exist: " + pvId));
    }
    if (!aclService.canUpdate(currentUser, userAuthorityGroup)) {
        throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
    }
    if (user.getUserAuthorityGroups().contains(userAuthorityGroup)) {
        user.getUserAuthorityGroups().remove(userAuthorityGroup);
        userService.updateUser(user);
    }
}
Also used : CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)56 User (org.hisp.dhis.user.User)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 Test (org.junit.jupiter.api.Test)19 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 List (java.util.List)15 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)15 DataSet (org.hisp.dhis.dataset.DataSet)15 DataElement (org.hisp.dhis.dataelement.DataElement)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)11 HashSet (java.util.HashSet)7 Program (org.hisp.dhis.program.Program)7 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 Section (org.hisp.dhis.dataset.Section)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)4