Search in sources :

Example 1 with WorkspaceUserGroupPermission

use of fi.otavanopisto.muikku.rest.model.WorkspaceUserGroupPermission in project muikku by otavanopisto.

the class PermissionRESTService method setWorkspaceUserGroupPermission.

@PUT
@Path("/workspaceUserGroupPermissions")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response setWorkspaceUserGroupPermission(WorkspaceUserGroupPermission payload) {
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(payload.getUserGroupId());
    Permission permission = permissionDAO.findById(payload.getPermissionId());
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(payload.getWorkspaceId());
    if (!sessionController.hasPermission(MuikkuPermissions.WORKSPACE_MANAGEWORKSPACESETTINGS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if ((userGroupEntity == null) || (permission == null)) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    try {
        if (payload.getPermitted())
            permissionController.addWorkspaceGroupPermission(workspaceEntity, userGroupEntity, permission);
        else {
            WorkspaceGroupPermission workspaceGroupPermission = permissionController.findWorkspaceGroupPermission(workspaceEntity, userGroupEntity, permission);
            if (workspaceGroupPermission != null)
                permissionController.removeWorkspaceGroupPermission(workspaceGroupPermission);
            else
                return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.noContent().build();
    } catch (ConstraintViolationException violationException) {
        return getConstraintViolations(violationException);
    }
}
Also used : WorkspaceGroupPermission(fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) WorkspaceGroupPermission(fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission) WorkspaceUserGroupPermission(fi.otavanopisto.muikku.rest.model.WorkspaceUserGroupPermission) ConstraintViolationException(javax.validation.ConstraintViolationException) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Aggregations

Permission (fi.otavanopisto.muikku.model.security.Permission)1 WorkspaceGroupPermission (fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission)1 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceUserGroupPermission (fi.otavanopisto.muikku.rest.model.WorkspaceUserGroupPermission)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1