Search in sources :

Example 6 with RequestAction

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

the class DiscussionBackingBean method init.

@RequestAction
public String init() {
    if (!sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_ACCESSENVIRONMENTFORUM) || !sessionController.isActiveUser()) {
        return NavigationRules.ACCESS_DENIED;
    }
    List<EnvironmentForumArea> forumAreas = forumController.listEnvironmentForums();
    lockStickyPermission = sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_LOCK_OR_STICKIFY_MESSAGES);
    showFullNamePermission = sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_SHOW_FULL_NAMES);
    Map<Long, AreaPermission> areaPermissions = new HashMap<>();
    for (EnvironmentForumArea forumArea : forumAreas) {
        AreaPermission areaPermission = new AreaPermission(sessionController.hasPermission(ForumResourcePermissionCollection.FORUM_EDIT_ENVIRONMENT_MESSAGES, forumArea), sessionController.hasPermission(ForumResourcePermissionCollection.FORUM_DELETE_ENVIRONMENT_MESSAGES, forumArea));
        areaPermissions.put(forumArea.getId(), areaPermission);
    }
    try {
        this.areaPermissions = new ObjectMapper().writeValueAsString(areaPermissions);
    } catch (JsonProcessingException e) {
        return NavigationRules.INTERNAL_ERROR;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 7 with RequestAction

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

the class EvaluationMainViewBackingBean method init.

@RequestAction
public String init() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    if (userEntity == null) {
        return NavigationRules.ACCESS_DENIED;
    }
    WorkspaceEntity workspaceEntity = null;
    if (workspaceEntityId != null) {
        workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        if (workspaceEntity == null) {
            return NavigationRules.NOT_FOUND;
        }
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            return NavigationRules.NOT_FOUND;
        }
        setWorkspaceName(workspace.getName());
        if (!StringUtils.isEmpty(workspace.getNameExtension())) {
            setWorkspaceName(getWorkspaceName() + String.format(" (%s)", workspace.getNameExtension()));
        }
    }
    if (workspaceEntity == null) {
        if (!sessionController.hasEnvironmentPermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX)) {
            return NavigationRules.ACCESS_DENIED;
        }
    } else {
        if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX, workspaceEntity)) {
            return NavigationRules.ACCESS_DENIED;
        }
    }
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 8 with RequestAction

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

the class AbstractWorkspaceBackingBean method checkAccess.

@RequestAction
public String checkAccess() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    switch(workspaceEntity.getAccess()) {
        case ANYONE:
            break;
        case LOGGED_IN:
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            }
            break;
        case MEMBERS_ONLY:
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            }
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
            if (workspaceUserEntity == null) {
                if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_MEMBERS_ONLY_WORKSPACE, workspaceEntity)) {
                    return NavigationRules.ACCESS_DENIED;
                }
            }
            break;
    }
    return null;
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 9 with RequestAction

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

the class WorkspaceFrontPageManagementBackingBean 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.MANAGE_WORKSPACE_FRONTPAGE, workspaceEntity)) {
        return NavigationRules.ACCESS_DENIED;
    }
    rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    try {
        WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
        contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 10 with RequestAction

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

the class ProfileBackingBean method init.

@RequestAction
@LoggedIn
public String init() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
    List<UserAddress> userAddresses = userController.listUserAddresses(user);
    List<UserPhoneNumber> userPhoneNumbers = userController.listUserPhoneNumbers(user);
    displayName = user.getNickName() == null ? user.getDisplayName() : String.format("%s %s (%s)", user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
    studyStartDate = user.getStudyStartDate();
    studyTimeEnd = user.getStudyTimeEnd();
    studyTimeLeftStr = "";
    if (studyTimeEnd != null) {
        OffsetDateTime now = OffsetDateTime.now();
        Locale locale = sessionController.getLocale();
        if (now.isBefore(studyTimeEnd)) {
            long studyTimeLeftYears = now.until(studyTimeEnd, ChronoUnit.YEARS);
            now = now.plusYears(studyTimeLeftYears);
            if (studyTimeLeftYears > 0) {
                studyTimeLeftStr += studyTimeLeftYears + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.y");
            }
            long studyTimeLeftMonths = now.until(studyTimeEnd, ChronoUnit.MONTHS);
            now = now.plusMonths(studyTimeLeftMonths);
            if (studyTimeLeftMonths > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftMonths + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.m");
            }
            long studyTimeLeftDays = now.until(studyTimeEnd, ChronoUnit.DAYS);
            now = now.plusDays(studyTimeLeftDays);
            if (studyTimeLeftDays > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftDays + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.d");
            }
        }
    }
    addresses = new ArrayList<>();
    for (UserAddress userAddress : userAddresses) {
        addresses.add(String.format("%s %s %s %s", userAddress.getStreet(), userAddress.getPostalCode(), userAddress.getCity(), userAddress.getCountry()));
    }
    phoneNumbers = new ArrayList<>();
    for (UserPhoneNumber userPhoneNumber : userPhoneNumbers) {
        phoneNumbers.add(userPhoneNumber.getNumber());
    }
    SchoolDataIdentifier identifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
    emails = userEmailEntityController.getUserEmailAddresses(identifier);
    return null;
}
Also used : Locale(java.util.Locale) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) OffsetDateTime(java.time.OffsetDateTime) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) UserPhoneNumber(fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction) LoggedIn(fi.otavanopisto.security.LoggedIn)

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