Search in sources :

Example 81 with UserCourseEnvironment

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

the class ConditionTest method testIsInUserPropertyFunction.

@Test
public void testIsInUserPropertyFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "isInUserProperty(\"firstName\", \"firstcondition\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isInUserProperty(\"firstName\", \"stcondit\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isInUserProperty(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 82 with UserCourseEnvironment

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

the class ConditionTest method testUserPropertyStartswithFunction.

@Test
public void testUserPropertyStartswithFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "userPropertyStartswith(\"firstName\", \"firs\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 83 with UserCourseEnvironment

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

the class ReminderRuleEngineTest method assessmentData.

private String assessmentData(Identity tutor, Identity student, ScoreEvaluation scoreEval, RepositoryEntry re) {
    // create user course infos
    ICourse course = CourseFactory.loadCourse(re);
    List<CourseNode> assessableNodeList = AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), null);
    AssessableCourseNode testNode = null;
    for (CourseNode currentNode : assessableNodeList) {
        if (currentNode instanceof AssessableCourseNode) {
            if (currentNode.getType().equalsIgnoreCase("iqtest")) {
                testNode = (AssessableCourseNode) currentNode;
                break;
            }
        }
    }
    Assert.assertNotNull(testNode);
    Assert.assertTrue(testNode.hasScoreConfigured());
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(student);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    course.getCourseEnvironment().getAssessmentManager().saveScoreEvaluation(testNode, tutor, student, scoreEval, userCourseEnv, true, Role.coach);
    dbInstance.commit();
    return testNode.getIdent();
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 84 with UserCourseEnvironment

use of org.olat.course.run.userview.UserCourseEnvironment 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 85 with UserCourseEnvironment

use of org.olat.course.run.userview.UserCourseEnvironment 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

UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)158 ICourse (org.olat.course.ICourse)84 Identity (org.olat.core.id.Identity)60 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)58 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)54 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)52 CourseNode (org.olat.course.nodes.CourseNode)42 RepositoryEntry (org.olat.repository.RepositoryEntry)42 Test (org.junit.Test)28 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)24 ConditionInterpreter (org.olat.course.condition.interpreter.ConditionInterpreter)20 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)16 Roles (org.olat.core.id.Roles)14 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)14 ArrayList (java.util.ArrayList)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)12 OLATResource (org.olat.resource.OLATResource)12 Date (java.util.Date)10 AssessmentManager (org.olat.course.assessment.AssessmentManager)10