Search in sources :

Example 6 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project OpenOLAT by OpenOLAT.

the class MergedCourseContainer method init.

protected void init(PersistingCourseImpl persistingCourse) {
    super.init();
    RepositoryEntry courseRe = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    courseReadOnly = !overrideReadOnly && (courseRe.getRepositoryEntryStatus().isClosed() || courseRe.getRepositoryEntryStatus().isUnpublished());
    if (courseReadOnly) {
        setLocalSecurityCallback(new ReadOnlyCallback());
    }
    if (identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
        VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
        if (courseReadOnly) {
            courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
        }
        addContainersChildren(courseContainer, true);
    } else {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance().isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
        if (reSecurity.isEntryAdmin()) {
            VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
            if (courseReadOnly) {
                courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            addContainersChildren(courseContainer, true);
        }
    }
    initSharedFolder(persistingCourse);
    // add all course building blocks of type BC to a virtual folder
    MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
    if (identityEnv == null) {
        CourseNode rootNode = persistingCourse.getRunStructure().getRootNode();
        addFoldersForAdmin(persistingCourse, nodesContainer, rootNode);
    } else {
        TreeEvaluation treeEval = new TreeEvaluation();
        GenericTreeModel treeModel = new GenericTreeModel();
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, persistingCourse.getCourseEnvironment());
        CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
        NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        TreeNode treeRoot = rootNodeEval.getTreeNode();
        treeModel.setRootNode(treeRoot);
        addFolders(persistingCourse, nodesContainer, treeRoot);
    }
    if (nodesContainer.getItems().size() > 0) {
        addContainer(nodesContainer);
    }
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 7 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project openolat by klemens.

the class FeedMediaDispatcher method hasAccess.

/**
 * Verifies the access of an identity to a course node.
 *
 * @param identity
 * @param token
 * @param course
 * @param node
 * @return True if the identity has access to the node in the given course.
 *         False otherwise.
 */
private boolean hasAccess(Identity identity, String token, ICourse course, CourseNode node) {
    boolean hasAccess = false;
    final RepositoryManager resMgr = RepositoryManager.getInstance();
    final RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(course, false);
    if (allowsGuestAccess(repoEntry)) {
        hasAccess = true;
    } else {
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(identity);
        Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
        ienv.setRoles(roles);
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // Build an evaluation tree
        TreeEvaluation treeEval = new TreeEvaluation();
        NodeEvaluation nodeEval = node.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        if (nodeEval.isVisible() && validAuthentication(identity, token)) {
            hasAccess = true;
        }
    }
    return hasAccess;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 8 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project openolat by klemens.

the class CourseIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry bcContextEntry = businessControl.popLauncherContextEntry();
    if (bcContextEntry == null) {
        // not a course node of course we have access to the course metadata
        return true;
    }
    if (isLogDebugEnabled())
        logDebug("Start identity=" + identity + "  roles=" + roles);
    Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
    if (isLogDebugEnabled())
        logDebug("repositoryEntry=" + repositoryEntry);
    if (roles.isGuestOnly()) {
        if (repositoryEntry.getAccess() != RepositoryEntry.ACC_USERS_GUESTS) {
            return false;
        }
    }
    Long nodeId = bcContextEntry.getOLATResourceable().getResourceableId();
    if (isLogDebugEnabled())
        logDebug("nodeId=" + nodeId);
    ICourse course = CourseFactory.loadCourse(repositoryEntry);
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(identity);
    ienv.setRoles(roles);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    if (isLogDebugEnabled())
        logDebug("userCourseEnv=" + userCourseEnv + "ienv=" + ienv);
    CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
    String nodeIdS = nodeId.toString();
    CourseNode courseNode = course.getRunStructure().getNode(nodeIdS);
    if (isLogDebugEnabled())
        logDebug("courseNode=" + courseNode);
    TreeEvaluation treeEval = new TreeEvaluation();
    NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
    if (isLogDebugEnabled())
        logDebug("rootNodeEval=" + rootNodeEval);
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        // TreeNode no longer visible
        return false;
    }
    // go further
    NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
    if (isLogDebugEnabled())
        logDebug("nodeEval=" + nodeEval);
    if (nodeEval.getCourseNode() != courseNode)
        throw new AssertException("error in structure");
    if (!nodeEval.isVisible())
        throw new AssertException("node eval not visible!!");
    if (isLogDebugEnabled())
        logDebug("call mayAccessWholeTreeUp...");
    boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
    if (isLogDebugEnabled())
        logDebug("call mayAccessWholeTreeUp=" + mayAccessWholeTreeUp);
    if (mayAccessWholeTreeUp) {
        CourseNodeIndexer courseNodeIndexer = getCourseNodeIndexer(courseNode);
        bcContextEntry.setTransientState(new CourseNodeEntry(courseNode));
        return courseNodeIndexer.checkAccess(bcContextEntry, businessControl, identity, roles) && super.checkAccess(bcContextEntry, businessControl, identity, roles);
    } else {
        return false;
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) ContextEntry(org.olat.core.id.context.ContextEntry) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) CourseNodeIndexer(org.olat.search.service.indexer.repository.course.CourseNodeIndexer) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) CourseNodeEntry(org.olat.search.service.indexer.repository.course.CourseNodeEntry) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 9 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project openolat by klemens.

