Search in sources :

Example 16 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceMaterialUploadBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return "/error/not-found.jsf";
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return "/error/not-found.jsf";
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 17 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceMaterialsBackingBean 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 (!workspaceEntity.getPublished()) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_WORKSPACE_MATERIALS, workspaceEntity)) {
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            } else {
                return NavigationRules.ACCESS_DENIED;
            }
        }
    }
    rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    workspaceNameExtension = workspaceBackingBean.getWorkspaceNameExtension();
    try {
        contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, false);
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    maySignUp = resolveMaySignUp();
    canSignUp = sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_SIGNUP, workspaceEntity);
    workspaceVisitController.visit(workspaceEntity);
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 18 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceMaterialsReadingBackingBean 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 (!workspaceEntity.getPublished()) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_WORKSPACE_MATERIALS, workspaceEntity)) {
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            } else {
                return NavigationRules.ACCESS_DENIED;
            }
        }
    }
    rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    try {
        contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, false);
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 19 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspacePermissionsManagementBackingBean 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_MANAGE_PERMISSIONS, workspaceEntity)) {
        return NavigationRules.NOT_FOUND;
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    userGroupBeans = new ArrayList<WorkspacePermissionsManagementBackingBean.UserGroupBean>();
    permissions = new ArrayList<Permission>();
    // TODO: atm we only support the sign up permission
    Permission permission = permissionController.findByName(MuikkuPermissions.WORKSPACE_SIGNUP);
    permissions.add(permission);
    List<UserGroupEntity> userGroupEntities;
    String permissionGroupIds = pluginSettingsController.getPluginSetting("workspace", "permission-group-ids");
    if (permissionGroupIds == null) {
        userGroupEntities = userGroupEntityController.listUserGroupEntities();
    } else {
        userGroupEntities = new ArrayList<UserGroupEntity>();
        String[] idArray = permissionGroupIds.split(",");
        for (int i = 0; i < idArray.length; i++) {
            Long groupId = NumberUtils.createLong(idArray[i]);
            if (groupId != null) {
                UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(groupId);
                if (userGroupEntity == null) {
                    logger.warning(String.format("Missing group %d in plugin setting workspace.permission-group-ids", groupId));
                } else {
                    userGroupEntities.add(userGroupEntity);
                }
            } else {
                logger.warning(String.format("Malformatted plugin setting workspace.permission-group-ids %s", permissionGroupIds));
            }
        }
    }
    for (UserGroupEntity userGroupEntity : userGroupEntities) {
        UserGroup userGroup = userGroupController.findUserGroup(userGroupEntity);
        userGroupBeans.add(new UserGroupBean(userGroupEntity.getId(), userGroup.getName()));
    }
    Collections.sort(userGroupBeans, new Comparator<UserGroupBean>() {

        @Override
        public int compare(UserGroupBean o1, UserGroupBean o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return null;
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 20 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceDiscussionsBackingBean 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(ForumResourcePermissionCollection.FORUM_ACCESSWORKSPACEFORUMS, workspaceEntity)) {
        return NavigationRules.ACCESS_DENIED;
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    lockStickyPermission = sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_LOCK_OR_STICKIFY_WORKSPACE_MESSAGES, workspaceEntity);
    showFullNamePermission = sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_SHOW_FULL_NAMES);
    Map<Long, AreaPermission> areaPermissions = new HashMap<>();
    for (WorkspaceForumArea forumArea : forumController.listWorkspaceForumAreas(workspaceEntity)) {
        AreaPermission areaPermission = new AreaPermission(sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_EDIT_WORKSPACE_MESSAGES, workspaceEntity), sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETE_WORKSPACE_MESSAGES, workspaceEntity));
        areaPermissions.put(forumArea.getId(), areaPermission);
    }
    canCreateArea = sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_CREATEWORKSPACEFORUM, workspaceEntity);
    canUpdateArea = sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_UPDATEWORKSPACEFORUM, workspaceEntity);
    canDeleteArea = sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETEWORKSPACEFORUM, workspaceEntity);
    try {
        this.areaPermissions = new ObjectMapper().writeValueAsString(areaPermissions);
    } catch (JsonProcessingException e) {
        return NavigationRules.INTERNAL_ERROR;
    }
    return null;
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Aggregations

RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)27 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)19 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Permission (fi.otavanopisto.muikku.model.security.Permission)3 HashMap (java.util.HashMap)3 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)2 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)2 SystemRoleEntity (fi.otavanopisto.muikku.model.users.SystemRoleEntity)2 WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 OffsetDateTime (java.time.OffsetDateTime)2 Locale (java.util.Locale)2 AuthenticationProvider (fi.otavanopisto.muikku.auth.AuthenticationProvider)1 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)1 CacheFlushEvent (fi.otavanopisto.muikku.cache.CacheFlushEvent)1 AuthSource (fi.otavanopisto.muikku.model.security.AuthSource)1