Search in sources :

Example 16 with VFSSecurityCallback

use of org.olat.core.util.vfs.callbacks.VFSSecurityCallback in project openolat by klemens.

the class LearningGroupWebService method getFolder.

@Path("{groupKey}/folder")
public VFSWebservice getFolder(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return null;
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return null;
        }
    }
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (!collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER)) {
        return null;
    }
    String relPath = collabTools.getFolderRelPath();
    QuotaManager qm = QuotaManager.getInstance();
    Quota folderQuota = qm.getCustomQuota(relPath);
    if (folderQuota == null) {
        Quota defQuota = qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_GROUPS);
        folderQuota = QuotaManager.getInstance().createQuota(relPath, defQuota.getQuotaKB(), defQuota.getUlLimitKB());
    }
    SubscriptionContext subsContext = null;
    VFSSecurityCallback secCallback = new VFSWebServiceSecurityCallback(true, true, true, folderQuota, subsContext);
    OlatRootFolderImpl rootContainer = new OlatRootFolderImpl(relPath, null);
    rootContainer.setLocalSecurityCallback(secCallback);
    return new VFSWebservice(rootContainer);
}
Also used : VFSWebServiceSecurityCallback(org.olat.core.util.vfs.restapi.VFSWebServiceSecurityCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Quota(org.olat.core.util.vfs.Quota) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) QuotaManager(org.olat.core.util.vfs.QuotaManager) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSWebservice(org.olat.core.util.vfs.restapi.VFSWebservice) Path(javax.ws.rs.Path)

Example 17 with VFSSecurityCallback

use of org.olat.core.util.vfs.callbacks.VFSSecurityCallback in project openolat by klemens.

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 18 with VFSSecurityCallback

use of org.olat.core.util.vfs.callbacks.VFSSecurityCallback in project openolat by klemens.

the class BCWebService method createFolderVO.

public static FolderVO createFolderVO(IdentityEnvironment ienv, ICourse course, BCCourseNode bcNode, Collection<String> subscribed) {
    OlatNamedContainerImpl container = BCCourseNode.getSecurisedNodeFolderContainer(bcNode, course.getCourseEnvironment(), ienv);
    VFSSecurityCallback secCallback = container.getLocalSecurityCallback();
    FolderVO folderVo = new FolderVO();
    folderVo.setName(course.getCourseTitle());
    folderVo.setDetailsName(bcNode.getShortTitle());
    if (subscribed != null && subscribed.contains(bcNode.getIdent())) {
        folderVo.setSubscribed(true);
    } else {
        folderVo.setSubscribed(false);
    }
    folderVo.setCourseKey(course.getResourceableId());
    folderVo.setCourseNodeId(bcNode.getIdent());
    folderVo.setWrite(secCallback.canWrite());
    folderVo.setRead(secCallback.canRead());
    folderVo.setDelete(secCallback.canDelete());
    folderVo.setList(secCallback.canList());
    return folderVo;
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) FolderVO(org.olat.restapi.support.vo.FolderVO) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 19 with VFSSecurityCallback

use of org.olat.core.util.vfs.callbacks.VFSSecurityCallback in project openolat by klemens.

the class VFSResourceRoot method write.

@Override
public boolean write(String path, InputStream is, boolean overwrite, WebResource movedFrom) throws QuotaExceededException {
    VFSLeaf childLeaf;
    VFSItem file = resolveFile(path);
    if (file instanceof VFSLeaf) {
        if (overwrite) {
            // overwrite the file
            childLeaf = (VFSLeaf) file;
            // versioning
            if (childLeaf instanceof Versionable && ((Versionable) childLeaf).getVersions().isVersioned()) {
                if (childLeaf.getSize() == 0) {
                    VersionsManager.getInstance().createVersionsFor(childLeaf, true);
                } else {
                    VersionsManager.getInstance().addToRevisions((Versionable) childLeaf, identity, "");
                }
            }
        } else {
            return false;
        }
    } else if (file instanceof VFSContainer) {
        return false;
    } else {
        // create a new file
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1)
            return false;
        String parentPath = path.substring(0, lastSlash);
        VFSItem parentItem = resolveFile(parentPath);
        if (parentItem instanceof VFSContainer) {
            VFSContainer folder = (VFSContainer) parentItem;
            String name = path.substring(lastSlash + 1);
            childLeaf = folder.createChildLeaf(name);
        } else {
            return false;
        }
    }
    if (childLeaf == null) {
        return false;
    }
    try {
        copyVFS(childLeaf, is);
    } catch (QuotaExceededException e) {
        throw e;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
    VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(childLeaf.getParentContainer());
    if (inheritingCont != null) {
        VFSSecurityCallback callback = inheritingCont.getLocalSecurityCallback();
        if (callback != null && callback.getSubscriptionContext() != null) {
            SubscriptionContext subContext = callback.getSubscriptionContext();
            NotificationsManager.getInstance().markPublisherNews(subContext, null, true);
        }
    }
    if (childLeaf instanceof MetaTagged && identity != null) {
        MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo();
        if (infos != null && !infos.hasAuthorIdentity()) {
            infos.setAuthor(identity);
            addLicense(infos, identity);
            infos.clearThumbnails();
        // infos.write(); the clearThumbnails call write()
        }
    }
    if (movedFrom instanceof VFSResource) {
        VFSResource vfsResource = (VFSResource) movedFrom;
        if (vfsResource.getItem() instanceof Versionable && ((Versionable) vfsResource.getItem()).getVersions().isVersioned()) {
            VFSLeaf currentVersion = (VFSLeaf) vfsResource.getItem();
            VersionsManager.getInstance().move(currentVersion, childLeaf, identity);
        }
    }
    return true;
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) IOException(java.io.IOException) QuotaExceededException(org.olat.core.util.vfs.QuotaExceededException)

Example 20 with VFSSecurityCallback

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

Aggregations

VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)50 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)28 VFSContainer (org.olat.core.util.vfs.VFSContainer)26 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)24 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)10 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)8 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)8 Identity (org.olat.core.id.Identity)8 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)8 VFSItem (org.olat.core.util.vfs.VFSItem)8 Path (java.nio.file.Path)6 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)6 VirtualContainer (org.olat.core.util.vfs.VirtualContainer)6 Quota (org.olat.core.util.vfs.Quota)5 Locale (java.util.Locale)4 Path (javax.ws.rs.Path)4 WindowControl (org.olat.core.gui.control.WindowControl)4 MediaResource (org.olat.core.gui.media.MediaResource)4