the class MergedCourseContainer method addFolders.

private void addFolders(PersistingCourseImpl course, MergeSource nodesContainer, TreeNode courseNode) {
    if (courseNode == null)
        return;
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        TreeNode child = (TreeNode) courseNode.getChildAt(i);
        NodeEvaluation nodeEval;
        if (child.getUserObject() instanceof NodeEvaluation) {
            nodeEval = (NodeEvaluation) child.getUserObject();
        } else {
            continue;
        }
        if (nodeEval != null && nodeEval.getCourseNode() != null) {
            CourseNode courseNodeChild = nodeEval.getCourseNode();
            String folderName = RequestUtil.normalizeFilename(courseNodeChild.getShortTitle());
            if (courseNodeChild instanceof BCCourseNode) {
                final BCCourseNode bcNode = (BCCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                VFSContainer rootFolder = getBCContainer(course, bcNode, nodeEval, false);
                boolean canDownload = nodeEval.isCapabilityAccessible("download");
                if (canDownload && rootFolder != null) {
                    if (courseReadOnly) {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    } else if (nodeEval.isCapabilityAccessible("upload")) {
                    // inherit the security callback from the course as for author
                    } else {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    folderName = getFolderName(nodesContainer, bcNode, folderName);
                    // Create a container for this node content and wrap it with a merge source which is attached to tree
                    VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                    MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                    courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                    nodesContainer.addContainer(courseNodeContainer);
                    // Do recursion for all children
                    addFolders(course, courseNodeContainer, child);
                } else {
                    // For non-folder course nodes, add merge source (no files to show) ...
                    MergeSource courseNodeContainer = new MergeSource(null, folderName);
                    // , then do recursion for all children ...
                    addFolders(course, courseNodeContainer, child);
                    // ... but only add this container if it contains any children with at least one BC course node
                    if (courseNodeContainer.getItems().size() > 0) {
                        nodesContainer.addContainer(courseNodeContainer);
                    }
                }
            } else if (courseNodeChild instanceof PFCourseNode) {
                final PFCourseNode pfNode = (PFCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
                folderName = getFolderName(nodesContainer, pfNode, folderName);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
                VFSContainer rootFolder = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, identityEnv.getIdentity(), courseReadOnly);
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                addFolders(course, courseNodeContainer, child);
                nodesContainer.addContainer(courseNodeContainer);
            } else {
                // For non-folder course nodes, add merge source (no files to show) ...
                MergeSource courseNodeContainer = new MergeSource(null, folderName);
                // , then do recursion for all children ...
                addFolders(course, courseNodeContainer, child);
                // ... but only add this container if it contains any children with at least one BC course node
                if (courseNodeContainer.getItems().size() > 0) {
                    nodesContainer.addContainer(courseNodeContainer);
                }
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) TreeNode(org.olat.core.gui.components.tree.TreeNode) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 10 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project openolat by klemens.

the class MergedCourseContainer method init.

protected void init(PersistingCourseImpl persistingCourse) {
    super.init();
    RepositoryEntry courseRe = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    courseReadOnly = !overrideReadOnly && (courseRe.getRepositoryEntryStatus().isClosed() || courseRe.getRepositoryEntryStatus().isUnpublished());
    if (courseReadOnly) {
        setLocalSecurityCallback(new ReadOnlyCallback());
    }
    if (identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
        VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
        if (courseReadOnly) {
            courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
        }
        addContainersChildren(courseContainer, true);
    } else {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance().isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
        if (reSecurity.isEntryAdmin()) {
            VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
            if (courseReadOnly) {
                courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            addContainersChildren(courseContainer, true);
        }
    }
    initSharedFolder(persistingCourse);
    // add all course building blocks of type BC to a virtual folder
    MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
    if (identityEnv == null) {
        CourseNode rootNode = persistingCourse.getRunStructure().getRootNode();
        addFoldersForAdmin(persistingCourse, nodesContainer, rootNode);
    } else {
        TreeEvaluation treeEval = new TreeEvaluation();
        GenericTreeModel treeModel = new GenericTreeModel();
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, persistingCourse.getCourseEnvironment());
        CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
        NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        TreeNode treeRoot = rootNodeEval.getTreeNode();
        treeModel.setRootNode(treeRoot);
        addFolders(persistingCourse, nodesContainer, treeRoot);
    }
    if (nodesContainer.getItems().size() > 0) {
        addContainer(nodesContainer);
    }
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Aggregations

NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)24 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)16 CourseNode (org.olat.course.nodes.CourseNode)14 TreeNode (org.olat.core.gui.components.tree.TreeNode)12 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 RepositoryEntry (org.olat.repository.RepositoryEntry)10 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)8 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Controller (org.olat.core.gui.control.Controller)6 ControllerEventListener (org.olat.core.gui.control.ControllerEventListener)6 WindowControl (org.olat.core.gui.control.WindowControl)6 ContextEntry (org.olat.core.id.context.ContextEntry)6 AssertException (org.olat.core.logging.AssertException)6 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)6 STCourseNode (org.olat.course.nodes.STCourseNode)6 TitledWrapperController (org.olat.core.gui.control.generic.title.TitledWrapperController)4 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 OLATResourceable (org.olat.core.id.OLATResourceable)4