Search in sources :

Example 46 with VFSSecurityCallback

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

the class MergedCourseContainer method getBCContainer.

private VFSContainer getBCContainer(ICourse course, BCCourseNode bcNode, NodeEvaluation nodeEval, boolean isOlatAdmin) {
    bcNode.updateModuleConfigDefaults(false);
    // add folder not to merge source. Use name and node id to have unique name
    VFSContainer rootFolder = null;
    String subpath = bcNode.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
    if (StringHelper.containsNonWhitespace(subpath)) {
        if (bcNode.isSharedFolder()) {
            // grab any shared folder that is configured
            OlatRootFolderImpl sharedFolder = null;
            String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
            if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
                RepositoryManager rm = RepositoryManager.getInstance();
                RepositoryEntry re = rm.lookupRepositoryEntryBySoftkey(sfSoftkey, false);
                if (re != null) {
                    sharedFolder = SharedFolderManager.getInstance().getSharedFolder(re.getOlatResource());
                    VFSContainer courseBase = sharedFolder;
                    subpath = subpath.replaceFirst("/_sharedfolder", "");
                    rootFolder = (VFSContainer) courseBase.resolve(subpath);
                    if (rootFolder != null && (course.getCourseConfig().isSharedFolderReadOnlyMount() || courseReadOnly)) {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                }
            }
        } else {
            VFSContainer courseBase = course.getCourseBaseContainer();
            rootFolder = (VFSContainer) courseBase.resolve("/coursefolder" + subpath);
        }
    }
    if (bcNode.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
        String path = BCCourseNode.getFoldernodePathRelToFolderBase(course.getCourseEnvironment(), bcNode);
        rootFolder = new OlatRootFolderImpl(path, null);
        if (nodeEval != null) {
            rootFolder.setLocalSecurityCallback(new FolderNodeCallback(path, nodeEval, isOlatAdmin, false, null));
        } else {
            VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(this);
            if (secCallback != null) {
                rootFolder.setLocalSecurityCallback(new OverrideQuotaSecurityCallback(path, secCallback));
            }
        }
    }
    return rootFolder;
}
Also used : FolderNodeCallback(org.olat.course.nodes.bc.FolderNodeCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 47 with VFSSecurityCallback

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

the class PFManager method calculateCallback.

/**
 * Calculate callback dependent on ModuleConfiguration.
 *
 * @param pfNode
 * @param dropbox
 * @return the VFSSecurityCallback
 */
private VFSSecurityCallback calculateCallback(CourseEnvironment courseEnv, PFCourseNode pfNode, VFSContainer dropbox, boolean webdav) {
    VFSSecurityCallback callback;
    SubscriptionContext folderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    int count = countFiles(dropbox);
    boolean limitCount = pfNode.hasLimitCountConfigured() && pfNode.isGreaterOrEqualToLimit(count);
    boolean timeFrame = pfNode.hasDropboxTimeFrameConfigured() && !pfNode.isInDropboxTimeFrame();
    boolean alterFile = pfNode.hasAlterFileConfigured();
    if (timeFrame || limitCount && !alterFile) {
        callback = new ReadOnlyCallback(folderSubContext);
    } else if (webdav) {
        callback = new CountingCallback(folderSubContext, dropbox, pfNode.getLimitCount(), alterFile);
    } else if (limitCount && alterFile) {
        callback = new ReadDeleteCallback(folderSubContext);
    } else if (!limitCount && !alterFile) {
        callback = new ReadWriteCallback(folderSubContext);
    } else {
        callback = new ReadWriteDeleteCallback(folderSubContext);
    }
    return callback;
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 48 with VFSSecurityCallback

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

the class PFManager method provideCoachContainer.

/**
 * Provide coach view in webdav.
 *
 * @param pfNode
 * @param courseEnv
 * @param identity
 * @return the VFSContainer
 */
private VFSContainer provideCoachContainer(PFCourseNode pfNode, CourseEnvironment courseEnv, Identity identity, boolean admin) {
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
    SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
    List<Identity> participants = getParticipants(identity, courseEnv, admin);
    String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
    VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
    VirtualContainer namedCourseFolder = new VirtualContainer(translator.translate("participant.folder"));
    for (Identity participant : participants) {
        Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(participant));
        VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
        String participantfoldername = userManager.getUserDisplayName(participant);
        VirtualContainer participantFolder = new VirtualContainer(participantfoldername);
        namedCourseFolder.addItem(participantFolder);
        if (pfNode.hasParticipantBoxConfigured()) {
            VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
            // if coach is also participant, can user his/her webdav folder with participant rights
            if (identity.equals(participant)) {
                VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
                VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, true);
                dropContainer.setLocalSecurityCallback(callback);
            } else {
                dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
            }
            participantFolder.addItem(dropContainer);
        }
        if (pfNode.hasCoachBoxConfigured()) {
            VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
            returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
            participantFolder.addItem(returnContainer);
        }
    }
    return namedCourseFolder;
}
Also used : Locale(java.util.Locale) Path(java.nio.file.Path) VFSContainer(org.olat.core.util.vfs.VFSContainer) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Translator(org.olat.core.gui.translator.Translator) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 49 with VFSSecurityCallback

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

