use of fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission in project muikku by otavanopisto.
the class WorkspaceGroupPermissionDAO method listByWorkspaceEntity.
public List<WorkspaceGroupPermission> listByWorkspaceEntity(WorkspaceEntity workspaceEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceGroupPermission> criteria = criteriaBuilder.createQuery(WorkspaceGroupPermission.class);
Root<WorkspaceGroupPermission> root = criteria.from(WorkspaceGroupPermission.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceGroupPermission_.workspace), workspaceEntity));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission in project muikku by otavanopisto.
the class WorkspaceGroupPermissionDAO method create.
public WorkspaceGroupPermission create(WorkspaceEntity workspace, UserGroupEntity userGroup, Permission permission) {
WorkspaceGroupPermission curpermission = new WorkspaceGroupPermission();
curpermission.setWorkspace(workspace);
curpermission.setUserGroup(userGroup);
curpermission.setPermission(permission);
getEntityManager().persist(curpermission);
return curpermission;
}
use of fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission in project muikku by otavanopisto.
the class WorkspaceGroupPermissionDAO method findByGroupAndPermission.
public WorkspaceGroupPermission findByGroupAndPermission(WorkspaceEntity course, UserGroupEntity userGroup, Permission permission) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceGroupPermission> criteria = criteriaBuilder.createQuery(WorkspaceGroupPermission.class);
Root<WorkspaceGroupPermission> root = criteria.from(WorkspaceGroupPermission.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceGroupPermission_.workspace), course), criteriaBuilder.equal(root.get(WorkspaceGroupPermission_.userGroup), userGroup), criteriaBuilder.equal(root.get(WorkspaceGroupPermission_.permission), permission)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission 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