From 92d7dd4781bdf7c4134cd6fdbfd6f6915919545b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Jan 2017 13:24:46 +0100 Subject: [PATCH] allow editing single files shared as public link Signed-off-by: Bjoern Schiessle --- .../lib/Controller/ShareAPIController.php | 1 + core/js/sharedialoglinkshareview.js | 39 ++++++++++++++++++- core/js/shareitemmodel.js | 16 ++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index ccd0e3aa31d..6181cde6fe6 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -668,6 +668,7 @@ class ShareAPIController extends OCSController { \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct \OCP\Constants::PERMISSION_CREATE, // hidden file list + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files ]) ) { throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index cb553947de6..84a3d18942f 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -43,6 +43,13 @@ '' + ' {{/if}}' + ' {{/if}}' + + ' {{#if publicEditing}}' + + '
' + + ' ' + + ' ' + + '' + + '
' + + ' {{/if}}' + ' {{#if showPasswordCheckBox}}' + '' + '' + @@ -87,6 +94,7 @@ 'click .linkCheckbox': 'onLinkCheckBoxChange', 'click .linkText': 'onLinkTextClick', 'change .publicUploadCheckbox': 'onAllowPublicUploadChange', + 'change .publicEditingCheckbox': 'onAllowPublicEditingChange', 'change .hideFileListCheckbox': 'onHideFileListChange', 'click .showPasswordCheckbox': 'onShowPasswordClick' }, @@ -128,7 +136,8 @@ 'onLinkTextClick', 'onShowPasswordClick', 'onHideFileListChange', - 'onAllowPublicUploadChange' + 'onAllowPublicUploadChange', + 'onAllowPublicEditingChange' ); var clipboard = new Clipboard('.clipboardButton'); @@ -266,6 +275,20 @@ }); }, + onAllowPublicEditingChange: function() { + var $checkbox = this.$('.publicEditingCheckbox'); + $checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock'); + + var permissions = OC.PERMISSION_READ; + if($checkbox.is(':checked')) { + permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_READ; + } + + this.model.saveLinkShare({ + permissions: permissions + }); + }, + onHideFileListChange: function () { var $checkbox = this.$('.hideFileListCheckbox'); $checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock'); @@ -307,6 +330,12 @@ publicUploadChecked = 'checked="checked"'; } + var publicEditingChecked = ''; + if(this.model.isPublicEditingAllowed()) { + publicEditingChecked = 'checked="checked"'; + } + + var hideFileList = publicUploadChecked; var hideFileListChecked = ''; @@ -320,6 +349,11 @@ && ( !this.configModel.get('enforcePasswordForPublicLink') || !this.model.get('linkShare').password); + var publicEditable = + !this.model.isFolder() + && isLinkShare + && this.model.updatePermissionPossible(); + this.$el.html(linkShareTemplate({ cid: this.cid, shareAllowed: true, @@ -337,6 +371,9 @@ publicUploadChecked: publicUploadChecked, hideFileListChecked: hideFileListChecked, publicUploadLabel: t('core', 'Allow upload and editing'), + publicEditing: publicEditable, + publicEditingChecked: publicEditingChecked, + publicEditingLabel: t('core', 'Allow editing'), hideFileListLabel: t('core', 'File drop (upload only)'), mailPrivatePlaceholder: t('core', 'Email link to person'), mailButtonText: t('core', 'Send') diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 9b10f067afc..ae4c07e3f4e 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -272,6 +272,10 @@ return this.get('allowPublicUploadStatus'); }, + isPublicEditingAllowed: function() { + return this.get('allowPublicEditingStatus'); + }, + /** * @returns {boolean} */ @@ -679,6 +683,17 @@ }); } + var allowPublicEditingStatus = true; + if(!_.isUndefined(data.shares)) { + $.each(data.shares, function (key, value) { + if (value.share_type === OC.Share.SHARE_TYPE_LINK) { + allowPublicEditingStatus = (value.permissions & OC.PERMISSION_UPDATE) ? true : false; + return true; + } + }); + } + + var hideFileListStatus = false; if(!_.isUndefined(data.shares)) { $.each(data.shares, function (key, value) { @@ -762,6 +777,7 @@ linkShare: linkShare, permissions: permissions, allowPublicUploadStatus: allowPublicUploadStatus, + allowPublicEditingStatus: allowPublicEditingStatus, hideFileListStatus: hideFileListStatus }; }, -- 2.39.5