use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityDAO method findByIdentifierAndArchived.
public WorkspaceUserEntity findByIdentifierAndArchived(String identifier, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceUserEntity> criteria = criteriaBuilder.createQuery(WorkspaceUserEntity.class);
Root<WorkspaceUserEntity> root = criteria.from(WorkspaceUserEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceUserEntity_.identifier), identifier), criteriaBuilder.equal(root.get(WorkspaceUserEntity_.archived), archived)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityDAO method listByWorkspaceEntityAndRoleArchetypeAndArchived.
public List<WorkspaceUserEntity> listByWorkspaceEntityAndRoleArchetypeAndArchived(WorkspaceEntity workspaceEntity, WorkspaceRoleArchetype archetype, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceUserEntity> criteria = criteriaBuilder.createQuery(WorkspaceUserEntity.class);
Root<WorkspaceUserEntity> root = criteria.from(WorkspaceUserEntity.class);
Join<WorkspaceUserEntity, WorkspaceRoleEntity> join = root.join(WorkspaceUserEntity_.workspaceUserRole);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceUserEntity_.archived), archived), criteriaBuilder.equal(root.get(WorkspaceUserEntity_.workspaceEntity), workspaceEntity), criteriaBuilder.equal(join.get(WorkspaceRoleEntity_.archetype), archetype)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityDAO method findByWorkspaceEntityAndUserSchoolDataIdentifier.
public WorkspaceUserEntity findByWorkspaceEntityAndUserSchoolDataIdentifier(WorkspaceEntity workspaceEntity, UserSchoolDataIdentifier userSchoolDataIdentifier) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceUserEntity> criteria = criteriaBuilder.createQuery(WorkspaceUserEntity.class);
Root<WorkspaceUserEntity> root = criteria.from(WorkspaceUserEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceUserEntity_.userSchoolDataIdentifier), userSchoolDataIdentifier), criteriaBuilder.equal(root.get(WorkspaceUserEntity_.workspaceEntity), workspaceEntity)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityDAO method listByUserSchoolDataIdentifierAndArchived.
public List<WorkspaceUserEntity> listByUserSchoolDataIdentifierAndArchived(UserSchoolDataIdentifier userSchoolDataIdentifier, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceUserEntity> criteria = criteriaBuilder.createQuery(WorkspaceUserEntity.class);
Root<WorkspaceUserEntity> root = criteria.from(WorkspaceUserEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceUserEntity_.archived), archived), criteriaBuilder.equal(root.get(WorkspaceUserEntity_.userSchoolDataIdentifier), userSchoolDataIdentifier)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class ForumPermissionResolver method hasPermission.
@Override
public boolean hasPermission(String permission, ContextReference contextReference, User user) {
ForumArea forumArea = getForumArea(contextReference);
Permission perm = permissionDAO.findByName(permission);
UserEntity userEntity = getUserEntity(user);
if (forumArea == null) {
return false;
}
RoleEntity userRole;
// TODO: typecasts
if (forumArea instanceof WorkspaceForumArea) {
WorkspaceForumArea workspaceForum = (WorkspaceForumArea) forumArea;
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceForum.getWorkspace());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity != null) {
userRole = workspaceUserEntity.getWorkspaceUserRole();
if (resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || userEntity.getId().equals(forumArea.getOwner()))
return true;
}
}
EnvironmentUser environmentUser = environmentUserDAO.findByUserAndArchived(userEntity, Boolean.FALSE);
userRole = environmentUser.getRole();
boolean isOwner = userEntity != null ? userEntity.getId().equals(forumArea.getOwner()) : false;
return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || isOwner;
}
Aggregations