use of fi.otavanopisto.muikku.model.security.Permission in project muikku by otavanopisto.
the class PermissionDAO method create.
public Permission create(String name, String scope) {
Permission permission = new Permission();
permission.setName(name);
permission.setScope(scope);
getEntityManager().persist(permission);
return permission;
}
use of fi.otavanopisto.muikku.model.security.Permission 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;
}
use of fi.otavanopisto.muikku.model.security.Permission in project muikku by otavanopisto.
the class VopsLister method processCourse.
private VopsRESTModel.VopsEntry processCourse(Subject subject, int courseNumber) {
VopsRESTModel.VopsEntry transferCreditEntry = processTransferCredits(subject, courseNumber);
if (transferCreditEntry != null) {
return transferCreditEntry;
}
List<VopsWorkspace> workspaces = vopsController.listWorkspaceIdentifiersBySubjectIdentifierAndCourseNumber(subject.getSchoolDataSource(), subject.getIdentifier(), courseNumber);
List<WorkspaceAssessment> workspaceAssessments = new ArrayList<>();
if (curriculumIdentifier != null) {
workspaces.removeIf((VopsWorkspace workspace) -> !workspace.getCurriculumIdentifiers().contains(curriculumIdentifier));
}
if (!workspaces.isEmpty()) {
SchoolDataIdentifier educationSubtypeIdentifier = null;
boolean workspaceUserExists = false;
String name = "";
String description = "";
boolean canSignUp = false;
for (VopsWorkspace workspace : workspaces) {
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspace.getWorkspaceIdentifier());
WorkspaceUserEntity workspaceUser = workspaceUserEntityController.findWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
WorkspaceAssessment workspaceAssesment = studentAssessments.get(workspace.getWorkspaceIdentifier());
List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupsByUserIdentifier(studentIdentifier);
Permission permission = permissionController.findByName(MuikkuPermissions.WORKSPACE_SIGNUP);
for (UserGroupEntity userGroupEntity : userGroupEntities) {
if (permissionController.hasWorkspaceGroupPermission(workspaceEntity, userGroupEntity, permission)) {
canSignUp = true;
break;
}
}
if (workspaceAssesment != null) {
workspaceAssessments.add(workspaceAssesment);
}
if (workspaceUser != null) {
workspaceUserExists = true;
}
}
for (VopsWorkspace workspace : workspaces) {
name = workspace.getName();
if (name != null) {
break;
}
}
for (VopsWorkspace workspace : workspaces) {
description = workspace.getDescription();
if (description != null) {
break;
}
}
for (VopsWorkspace workspace : workspaces) {
educationSubtypeIdentifier = workspace.getEducationSubtypeIdentifier();
if (educationSubtypeIdentifier != null) {
break;
}
}
Mandatority mandatority = educationTypeMapping.getMandatority(educationSubtypeIdentifier);
CourseCompletionState state = CourseCompletionState.NOT_ENROLLED;
String grade = null;
if (workspaceUserExists) {
state = CourseCompletionState.ENROLLED;
}
for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
if (!Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
state = CourseCompletionState.FAILED;
break;
}
}
for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
if (Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
state = CourseCompletionState.ASSESSED;
numCourses++;
if (mandatority == Mandatority.MANDATORY) {
numMandatoryCourses++;
}
SchoolDataIdentifier gradingScaleIdentifier = workspaceAssessment.getGradingScaleIdentifier();
if (gradingScaleIdentifier == null) {
break;
}
SchoolDataIdentifier gradeIdentifier = workspaceAssessment.getGradeIdentifier();
if (gradeIdentifier == null) {
break;
}
GradingScaleItem gradingScaleItem = findGradingScaleItemCached(gradingScaleIdentifier, gradeIdentifier);
String gradeName = gradingScaleItem.getName();
if (!StringUtils.isBlank(gradeName)) {
if (gradeName.length() > 2)
grade = gradeName.substring(0, 2);
else
grade = gradeName;
}
break;
}
}
if (state == CourseCompletionState.NOT_ENROLLED && !canSignUp) {
return new VopsRESTModel.VopsPlaceholder();
}
StudiesViewCourseChoice courseChoice = studiesViewCourseChoiceController.find(new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()).toId(), courseNumber, studentIdentifierString);
if (state == CourseCompletionState.NOT_ENROLLED && courseChoice != null) {
state = CourseCompletionState.PLANNED;
}
return new VopsRESTModel.VopsItem(courseNumber, state, educationSubtypeIdentifier != null ? educationSubtypeIdentifier.toId() : null, mandatority, grade, workspaceUserExists, clean(name), clean(description));
}
return new VopsRESTModel.VopsPlaceholder();
}
use of fi.otavanopisto.muikku.model.security.Permission in project muikku by otavanopisto.
the class WorkspacePermissionsRoleManagementBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_MANAGEWORKSPACESETTINGS, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
/**
* View data
*/
permissions = permissionController.listPermissionsByScope(PermissionScope.WORKSPACE);
Collections.sort(permissions, new Comparator<Permission>() {
@Override
public int compare(Permission o1, Permission o2) {
return o1.getName().compareTo(o2.getName());
}
});
roleEntities = new ArrayList<RoleEntity>();
List<SystemRoleEntity> systemRoleEntities = roleController.listSystemRoleEntities();
List<EnvironmentRoleEntity> environmentRoleEnties = roleController.listEnvironmentRoleEntities();
List<WorkspaceRoleEntity> workspaceRoleEntities = roleController.listWorkspaceRoleEntities();
Collections.sort(environmentRoleEnties, new Comparator<EnvironmentRoleEntity>() {
@Override
public int compare(EnvironmentRoleEntity o1, EnvironmentRoleEntity o2) {
return o1.getArchetype().compareTo(o2.getArchetype());
}
});
Collections.sort(workspaceRoleEntities, new Comparator<WorkspaceRoleEntity>() {
@Override
public int compare(WorkspaceRoleEntity o1, WorkspaceRoleEntity o2) {
return o1.getArchetype().compareTo(o2.getArchetype());
}
});
for (SystemRoleEntity systemRoleEntity : systemRoleEntities) {
roleEntities.add(systemRoleEntity);
}
for (EnvironmentRoleEntity environmentRoleEntity : environmentRoleEnties) {
roleEntities.add(environmentRoleEntity);
}
for (WorkspaceRoleEntity workspaceRoleEntity : workspaceRoleEntities) {
roleEntities.add(workspaceRoleEntity);
}
return null;
}
use of fi.otavanopisto.muikku.model.security.Permission in project muikku by otavanopisto.
the class UserRolePermissionObserver method onEnvironmentRoleDiscoveredEvent.
// TODO: roolit workspacen luonnissa
public void onEnvironmentRoleDiscoveredEvent(@Observes(during = TransactionPhase.BEFORE_COMPLETION) SchoolDataEnvironmentRoleDiscoveredEvent event) {
for (MuikkuPermissionCollection collection : permissionCollections) {
List<String> permissions = collection.listPermissions();
for (String permissionName : permissions) {
Permission permission = permissionDAO.findByName(permissionName);
if (permission != null) {
try {
String permissionScope = collection.getPermissionScope(permissionName);
RoleEntity role = environmentRoleEntityDAO.findById(event.getDiscoveredEnvironmentRoleEntityId());
EnvironmentRoleArchetype[] archetypes = collection.getDefaultEnvironmentRoles(permissionName);
if (archetypes != null) {
for (EnvironmentRoleArchetype archetype : archetypes) {
if (archetype.equals(event.getArchetype())) {
applyPermission(permissionScope, role, permission);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Aggregations