Search in sources :

Example 11 with NodeEvaluation

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

the class CourseSite method createController.

@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
    if (entry == null) {
        return getAlternativeController(ureq, wControl, config);
    }
    MainLayoutController c;
    ICourse course = CourseFactory.loadCourse(entry);
    UserSession usess = ureq.getUserSession();
    // course-launch-state depending course-settings
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
    boolean isAllowedToLaunch = reSecurity.canLaunch();
    boolean hasAccess = false;
    if (isAllowedToLaunch) {
        // either check with securityCallback or use access-settings from course-nodes
        if (siteSecCallback != null) {
            hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
        } else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
            hasAccess = false;
        } else {
            // check within course: accessibility of course root node
            CourseNode rootNode = course.getRunStructure().getRootNode();
            UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
            NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
            boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
            hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
        }
    }
    // load course (admins always see content) or alternative controller if course is not launchable
    if (hasAccess || usess.getRoles().isOLATAdmin()) {
        rs.incrementLaunchCounter(entry);
        // build up the context path for linked course
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
        CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {

            @Override
            public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
                return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
            }
        }, false, true);
        // Configure run controller
        // a: don't show close link, is opened as site not tab
        runCtr.setCourseCloseEnabled(false);
        // b: don't show toolbar
        if (!showToolController) {
            runCtr.setToolControllerEnabled(false);
        }
        c = runCtr;
    } else {
        // access restricted (not in group / author) -> show controller
        // defined in olat_extensions (type autoCreator)
        c = getAlternativeController(ureq, wControl, config);
    }
    return c;
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) StateSite(org.olat.core.id.context.StateSite) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) RunMainController(org.olat.course.run.RunMainController) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RunMainController(org.olat.course.run.RunMainController) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) Controller(org.olat.core.gui.control.Controller) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) UserSession(org.olat.core.util.UserSession) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RepositoryManager(org.olat.repository.RepositoryManager) CourseNode(org.olat.course.nodes.CourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService)

Example 12 with NodeEvaluation

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

the class BCCourseNode method getSecurisedNodeFolderContainer.

public static OlatNamedContainerImpl getSecurisedNodeFolderContainer(BCCourseNode node, CourseEnvironment courseEnv, IdentityEnvironment ienv) {
    boolean isOlatAdmin = ienv.getRoles().isOLATAdmin();
    boolean isGuestOnly = ienv.getRoles().isGuestOnly();
    UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ienv, courseEnv);
    NodeEvaluation ne = node.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
    OlatNamedContainerImpl container = getNodeFolderContainer(node, courseEnv);
    VFSSecurityCallback secCallback = new FolderNodeCallback(container.getRelPath(), ne, isOlatAdmin, isGuestOnly, null);
    container.setLocalSecurityCallback(secCallback);
    return container;
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) FolderNodeCallback(org.olat.course.nodes.bc.FolderNodeCallback) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 13 with NodeEvaluation

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

the class NavigationHandler method evaluateJumpToTreeNode.

/**
 * to be called when the users clickes on a node when in the course
 *
 * @param ureq
 * @param wControl
 * @param treeModel
 * @param treeEvent
 * @param listeningController
 * @param nodecmd null or a subcmd which activates a node-specific view (e.g. opens a certain uri in a contentpackaging- buildingblock)
 * @return the NodeClickedRef
 * @return currentNodeController the current node controller that will be dispose before creating the new one
 */
