Search in sources :

Example 1 with ReadOnlyCallback

use of org.olat.core.util.vfs.callbacks.ReadOnlyCallback in project OpenOLAT by OpenOLAT.

the class CourseResourceFolderWebService method getFiles.

public Response getFiles(Long courseId, List<PathSegment> path, FolderType type, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
    if (!isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSContainer container = null;
    RepositoryEntry re = null;
    switch(type) {
        case COURSE_FOLDER:
            container = course.getCourseFolderContainer();
            break;
        case SHARED_FOLDER:
            {
                container = null;
                String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
                OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
                if (sharedResource != null) {
                    re = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(sharedResource.getKey());
                    container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
                    CourseConfig courseConfig = course.getCourseConfig();
                    if (courseConfig.isSharedFolderReadOnlyMount()) {
                        container.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                }
                break;
            }
    }
    if (container == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSLeaf leaf = null;
    for (PathSegment seg : path) {
        VFSItem item = container.resolve(seg.getPath());
        if (item instanceof VFSLeaf) {
            leaf = (VFSLeaf) item;
            break;
        } else if (item instanceof VFSContainer) {
            container = (VFSContainer) item;
        }
    }
    if (leaf != null) {
        Date lastModified = new Date(leaf.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            String mimeType = WebappHelper.getMimeType(leaf.getName());
            if (mimeType == null)
                mimeType = MediaType.APPLICATION_OCTET_STREAM;
            response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
        }
        return response.build();
    }
    List<VFSItem> items = container.getItems(new SystemItemFilter());
    int count = 0;
    LinkVO[] links = new LinkVO[items.size()];
    for (VFSItem item : items) {
        UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        UriBuilder repoUri = baseUriBuilder.path(CourseResourceFolderWebService.class).path("files");
        if (type.equals(FolderType.SHARED_FOLDER) && re != null) {
            repoUri = baseUriBuilder.replacePath("restapi").path(SharedFolderWebService.class).path(re.getKey().toString()).path("files");
        }
        for (PathSegment pathSegment : path) {
            repoUri.path(pathSegment.getPath());
        }
        String uri = repoUri.path(item.getName()).build(courseId).toString();
        links[count++] = new LinkVO("self", uri, item.getName());
    }
    return Response.ok(links).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) SharedFolderWebService(org.olat.restapi.repository.SharedFolderWebService) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) VFSItem(org.olat.core.util.vfs.VFSItem) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Response(javax.ws.rs.core.Response) LinkVO(org.olat.restapi.support.vo.LinkVO) UriBuilder(javax.ws.rs.core.UriBuilder) RepositoryService(org.olat.repository.RepositoryService)

Example 2 with ReadOnlyCallback

use of org.olat.core.util.vfs.callbacks.ReadOnlyCallback in project OpenOLAT by OpenOLAT.

the class UserInfoMainController method doOpenFolder.

private FolderRunController doOpenFolder(UserRequest ureq) {
    removeAsListenerAndDispose(folderRunController);
    String chosenUserFolderRelPath = FolderConfig.getUserHome(chosenIdentity.getName()) + "/public";
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(chosenUserFolderRelPath, null);
    OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(firstLastName, rootFolder);
    // decided in plenum to have read only view in the personal visiting card, even for admin
    VFSSecurityCallback secCallback = new ReadOnlyCallback();
    namedFolder.setLocalSecurityCallback(secCallback);
    OLATResourceable ores = OresHelper.createOLATResourceableType("userfolder");
    WindowControl bwControl = addToHistory(ureq, ores, null);
    folderRunController = new FolderRunController(namedFolder, false, true, false, ureq, bwControl);
    folderRunController.setResourceURL("[Identity:" + chosenIdentity.getKey() + "][userfolder:0]");
    listenTo(folderRunController);
    return folderRunController;
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) OLATResourceable(org.olat.core.id.OLATResourceable) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) WindowControl(org.olat.core.gui.control.WindowControl) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 3 with ReadOnlyCallback

use of org.olat.core.util.vfs.callbacks.ReadOnlyCallback in project OpenOLAT by OpenOLAT.

the class GroupfoldersWebDAVMergeSource method getGroupContainer.

private VFSContainer getGroupContainer(String name, BusinessGroup group, boolean isOwner) {
    String folderPath = collaborationManager.getFolderRelPath(group);
    // create container and set quota
    OlatRootFolderImpl localImpl = new OlatRootFolderImpl(folderPath, this);
    // already done in OlatRootFolderImpl localImpl.getBasefile().mkdirs(); // lazy initialize dirs
    String containerName = RequestUtil.normalizeFilename(name);
    NamedContainerImpl grpContainer = new GroupNamedContainer(containerName, localImpl);
    boolean writeAccess;
    if (!isOwner) {
        // check if participants have read/write access
        int folderAccess = CollaborationTools.FOLDER_ACCESS_ALL;
        Long lFolderAccess = collaborationManager.lookupFolderAccess(group);
        if (lFolderAccess != null) {
            folderAccess = lFolderAccess.intValue();
        }
        writeAccess = (folderAccess == CollaborationTools.FOLDER_ACCESS_ALL);
    } else {
        writeAccess = true;
    }
    VFSSecurityCallback secCallback;
    if (writeAccess) {
        SubscriptionContext sc = new SubscriptionContext(group, "toolfolder");
        secCallback = new FullAccessWithLazyQuotaCallback(folderPath, QuotaConstants.IDENTIFIER_DEFAULT_GROUPS, sc);
    } else {
        secCallback = new ReadOnlyCallback();
    }
    grpContainer.setLocalSecurityCallback(secCallback);
    return grpContainer;
}
Also used : FullAccessWithLazyQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithLazyQuotaCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 4 with ReadOnlyCallback

use of org.olat.core.util.vfs.callbacks.ReadOnlyCallback in project OpenOLAT by OpenOLAT.

the class WebDAVManagerImpl method createEmptyRoot.

private WebResourceRoot createEmptyRoot(UserSession usess) {
    // create the / folder
    VirtualContainer rootContainer = new VirtualContainer("");
    rootContainer.setLocalSecurityCallback(new ReadOnlyCallback());
    return new VFSResourceRoot(usess.getIdentity(), rootContainer);
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 5 with ReadOnlyCallback

use of org.olat.core.util.vfs.callbacks.ReadOnlyCallback 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)

Aggregations

ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)30 VFSContainer (org.olat.core.util.vfs.VFSContainer)20 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)12 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)8 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)6 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)6 MergeSource (org.olat.core.util.vfs.MergeSource)6 BCCourseNode (org.olat.course.nodes.BCCourseNode)6 CourseNode (org.olat.course.nodes.CourseNode)6 PFCourseNode (org.olat.course.nodes.PFCourseNode)6 Path (javax.ws.rs.Path)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 WindowControl (org.olat.core.gui.control.WindowControl)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 VirtualContainer (org.olat.core.util.vfs.VirtualContainer)4 VFSWebservice (org.olat.core.util.vfs.restapi.VFSWebservice)4 CourseConfig (org.olat.course.config.CourseConfig)4