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