the class TaskFolderCallback method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (log.isDebug())
        log.debug("event source=" + source + " " + event.toString());
    if (source == btfButton) {
        // check if there are already assigned tasks
        CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
        List<Property> assignedProps = cpm.listCourseNodeProperties(node, null, null, TaskController.PROP_ASSIGNED);
        if (assignedProps.size() == 0) {
            // no task assigned
            String relPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course, node);
            OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(relPath, null);
            OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(translate("taskfolder"), rootFolder);
            namedFolder.setLocalSecurityCallback(getTaskFolderSecCallback(relPath));
            frc = new FolderRunController(namedFolder, false, ureq, getWindowControl());
            // listenTo(frc);
            frc.addControllerListener(this);
            CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("folder.close"), frc.getInitialComponent());
            cmc.activate();
        } else {
            // already assigned task => open dialog with warn
            String[] args = new String[] { new Integer(assignedProps.size()).toString() };
            dialogBoxController = activateOkCancelDialog(ureq, "", getTranslator().translate("taskfolder.overwriting.confirm", args), dialogBoxController);
        }
    } else if (source == vfButton) {
        // switch to new dialog
        OlatNamedContainerImpl namedContainer = TACourseNode.getNodeFolderContainer(node, course.getCourseEnvironment());
        Quota quota = QuotaManager.getInstance().getCustomQuota(namedContainer.getRelPath());
        if (quota == null) {
            Quota defQuota = QuotaManager.getInstance().getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_NODES);
            quota = QuotaManager.getInstance().createQuota(namedContainer.getRelPath(), defQuota.getQuotaKB(), defQuota.getUlLimitKB());
        }
        SubscriptionContext subContext = SolutionFileUploadNotificationHandler.getSubscriptionContext(course.getCourseEnvironment(), node);
        VFSSecurityCallback secCallback = new FullAccessWithQuotaCallback(quota, subContext);
        namedContainer.setLocalSecurityCallback(secCallback);
        FolderRunController folderCtrl = new FolderRunController(namedContainer, false, ureq, getWindowControl());
        CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("close"), folderCtrl.getInitialComponent());
        cmc.activate();
    } else if (source == editScoringConfigButton) {
        scoringController.setDisplayOnly(false);
        editScoring.contextPut("isOverwriting", new Boolean(true));
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FullAccessWithQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback) Quota(org.olat.core.util.vfs.Quota) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Property(org.olat.properties.Property) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 50 with VFSSecurityCallback

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

the class DocumentPoolMainController method doSelectTemplatesDirectory.

private DocumentDirectoryController doSelectTemplatesDirectory(UserRequest ureq, TaxonomyTreeNode node) {
    content.popUpToRootController(ureq);
    VFSContainer directory = node.getDirectory();
    VFSSecurityCallback secCallback = isTaxonomyAdmin ? new FullAccessCallback() : new ReadOnlyCallback();
    directory.setLocalSecurityCallback(secCallback);
    String name = translate("document.pool.templates");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("Templates", 0l);
    WindowControl bwControl = addToHistory(ureq, ores, null);
    DocumentDirectoryController directoryCtrl = new DocumentDirectoryController(ureq, bwControl, directory, name);
    directoryCtrl.setAdditionalResourceURL("[Templates:0]");
    listenTo(directoryCtrl);
    content.pushController(name, directoryCtrl);
    return directoryCtrl;
}
Also used : FullAccessCallback(org.olat.core.util.vfs.callbacks.FullAccessCallback) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) WindowControl(org.olat.core.gui.control.WindowControl) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) TaxonomyVFSSecurityCallback(org.olat.modules.taxonomy.ui.component.TaxonomyVFSSecurityCallback)

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