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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations