Skip to content
Snippets Groups Projects
Commit a40b406d authored by srosse's avatar srosse
Browse files

OO-922: add a check box to force downloads of files in the folder component

parent bb824338
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ package org.olat.admin.security; ...@@ -21,6 +21,7 @@ package org.olat.admin.security;
import org.olat.basesecurity.BaseSecurityModule; import org.olat.basesecurity.BaseSecurityModule;
import org.olat.core.CoreSpringFactory; import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.FolderModule;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.FormItemContainer;
...@@ -38,12 +39,15 @@ import org.olat.core.gui.control.WindowControl; ...@@ -38,12 +39,15 @@ import org.olat.core.gui.control.WindowControl;
*/ */
public class SecurityAdminController extends FormBasicController { public class SecurityAdminController extends FormBasicController {
private MultipleSelectionElement wikiEl, topFrameEl; private MultipleSelectionElement wikiEl, topFrameEl, forceDownloadEl;
private final FolderModule folderModule;
private final BaseSecurityModule securityModule; private final BaseSecurityModule securityModule;
public SecurityAdminController(UserRequest ureq, WindowControl wControl) { public SecurityAdminController(UserRequest ureq, WindowControl wControl) {
super(ureq, wControl); super(ureq, wControl);
securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class); securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class);
folderModule = CoreSpringFactory.getImpl(FolderModule.class);
initForm(ureq); initForm(ureq);
} }
...@@ -63,6 +67,10 @@ public class SecurityAdminController extends FormBasicController { ...@@ -63,6 +67,10 @@ public class SecurityAdminController extends FormBasicController {
wikiEl = uifactory.addCheckboxesHorizontal("sec.wiki", "sec.wiki", formLayout, frameKeys, frameValues, null); wikiEl = uifactory.addCheckboxesHorizontal("sec.wiki", "sec.wiki", formLayout, frameKeys, frameValues, null);
wikiEl.select("on", securityModule.isWikiEnabled()); wikiEl.select("on", securityModule.isWikiEnabled());
wikiEl.addActionListener(this, FormEvent.ONCHANGE); wikiEl.addActionListener(this, FormEvent.ONCHANGE);
forceDownloadEl = uifactory.addCheckboxesHorizontal("sec.download", "sec.force.download", formLayout, frameKeys, frameValues, null);
forceDownloadEl.select("on", folderModule.isForceDownload());
forceDownloadEl.addActionListener(this, FormEvent.ONCHANGE);
} }
@Override @Override
...@@ -78,6 +86,9 @@ public class SecurityAdminController extends FormBasicController { ...@@ -78,6 +86,9 @@ public class SecurityAdminController extends FormBasicController {
} else if(wikiEl == source) { } else if(wikiEl == source) {
boolean enabled = wikiEl.isAtLeastSelected(1); boolean enabled = wikiEl.isAtLeastSelected(1);
securityModule.setWikiEnabled(enabled); securityModule.setWikiEnabled(enabled);
} else if(forceDownloadEl == source) {
boolean enabled = forceDownloadEl.isAtLeastSelected(1);
folderModule.setForceDownload(enabled);
} }
super.formInnerEvent(ureq, source, event); super.formInnerEvent(ureq, source, event);
} }
...@@ -86,8 +97,4 @@ public class SecurityAdminController extends FormBasicController { ...@@ -86,8 +97,4 @@ public class SecurityAdminController extends FormBasicController {
protected void formOK(UserRequest ureq) { protected void formOK(UserRequest ureq) {
// //
} }
}
\ No newline at end of file
}
...@@ -6,6 +6,7 @@ chelp.ced-sec.title=Sicherheitsaspekten von OpenOLAT ...@@ -6,6 +6,7 @@ chelp.ced-sec.title=Sicherheitsaspekten von OpenOLAT
help.hover.sec=Hilfe zur Sicherheits in OpenOLAT konfigurieren help.hover.sec=Hilfe zur Sicherheits in OpenOLAT konfigurieren
sec.title=Sicherheitsaspekten von OpenOLAT sec.title=Sicherheitsaspekten von OpenOLAT
sec.description=Sie k\u00F6nnen hier ein paar Sicherheitsentscheidung nehmen sec.description=Sie k\u00F6nnen hier ein paar Sicherheitsentscheidung nehmen
sec.force.download=Datei herunterladen
sec.topframe=Enforce top frame sec.topframe=Enforce top frame
sec.wiki=Wiki sec.wiki=Wiki
...@@ -33,6 +33,7 @@ import org.olat.core.configuration.PersistedProperties; ...@@ -33,6 +33,7 @@ import org.olat.core.configuration.PersistedProperties;
import org.olat.core.helpers.Settings; import org.olat.core.helpers.Settings;
import org.olat.core.logging.OLog; import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import org.olat.core.util.vfs.version.FolderVersioningConfigurator; import org.olat.core.util.vfs.version.FolderVersioningConfigurator;
/** /**
...@@ -42,15 +43,18 @@ import org.olat.core.util.vfs.version.FolderVersioningConfigurator; ...@@ -42,15 +43,18 @@ import org.olat.core.util.vfs.version.FolderVersioningConfigurator;
*/ */
public class FolderModule extends AbstractOLATModule { public class FolderModule extends AbstractOLATModule {
OLog log = Tracing.createLoggerFor(FolderModule.class); private static final OLog log = Tracing.createLoggerFor(FolderModule.class);
private static final String CONFIG_ROOT = "Root"; private static final String CONFIG_ROOT = "Root";
private static final String CONFIG_LIMITULMB = "LimitULMB"; private static final String CONFIG_LIMITULMB = "LimitULMB";
private static final String CONFIG_EDITFILESIZELIMIT = "EditFileSizeLimit"; private static final String CONFIG_EDITFILESIZELIMIT = "EditFileSizeLimit";
private static final String CONFIG_QUOTAMB = "QuotaMB"; private static final String CONFIG_QUOTAMB = "QuotaMB";
private static final String CONFIG_SENDDOCLINKONLY = "SendDocLinkOnly"; private static final String CONFIG_SENDDOCLINKONLY = "SendDocLinkOnly";
private static final String CONFIG_SENDDOCTOEXTERN = "SendDocToExtern"; private static final String CONFIG_SENDDOCTOEXTERN = "SendDocToExtern";
private static final String CONFIG_FORCE_DOWNLOAD = "forceDownload";
private FolderVersioningConfigurator versioning; private FolderVersioningConfigurator versioning;
private String forceDownload;
/** /**
* [used by spring] * [used by spring]
*/ */
...@@ -99,18 +103,26 @@ public class FolderModule extends AbstractOLATModule { ...@@ -99,18 +103,26 @@ public class FolderModule extends AbstractOLATModule {
// create tmp directory // create tmp directory
File fTmp = new File(FolderConfig.getCanonicalTmpDir()); File fTmp = new File(FolderConfig.getCanonicalTmpDir());
fTmp.mkdirs(); fTmp.mkdirs();
forceDownload = getStringConfigParameter(CONFIG_FORCE_DOWNLOAD, "true", true);
} }
@Override @Override
protected void initFromChangedProperties() { protected void initFromChangedProperties() {
// TODO Auto-generated method stub updateProperties();
} }
@Override @Override
public void init() { public void init() {
FolderConfig.setVersioningConfigurator(versioning); FolderConfig.setVersioningConfigurator(versioning);
updateProperties();
}
private void updateProperties() {
String enabled = getStringPropertyValue(CONFIG_FORCE_DOWNLOAD, true);
if(StringHelper.containsNonWhitespace(enabled)) {
forceDownload = enabled;
}
} }
/** /**
...@@ -125,6 +137,13 @@ public class FolderModule extends AbstractOLATModule { ...@@ -125,6 +137,13 @@ public class FolderModule extends AbstractOLATModule {
public void setPersistedProperties(PersistedProperties persistedProperties) { public void setPersistedProperties(PersistedProperties persistedProperties) {
this.moduleConfigProperties = persistedProperties; this.moduleConfigProperties = persistedProperties;
} }
} public boolean isForceDownload() {
return "true".equals(forceDownload);
}
public void setForceDownload(boolean enable) {
String enabled = enable ? "true" : "false";
setStringProperty(CONFIG_FORCE_DOWNLOAD, enabled, true);
}
}
\ No newline at end of file
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
SendDocLinkOnly=${folder.sendDocumentLinkOnly} SendDocLinkOnly=${folder.sendDocumentLinkOnly}
<!-- max edit filesize for online-editing in Bytes --> <!-- max edit filesize for online-editing in Bytes -->
EditFileSizeLimit=${folder.editFileSizeLimitBytes} EditFileSizeLimit=${folder.editFileSizeLimitBytes}
forceDownload=${folder.force.download}
</value> </value>
</property> </property>
</bean> </bean>
......
...@@ -30,7 +30,9 @@ import java.io.InputStream; ...@@ -30,7 +30,9 @@ import java.io.InputStream;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.FolderLoggingAction; import org.olat.core.commons.modules.bc.FolderLoggingAction;
import org.olat.core.commons.modules.bc.FolderModule;
import org.olat.core.commons.modules.bc.components.FolderComponent; import org.olat.core.commons.modules.bc.components.FolderComponent;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Controller;
...@@ -78,6 +80,8 @@ public class CmdServeResource implements FolderCommand { ...@@ -78,6 +80,8 @@ public class CmdServeResource implements FolderCommand {
} else if(!(vfsitem instanceof VFSLeaf)) { } else if(!(vfsitem instanceof VFSLeaf)) {
mr = new NotFoundMediaResource(path); mr = new NotFoundMediaResource(path);
} else { } else {
boolean forceDownload = CoreSpringFactory.getImpl(FolderModule.class).isForceDownload();
VFSLeaf vfsfile = (VFSLeaf)vfsitem; VFSLeaf vfsfile = (VFSLeaf)vfsitem;
if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) { if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {
// setCurrentURI(path); // setCurrentURI(path);
...@@ -106,7 +110,7 @@ public class CmdServeResource implements FolderCommand { ...@@ -106,7 +110,7 @@ public class CmdServeResource implements FolderCommand {
g_encoding = enc; g_encoding = enc;
if (useLoaded) { if (useLoaded) {
StringMediaResource smr = new StringMediaResource(); StringMediaResource smr = new StringMediaResource();
String mimetype = "text/html;charset=" + enc; String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc;
smr.setContentType(mimetype); smr.setContentType(mimetype);
smr.setEncoding(enc); smr.setEncoding(enc);
smr.setData(page); smr.setData(page);
...@@ -117,6 +121,9 @@ public class CmdServeResource implements FolderCommand { ...@@ -117,6 +121,9 @@ public class CmdServeResource implements FolderCommand {
// again) // again)
VFSMediaResource vmr = new VFSMediaResource(vfsfile); VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding(enc); vmr.setEncoding(enc);
if(forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr; mr = vmr;
} }
} else if (path.endsWith(".js")) { // a javascript library } else if (path.endsWith(".js")) { // a javascript library
...@@ -127,12 +134,20 @@ public class CmdServeResource implements FolderCommand { ...@@ -127,12 +134,20 @@ public class CmdServeResource implements FolderCommand {
// together with the mime-type, which is wrong. // together with the mime-type, which is wrong.
// so we assume the .js file has the same encoding as the html file // so we assume the .js file has the same encoding as the html file
// that loads the .js file // that loads the .js file
if (g_encoding != null) vmr.setEncoding(g_encoding); if (g_encoding != null) {
vmr.setEncoding(g_encoding);
}
if(forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr; mr = vmr;
} else if (path.endsWith(".txt")) { } else if (path.endsWith(".txt")) {
//text files created in OpenOLAT are utf-8, prefer this encoding //text files created in OpenOLAT are utf-8, prefer this encoding
VFSMediaResource vmr = new VFSMediaResource(vfsfile); VFSMediaResource vmr = new VFSMediaResource(vfsfile);
vmr.setEncoding("utf-8"); vmr.setEncoding("utf-8");
if(forceDownload) {
vmr.setDownloadable(true);
}
mr = vmr; mr = vmr;
} else { } else {
// binary data: not .html, not .htm, not .js -> treated as is // binary data: not .html, not .htm, not .js -> treated as is
...@@ -140,6 +155,8 @@ public class CmdServeResource implements FolderCommand { ...@@ -140,6 +155,8 @@ public class CmdServeResource implements FolderCommand {
// This is to prevent the login prompt in Excel, Word and PowerPoint // This is to prevent the login prompt in Excel, Word and PowerPoint
if (path.endsWith(".xlsx") || path.endsWith(".pptx") || path.endsWith(".docx")) { if (path.endsWith(".xlsx") || path.endsWith(".pptx") || path.endsWith(".docx")) {
vmr.setDownloadable(true); vmr.setDownloadable(true);
} else if(forceDownload) {
vmr.setDownloadable(true);
} }
mr = vmr; mr = vmr;
} }
......
...@@ -41,7 +41,7 @@ public class VFSMediaResource implements MediaResource { ...@@ -41,7 +41,7 @@ public class VFSMediaResource implements MediaResource {
private static final String MIME_TYPE_OCTET_STREAM = "application/octet-stream"; private static final String MIME_TYPE_OCTET_STREAM = "application/octet-stream";
//use this pseudo mime-type to force download on ie 6 //use this pseudo mime-type to force download on ie 6
private static final String MIME_TYPE_FORCE_DOWNLOAD = "application/force-download"; public static final String MIME_TYPE_FORCE_DOWNLOAD = "application/force-download";
private VFSLeaf vfsLeaf; private VFSLeaf vfsLeaf;
private String encoding; private String encoding;
boolean unknownMimeType = false; boolean unknownMimeType = false;
......
...@@ -43,6 +43,9 @@ folder.sendDocumentToExtern=true ...@@ -43,6 +43,9 @@ folder.sendDocumentToExtern=true
folder.sendDocumentLinkOnly=true folder.sendDocumentLinkOnly=true
# file size limit for HTML and text editor is 1MB # file size limit for HTML and text editor is 1MB
folder.editFileSizeLimitBytes=1048576 folder.editFileSizeLimitBytes=1048576
#force download of the files
folder.force.download=true
folder.force.download.values=true,false
######################################################################## ########################################################################
# Application settings # Application settings
......
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