Skip to content
Snippets Groups Projects
Commit 8f7656b4 authored by uhensler's avatar uhensler
Browse files

OO-3170: Add default license to created files and to with WebDAV uploaded files.

parent 0d618451
No related branches found
No related tags found
No related merge requests found
...@@ -29,9 +29,14 @@ import org.olat.core.commons.editor.htmleditor.HTMLEditorController; ...@@ -29,9 +29,14 @@ import org.olat.core.commons.editor.htmleditor.HTMLEditorController;
import org.olat.core.commons.editor.htmleditor.WysiwygFactory; import org.olat.core.commons.editor.htmleditor.WysiwygFactory;
import org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController; import org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController;
import org.olat.core.commons.modules.bc.FolderEvent; import org.olat.core.commons.modules.bc.FolderEvent;
import org.olat.core.commons.modules.bc.FolderLicenseHandler;
import org.olat.core.commons.modules.bc.components.FolderComponent; import org.olat.core.commons.modules.bc.components.FolderComponent;
import org.olat.core.commons.modules.bc.meta.MetaInfo; import org.olat.core.commons.modules.bc.meta.MetaInfo;
import org.olat.core.commons.modules.bc.meta.tagged.MetaTagged; import org.olat.core.commons.modules.bc.meta.tagged.MetaTagged;
import org.olat.core.commons.services.license.License;
import org.olat.core.commons.services.license.LicenseModule;
import org.olat.core.commons.services.license.LicenseService;
import org.olat.core.commons.services.license.ui.LicenseUIFactory;
import org.olat.core.commons.services.notifications.NotificationsManager; import org.olat.core.commons.services.notifications.NotificationsManager;
import org.olat.core.commons.services.notifications.SubscriptionContext; import org.olat.core.commons.services.notifications.SubscriptionContext;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
...@@ -53,6 +58,7 @@ import org.olat.core.util.vfs.VFSLeaf; ...@@ -53,6 +58,7 @@ import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.VFSManager; import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.callbacks.VFSSecurityCallback; import org.olat.core.util.vfs.callbacks.VFSSecurityCallback;
import org.olat.core.util.vfs.util.ContainerAndFile; import org.olat.core.util.vfs.util.ContainerAndFile;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* *
...@@ -71,6 +77,13 @@ public class CmdCreateFile extends FormBasicController implements FolderCommand ...@@ -71,6 +77,13 @@ public class CmdCreateFile extends FormBasicController implements FolderCommand
private Controller editorCtr; private Controller editorCtr;
private TextElement textElement; private TextElement textElement;
private FolderComponent folderComponent; private FolderComponent folderComponent;
@Autowired
private LicenseService licenseService;
@Autowired
private LicenseModule licenseModule;
@Autowired
private FolderLicenseHandler licenseHandler;
protected CmdCreateFile(UserRequest ureq, WindowControl wControl) { protected CmdCreateFile(UserRequest ureq, WindowControl wControl) {
super(ureq, wControl); super(ureq, wControl);
...@@ -182,6 +195,13 @@ public class CmdCreateFile extends FormBasicController implements FolderCommand ...@@ -182,6 +195,13 @@ public class CmdCreateFile extends FormBasicController implements FolderCommand
if(item instanceof MetaTagged) { if(item instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged)item).getMetaInfo(); MetaInfo meta = ((MetaTagged)item).getMetaInfo();
meta.setAuthor(ureq.getIdentity()); meta.setAuthor(ureq.getIdentity());
if (licenseModule.isEnabled(licenseHandler)) {
License license = licenseService.createDefaultLicense(licenseHandler, getIdentity());
meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
meta.setLicenseTypeName(license.getLicenseType().getName());
meta.setLicensor(license.getLicensor());
meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
}
meta.write(); meta.write();
} }
......
...@@ -258,7 +258,7 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo { ...@@ -258,7 +258,7 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo {
} }
/** /**
* Copy values from froMeta into this object except name. * Copy values from fromMeta into this object except name.
* @param fromMeta * @param fromMeta
*/ */
@Override @Override
...@@ -274,6 +274,10 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo { ...@@ -274,6 +274,10 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo {
this.setSource(fromMeta.getSource()); this.setSource(fromMeta.getSource());
this.setTitle(fromMeta.getTitle()); this.setTitle(fromMeta.getTitle());
this.setUrl(fromMeta.getUrl()); this.setUrl(fromMeta.getUrl());
this.setLicenseTypeKey(fromMeta.getLicenseTypeKey());
this.setLicenseTypeName(fromMeta.getLicenseTypeName());
this.setLicensor(fromMeta.getLicensor());
this.setLicenseText(fromMeta.getLicenseText());
} }
public boolean isLocked() { public boolean isLocked() {
...@@ -809,7 +813,7 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo { ...@@ -809,7 +813,7 @@ public class MetaInfoFileImpl extends DefaultHandler implements MetaInfo {
@Override @Override
public void setLicensor(String licensor) { public void setLicensor(String licensor) {
this.licensor = licensor; this.licensor = licensor != null? licensor: "";
} }
@Override @Override
......
...@@ -475,7 +475,7 @@ public class MetaInfoFormController extends FormBasicController { ...@@ -475,7 +475,7 @@ public class MetaInfoFormController extends FormBasicController {
License license = getLicenseFromFormItems(); License license = getLicenseFromFormItems();
meta.setLicenseTypeKey(license.getLicenseType() != null? String.valueOf(license.getLicenseType().getKey()): ""); meta.setLicenseTypeKey(license.getLicenseType() != null? String.valueOf(license.getLicenseType().getKey()): "");
meta.setLicenseTypeName(license.getLicenseType() != null? license.getLicenseType().getName(): ""); meta.setLicenseTypeName(license.getLicenseType() != null? license.getLicenseType().getName(): "");
meta.setLicensor(license.getLicensor()); meta.setLicensor(license.getLicensor() != null? license.getLicensor(): "");
meta.setLicenseText(LicenseUIFactory.getLicenseText(license)); meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
return meta; return meta;
} }
......
...@@ -73,7 +73,8 @@ public class LicenseRenderer implements FlexiCellRenderer { ...@@ -73,7 +73,8 @@ public class LicenseRenderer implements FlexiCellRenderer {
// popup with license informations // popup with license informations
sb.append("<div id='o_lic_pop_").append(id).append("' style='display:none;'><div>"); sb.append("<div id='o_lic_pop_").append(id).append("' style='display:none;'><div>");
appendStaticcontrol(sb, "license.popup.type", LicenseUIFactory.translate(licenseType, locale)); appendStaticcontrol(sb, "license.popup.type", LicenseUIFactory.translate(licenseType, locale));
appendStaticcontrol(sb, "license.popup.licensor", license.getLicensor()); String licensor = license.getLicensor() != null? license.getLicensor(): "";
appendStaticcontrol(sb, "license.popup.licensor", licensor);
appendStaticcontrol(sb, "license.popup.text", LicenseUIFactory.getFormattedLicenseText(license)); appendStaticcontrol(sb, "license.popup.text", LicenseUIFactory.getFormattedLicenseText(license));
sb.append("</div>"); sb.append("</div>");
......
...@@ -27,8 +27,14 @@ import java.util.Collections; ...@@ -27,8 +27,14 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.FolderLicenseHandler;
import org.olat.core.commons.modules.bc.meta.MetaInfo; import org.olat.core.commons.modules.bc.meta.MetaInfo;
import org.olat.core.commons.modules.bc.meta.tagged.MetaTagged; import org.olat.core.commons.modules.bc.meta.tagged.MetaTagged;
import org.olat.core.commons.services.license.License;
import org.olat.core.commons.services.license.LicenseModule;
import org.olat.core.commons.services.license.LicenseService;
import org.olat.core.commons.services.license.ui.LicenseUIFactory;
import org.olat.core.commons.services.notifications.NotificationsManager; import org.olat.core.commons.services.notifications.NotificationsManager;
import org.olat.core.commons.services.notifications.SubscriptionContext; import org.olat.core.commons.services.notifications.SubscriptionContext;
import org.olat.core.commons.services.webdav.servlets.WebResource; import org.olat.core.commons.services.webdav.servlets.WebResource;
...@@ -231,6 +237,7 @@ public class VFSResourceRoot implements WebResourceRoot { ...@@ -231,6 +237,7 @@ public class VFSResourceRoot implements WebResourceRoot {
MetaInfo infos = ((MetaTagged)childLeaf).getMetaInfo(); MetaInfo infos = ((MetaTagged)childLeaf).getMetaInfo();
if(infos != null && !infos.hasAuthorIdentity()) { if(infos != null && !infos.hasAuthorIdentity()) {
infos.setAuthor(identity); infos.setAuthor(identity);
addLicense(infos, identity);
infos.clearThumbnails(); infos.clearThumbnails();
//infos.write(); the clearThumbnails call write() //infos.write(); the clearThumbnails call write()
} }
...@@ -248,6 +255,19 @@ public class VFSResourceRoot implements WebResourceRoot { ...@@ -248,6 +255,19 @@ public class VFSResourceRoot implements WebResourceRoot {
return true; return true;
} }
private void addLicense(MetaInfo meta, Identity identity) {
LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
LicenseModule licenseModule = CoreSpringFactory.getImpl(LicenseModule.class);
FolderLicenseHandler licenseHandler = CoreSpringFactory.getImpl(FolderLicenseHandler.class);
if (licenseModule.isEnabled(licenseHandler)) {
License license = licenseService.createDefaultLicense(licenseHandler, identity);
meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
meta.setLicenseTypeName(license.getLicenseType().getName());
meta.setLicensor(license.getLicensor());
meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
}
}
private void copyVFS(VFSLeaf file, InputStream is) throws IOException { private void copyVFS(VFSLeaf file, InputStream is) throws IOException {
// Try to get Quota // Try to get Quota
long quotaLeft = -1; long quotaLeft = -1;
......
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