Skip to content
Snippets Groups Projects
Commit 3111fa86 authored by uhensler's avatar uhensler
Browse files

OO-3939: Open documents read-only if folder is not writable

parent af4a4d15
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ package org.olat.core.commons.editor.fileeditor; ...@@ -28,6 +28,7 @@ package org.olat.core.commons.editor.fileeditor;
import org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel; import org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel;
import org.olat.core.commons.editor.htmleditor.HTMLEditorController; import org.olat.core.commons.editor.htmleditor.HTMLEditorController;
import org.olat.core.commons.editor.htmleditor.HTMLReadOnlyController;
import org.olat.core.commons.editor.htmleditor.WysiwygFactory; import org.olat.core.commons.editor.htmleditor.WysiwygFactory;
import org.olat.core.commons.editor.plaintexteditor.TextEditorController; import org.olat.core.commons.editor.plaintexteditor.TextEditorController;
import org.olat.core.commons.modules.bc.components.FolderComponent; import org.olat.core.commons.modules.bc.components.FolderComponent;
...@@ -77,42 +78,47 @@ public class FileEditorController extends BasicController { ...@@ -77,42 +78,47 @@ public class FileEditorController extends BasicController {
// } // }
// start HTML editor with the folders root folder as base and the file
// path as a relative path from the root directory. But first check if the
// root directory is wirtable at all (e.g. not the case in users personal
// briefcase), and seach for the next higher directory that is writable.
String relFilePath = "/" + vfsLeaf.getName();
// add current container path if not at root level
if (!folderComponent.getCurrentContainerPath().equals("/")) {
relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
}
VFSContainer writableRootContainer = folderComponent.getRootContainer();
ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
if (result != null) {
if(vfsLeaf.getParentContainer() != null) {
writableRootContainer = vfsLeaf.getParentContainer();
relFilePath = vfsLeaf.getName();
} else {
writableRootContainer = result.getContainer();
}
} else {
// use fallback that always work: current directory and current file
relFilePath = vfsLeaf.getName();
writableRootContainer = folderComponent.getCurrentContainer();
}
// launch plaintext or html editor depending on file type // launch plaintext or html editor depending on file type
if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) { if (vfsLeaf.getName().endsWith(".html") || vfsLeaf.getName().endsWith(".htm")) {
CustomLinkTreeModel customLinkTreeModel = folderComponent.getCustomLinkTreeModel(); if (secCallback.canEdit()) {
if (customLinkTreeModel != null) { // start HTML editor with the folders root folder as base and the file
editCtrl = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), writableRootContainer, relFilePath, true, customLinkTreeModel); // path as a relative path from the root directory. But first check if the
((HTMLEditorController)editCtrl).setNewFile(false); // root directory is wirtable at all (e.g. not the case in users personal
} else { // briefcase), and seach for the next higher directory that is writable.
editCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true); String relFilePath = "/" + vfsLeaf.getName();
((HTMLEditorController)editCtrl).setNewFile(false); // add current container path if not at root level
if (!folderComponent.getCurrentContainerPath().equals("/")) {
relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
}
VFSContainer writableRootContainer = folderComponent.getRootContainer();
ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
if (result != null) {
if(vfsLeaf.getParentContainer() != null) {
writableRootContainer = vfsLeaf.getParentContainer();
relFilePath = vfsLeaf.getName();
} else {
writableRootContainer = result.getContainer();
}
} else {
// use fallback that always work: current directory and current file
relFilePath = vfsLeaf.getName();
writableRootContainer = folderComponent.getCurrentContainer();
}
CustomLinkTreeModel customLinkTreeModel = folderComponent.getCustomLinkTreeModel();
if (customLinkTreeModel != null) {
editCtrl = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), writableRootContainer, relFilePath, true, customLinkTreeModel);
((HTMLEditorController)editCtrl).setNewFile(false);
} else {
editCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
((HTMLEditorController)editCtrl).setNewFile(false);
}
} else {
editCtrl = new HTMLReadOnlyController(ureq, getWindowControl(), vfsLeaf.getParentContainer(), vfsLeaf.getName(), secCallback.canClose());
} }
} }
else { else {
editCtrl = new TextEditorController(ureq, getWindowControl(), vfsLeaf, "utf-8", false); editCtrl = new TextEditorController(ureq, getWindowControl(), vfsLeaf, "utf-8", !secCallback.canEdit());
} }
listenTo(editCtrl); listenTo(editCtrl);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.editor.htmleditor;
import org.olat.core.commons.modules.singlepage.SinglePageController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.link.LinkFactory;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
import org.olat.core.util.vfs.VFSContainer;
/**
*
* Initial date: 25 Mar 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class HTMLReadOnlyController extends BasicController {
private Link closeLink;
private SinglePageController singlePageCtrl;
public HTMLReadOnlyController(UserRequest ureq, WindowControl wControl, VFSContainer rootContainer, String fileName, boolean showClose) {
super(ureq, wControl);
VelocityContainer mainVC = createVelocityContainer("readonly");
singlePageCtrl = new SinglePageController(ureq, wControl, rootContainer, fileName, false);
listenTo(singlePageCtrl);
mainVC.put("content", singlePageCtrl.getInitialComponent());
if (showClose) {
closeLink = LinkFactory.createButton("close", mainVC, this);
}
putInitialPanel(mainVC);
}
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == closeLink) {
fireEvent(ureq, Event.DONE_EVENT);
}
}
@Override
protected void doDispose() {
//
}
}
<div class="o_html_readonly">
$r.render("content")
#if($r.available("close"))
<div class="o_button_group">$r.render("close")</div>
#end
</div>
\ No newline at end of file
...@@ -112,7 +112,11 @@ public class CmdOpenContent extends BasicController implements FolderCommand { ...@@ -112,7 +112,11 @@ public class CmdOpenContent extends BasicController implements FolderCommand {
return null; return null;
} }
VFSLeafEditorSecurityCallback secCallback = VFSLeafEditorSecurityCallbackBuilder.builder().build(); VFSContainer container = VFSManager.findInheritingSecurityCallbackContainer(folderComponent.getCurrentContainer());
VFSSecurityCallback containerSecCallback = container.getLocalSecurityCallback();
VFSLeafEditorSecurityCallback secCallback = VFSLeafEditorSecurityCallbackBuilder.builder()
.canEdit(containerSecCallback.canWrite())
.build();
editCtrl = editor.get().getRunController(ureq, wControl, vfsLeaf, folderComponent, getIdentity(), secCallback); editCtrl = editor.get().getRunController(ureq, wControl, vfsLeaf, folderComponent, getIdentity(), secCallback);
listenTo(editCtrl); listenTo(editCtrl);
......
...@@ -99,17 +99,6 @@ public class SinglePageController extends BasicController implements CloneableCo ...@@ -99,17 +99,6 @@ public class SinglePageController extends BasicController implements CloneableCo
private VFSContainer g_new_rootContainer; private VFSContainer g_new_rootContainer;
private Long courseRepoKey; private Long courseRepoKey;
/**
*
* @param ureq
* @param wControl
* @param inIframe
* @param rootContainer
* @param fileName
* @param currentUri
* @param allowRelativeLinks
* @param showHomeLink
*/
public SinglePageController(UserRequest ureq, WindowControl wControl, VFSContainer rootContainer, String fileName, public SinglePageController(UserRequest ureq, WindowControl wControl, VFSContainer rootContainer, String fileName,
boolean allowRelativeLinks) { boolean allowRelativeLinks) {
//default behavior is to show the home link in a single page //default behavior is to show the home link in a single page
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment