Search in sources :

Example 1 with VisibleTreeFilter

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

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 2 with VisibleTreeFilter

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

the class CourseTemplateSearchController method loadCourseModel.

private void loadCourseModel(CourseNode courseNode, UserCourseEnvironment uce, List<CourseTemplateRow> rows, Set<CurrentBinder> currentSet) {
    if (courseNode instanceof PortfolioCourseNode) {
        PortfolioCourseNode pNode = (PortfolioCourseNode) courseNode;
        NodeEvaluation ne = pNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
        if (NavigationHandler.mayAccessWholeTreeUp(ne)) {
            RepositoryEntry refEntry = pNode.getReferencedRepositoryEntry();
            if ("BinderTemplate".equals(refEntry.getOlatResource().getResourceableTypeName())) {
                RepositoryEntry courseEntry = uce.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                CurrentBinder binderKey = new CurrentBinder(courseEntry.getKey(), pNode.getIdent());
                if (!currentSet.contains(binderKey)) {
                    rows.add(new CourseTemplateRow(courseEntry, pNode, refEntry));
                }
            }
        }
    }
    for (int i = courseNode.getChildCount(); i-- > 0; ) {
        loadCourseModel((CourseNode) courseNode.getChildAt(i), uce, rows, currentSet);
    }
}
Also used : CourseTemplateRow(org.olat.modules.portfolio.ui.model.CourseTemplateRow) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryEntry(org.olat.repository.RepositoryEntry) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 3 with VisibleTreeFilter

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

the class UserFoldersTest method myFolders.

/**
 * Test retrieve the folder which the user subscribe in a course.
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void myFolders() throws IOException, URISyntaxException {
    final Identity id = JunitTestHelper.createAndPersistIdentityAsUser("my-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // load my forums
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id.getName(), "A6B7C8"));
    // subscribed to nothing
    URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("folders").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    FolderVOes folders = conn.parse(body, FolderVOes.class);
    Assert.assertNotNull(folders);
    Assert.assertNotNull(folders.getFolders());
    Assert.assertEquals(0, folders.getFolders().length);
    // subscribe to the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id, new Roles(false, false, false, false, false, false, false));
    new CourseTreeVisitor(myCourse, ienv).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof BCCourseNode) {
                BCCourseNode folderNode = (BCCourseNode) node;
                String relPath = BCCourseNode.getFoldernodePathRelToFolderBase(myCourse.getCourseEnvironment(), folderNode);
                String businessPath = "[RepositoryEntry:" + myCourseRe.getKey() + "][CourseNode:" + folderNode.getIdent() + "]";
                SubscriptionContext folderSubContext = new SubscriptionContext("CourseModule", myCourse.getResourceableId(), folderNode.getIdent());
                PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
                NotificationsManager.getInstance().subscribe(id, folderSubContext, folderPdata);
            }
        }
    }, new VisibleTreeFilter());
    dbInstance.commitAndCloseSession();
    // retrieve my folders
    HttpGet method2 = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response2 = conn.execute(method2);
    assertEquals(200, response2.getStatusLine().getStatusCode());
    InputStream body2 = response2.getEntity().getContent();
    FolderVOes folders2 = conn.parse(body2, FolderVOes.class);
    Assert.assertNotNull(folders2);
    Assert.assertNotNull(folders2.getFolders());
    Assert.assertEquals(1, folders2.getFolders().length);
}
Also used : FolderVOes(org.olat.restapi.support.vo.FolderVOes) INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) InputStream(java.io.InputStream) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) HttpGet(org.apache.http.client.methods.HttpGet) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HttpResponse(org.apache.http.HttpResponse) Roles(org.olat.core.id.Roles) URI(java.net.URI) PublisherData(org.olat.core.commons.services.notifications.PublisherData) BCCourseNode(org.olat.course.nodes.BCCourseNode) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 4 with VisibleTreeFilter

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

the class ForumCourseNodeWebService method getForumContent.

@Path("{nodeId}/forum")
public ForumWebService getForumContent(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!CourseWebService.isCourseAccessible(course, false, request)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    CourseNode courseNode = course.getRunStructure().getNode(nodeId);
    if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    }
    UserRequest ureq = getUserRequest(request);
    CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
    if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
        FOCourseNode forumNode = (FOCourseNode) courseNode;
        Forum forum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
        return new ForumWebService(forum);
    } else {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 5 with VisibleTreeFilter

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

the class ForumCourseNodeWebService method getForums.

/**
 * Retrieves metadata of the published course node
 * @response.representation.200.qname {http://www.example.com}forumVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForums(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
    final ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    UserRequest ureq = getUserRequest(httpRequest);
    final Set<Long> subcribedForums = new HashSet<Long>();
    NotificationsManager man = NotificationsManager.getInstance();
    List<String> notiTypes = Collections.singletonList("Forum");
    List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
    for (Subscriber sub : subs) {
        Long forumKey = Long.parseLong(sub.getPublisher().getData());
        subcribedForums.add(forumKey);
    }
    final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
    new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                FOCourseNode forumNode = (FOCourseNode) node;
                ForumVO forum = createForumVO(course, forumNode, subcribedForums);
                forumVOs.add(forum);
            }
        }
    }, new VisibleTreeFilter());
    ForumVOes voes = new ForumVOes();
    voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
    voes.setTotalCount(forumVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)38 ICourse (org.olat.course.ICourse)28 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)26 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 Roles (org.olat.core.id.Roles)16 FOCourseNode (org.olat.course.nodes.FOCourseNode)16 Identity (org.olat.core.id.Identity)14 INode (org.olat.core.util.nodes.INode)14 Visitor (org.olat.core.util.tree.Visitor)14 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)12 UserRequest (org.olat.core.gui.UserRequest)12 BCCourseNode (org.olat.course.nodes.BCCourseNode)12 CourseNode (org.olat.course.nodes.CourseNode)12 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)12 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)12 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)12