Search in sources :

Example 1 with WorkspaceGroupPermission

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceGroupPermission(fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission)

Example 2 with WorkspaceGroupPermission

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;
}
Also used : WorkspaceGroupPermission(fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission)

Example 3 with WorkspaceGroupPermission

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));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceGroupPermission(fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission)

Example 4 with WorkspaceGroupPermission

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

WorkspaceGroupPermission (fi.otavanopisto.muikku.model.security.WorkspaceGroupPermission)4 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Permission (fi.otavanopisto.muikku.model.security.Permission)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