Search in sources :

Example 11 with VFSSecurityCallback

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

the class CmdMoveCopy method doMove.

private void doMove(UserRequest ureq) {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    if (selectedPath == null) {
        abortFailed(ureq, "failed");
        return;
    }
    VFSStatus vfsStatus = VFSConstants.SUCCESS;
    VFSContainer rootContainer = folderComponent.getRootContainer();
    VFSItem vfsItem = rootContainer.resolve(selectedPath);
    if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
        abortFailed(ureq, "failed");
        return;
    }
    // copy the files
    VFSContainer target = (VFSContainer) vfsItem;
    List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
    if (sources == null)
        return;
    boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
    for (VFSItem vfsSource : sources) {
        if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
            // copy the metainfo first
            MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
            if (meta != null) {
                meta.moveCopyToDir((OlatRelPathImpl) target, move);
            }
        }
        VFSItem targetFile = target.resolve(vfsSource.getName());
        if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
            // add a new version to the file
            ((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
        } else {
            vfsStatus = target.copyFrom(vfsSource);
        }
        if (vfsStatus != VFSConstants.SUCCESS) {
            String errorKey = "failed";
            if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
                errorKey = "QuotaExceeded";
            abortFailed(ureq, errorKey);
            return;
        }
        if (move) {
            // if move, delete the source. Note that meta source
            // has already been delete (i.e. moved)
            vfsSource.delete();
        }
    }
    // after a copy or a move, notify the subscribers
    VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (secCallback != null) {
        SubscriptionContext subsContext = secCallback.getSubscriptionContext();
        if (subsContext != null) {
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        }
    }
    fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
    notifyFinished(ureq);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) 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) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 12 with VFSSecurityCallback

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

the class PFManager method provideParticipantFolder.

/**
 * Provide participant folder in GUI.
 *
 * @param pfNode
 * @param pfView
 * @param courseEnv
 * @param identity
 * @param isCoach
 * @return the VFS container
 */
public VFSContainer provideParticipantFolder(PFCourseNode pfNode, PFView pfView, Translator translator, CourseEnvironment courseEnv, Identity identity, boolean isCoach, boolean readOnly) {
    SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
    VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
    String baseContainerName = userManager.getUserDisplayName(identity);
    VirtualContainer namedCourseFolder = new VirtualContainer(baseContainerName);
    namedCourseFolder.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
    VFSContainer dropContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
    if (pfNode.hasParticipantBoxConfigured()) {
        namedCourseFolder.addItem(dropContainer);
    }
    VFSContainer returnContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
    if (pfNode.hasCoachBoxConfigured()) {
        namedCourseFolder.addItem(returnContainer);
    }
    if (readOnly) {
        dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
        returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
    } else {
        if (isCoach) {
            dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
            returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
        } else {
            VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
            VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, false);
            dropContainer.setLocalSecurityCallback(callback);
            returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
        }
    }
    VFSContainer folderRunContainer;
    switch(pfView) {
        case dropAndReturn:
            folderRunContainer = namedCourseFolder;
            break;
        case onlyDrop:
            folderRunContainer = dropContainer;
            break;
        case onlyReturn:
            folderRunContainer = returnContainer;
            break;
        default:
            folderRunContainer = namedCourseFolder;
            break;
    }
    return folderRunContainer;
}
Also used : Path(java.nio.file.Path) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 13 with VFSSecurityCallback

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

the class PFManager method provideParticipantContainer.

/**
 * Provide participant view in webdav.
 *
 * @param pfNode
 * @param courseEnv
 * @param identity
 * @return the VFS container
 */
private VFSContainer provideParticipantContainer(PFCourseNode pfNode, CourseEnvironment courseEnv, Identity identity, boolean courseReadOnly) {
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
    SubscriptionContext subsContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    VirtualContainer namedCourseFolder = new VirtualContainer(identity.getName());
    Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
    VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
    if (pfNode.hasParticipantBoxConfigured()) {
        VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
        if (courseReadOnly) {
            dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
        } else {
            VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
            VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, true);
            dropContainer.setLocalSecurityCallback(callback);
        }
        namedCourseFolder.addItem(dropContainer);
    }
    if (pfNode.hasCoachBoxConfigured()) {
        VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
        returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
        namedCourseFolder.addItem(returnContainer);
    }
    return namedCourseFolder;
}
Also used : Locale(java.util.Locale) Path(java.nio.file.Path) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Translator(org.olat.core.gui.translator.Translator) VFSContainer(org.olat.core.util.vfs.VFSContainer) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 14 with VFSSecurityCallback

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

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

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

the class UserFoldersWebService method getFolder.

@Path("personal")
public VFSWebservice getFolder(@Context HttpServletRequest request) {
    Identity ureqIdentity = getIdentity(request);
    if (identity.getKey().equals(ureqIdentity.getKey())) {
        // private and public folder
        VFSContainer myFodlers = new BriefcaseWebDAVProvider().getContainer(ureqIdentity);
        return new VFSWebservice(myFodlers);
    } else {
        // only public
        String chosenUserFolderRelPath = FolderConfig.getUserHome(identity.getName()) + "/" + "public";
        OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(chosenUserFolderRelPath, null);
        VFSSecurityCallback secCallback = new ReadOnlyCallback();
        rootFolder.setLocalSecurityCallback(secCallback);
        return new VFSWebservice(rootFolder);
    }
}
Also used : BriefcaseWebDAVProvider(org.olat.core.commons.modules.bc.BriefcaseWebDAVProvider) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) VFSContainer(org.olat.core.util.vfs.VFSContainer) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) VFSWebservice(org.olat.core.util.vfs.restapi.VFSWebservice) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) Path(javax.ws.rs.Path)

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