public NodeClickedRef evaluateJumpToTreeNode(UserRequest ureq, WindowControl wControl, TreeModel treeModel, TreeEvent treeEvent, ControllerEventListener listeningController, String nodecmd, Controller currentNodeController) {
    NodeClickedRef ncr;
    String treeNodeId = treeEvent.getNodeId();
    TreeNode selTN = treeModel.getNodeById(treeNodeId);
    if (selTN == null) {
        selTN = treeModel.getRootNode();
    }
    if (!selTN.isAccessible()) {
        // event to match the new node
        if (selTN.getDelegate() != null) {
            selTN = selTN.getDelegate();
            treeNodeId = selTN.getIdent();
            treeEvent = new TreeEvent(MenuTree.COMMAND_TREENODE_CLICKED, treeNodeId);
        }
    }
    // check if appropriate for subtreemodelhandler
    Object userObject = selTN.getUserObject();
    if (!(userObject instanceof NodeEvaluation)) {
        // yes, appropriate
        NodeRunConstructionResult nrcr = null;
        CourseNode internCourseNode = null;
        GenericTreeModel subTreeModel;
        ControllerEventListener subtreemodelListener = null;
        if (selTN != null) {
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            CourseNode courseNode = prevEval.getCourseNode();
            if (externalTreeModels.containsKey(courseNode.getIdent())) {
                SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                subtreemodelListener = subTree.getTreeModelListener();
            }
        }
        if (subtreemodelListener == null) {
            // throw new AssertException("no handler for subtreemodelcall!");
            // reattach the subtreemodellistener
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            internCourseNode = prevEval.getCourseNode();
            final OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.parseLong(internCourseNode.getIdent()));
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
            nrcr = internCourseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, prevEval, nodecmd);
            // remember as instance variable for next click
            subtreemodelListener = nrcr.getSubTreeListener();
            subTreeModel = (GenericTreeModel) nrcr.getSubTreeModel();
            externalTreeModels.put(internCourseNode.getIdent(), new SubTree(nrcr.getRunController(), subTreeModel, subtreemodelListener));
        } else {
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            internCourseNode = prevEval.getCourseNode();
            SubTree subTree = externalTreeModels.get(internCourseNode.getIdent());
            subtreemodelListener = subTree.getTreeModelListener();
            if (currentNodeController instanceof TitledWrapperController) {
                currentNodeController = ((TitledWrapperController) currentNodeController).getContentController();
            }
            if (subtreemodelListener != currentNodeController) {
                if (subtreemodelListener instanceof CPRunController) {
                    nrcr = ((CPRunController) subtreemodelListener).createNodeRunConstructionResult(ureq, selTN.getIdent());
                } else {
                    nrcr = new NodeRunConstructionResult((Controller) subtreemodelListener);
                }
            }
            subTreeModel = subTree.getTreeModel();
        }
        if (log.isDebug()) {
            log.debug("delegating to handler: treeNodeId = " + treeNodeId);
        }
        // used in multiple nodes.
        if (!selTN.getUserObject().equals(userObject)) {
            selTN = subTreeModel.findNodeByUserObject(userObject);
        }
        treeEvent = new TreeEvent(treeEvent.getCommand(), treeEvent.getSubCommand(), selTN.getIdent());
        boolean dispatch = true;
        String selectedNodeId = null;
        if (userObject instanceof String) {
            String sObject = (String) userObject;
            if (MenuTree.COMMAND_TREENODE_CLICKED.equals(treeEvent.getCommand()) && treeEvent.getSubCommand() == null) {
                openCourseNodeIds.add(sObject);
                if (!openTreeNodeIds.contains(sObject)) {
                    openTreeNodeIds.add(sObject);
                }
                selectedNodeId = selTN.getIdent();
            } else if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand())) {
                openCourseNodeIds.add(sObject);
                if (!openTreeNodeIds.contains(sObject)) {
                    openTreeNodeIds.add(sObject);
                }
                selectedNodeId = selTN.getIdent();
                dispatch = false;
            } else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
                removeChildrenFromOpenNodes(selTN);
                openCourseNodeIds.remove(sObject);
                openTreeNodeIds.remove(sObject);
                openCourseNodeIds.remove(selTN.getIdent());
                openTreeNodeIds.remove(selTN.getIdent());
                dispatch = false;
            }
        }
        if (dispatch) {
            // null as controller source since we are not a controller
            subtreemodelListener.dispatchEvent(ureq, null, treeEvent);
        // no node construction result indicates handled
        }
        ncr = new NodeClickedRef(treeModel, true, selectedNodeId, openTreeNodeIds, internCourseNode, nrcr, true);
    } else {
        // normal dispatching to a coursenode.
        // get the courseNode that was called
        NodeEvaluation prevEval = (NodeEvaluation) selTN.getUserObject();
        if (!prevEval.isVisible())
            throw new AssertException("clicked on a node which is not visible: treenode=" + selTN.getIdent() + ", " + selTN.getTitle());
        CourseNode calledCourseNode = prevEval.getCourseNode();
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(calledCourseNode));
        // might be used in both controllers with the same ID (e.g. the course folder)
        if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand()) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
            if (isInParentLine(calledCourseNode)) {
                if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
                    currentNodeController.dispose();
                }
            }
            ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
        } else {
            if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
                currentNodeController.dispose();
            }
            ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
        }
    }
    return ncr;
}
Also used : CPRunController(org.olat.course.nodes.cp.CPRunController) AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) WindowControl(org.olat.core.gui.control.WindowControl) EditorMainController(org.olat.course.editor.EditorMainController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) CPRunController(org.olat.course.nodes.cp.CPRunController) Controller(org.olat.core.gui.control.Controller) ContextEntry(org.olat.core.id.context.ContextEntry) TreeEvent(org.olat.core.gui.components.tree.TreeEvent) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 14 with NodeEvaluation

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

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 15 with NodeEvaluation

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

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)

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