From 1127ef36287aba026862c582e217e000313fcdc1 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Tue, 5 Mar 2019 19:52:25 +0530 Subject: [PATCH] Renaming and adding new options for public link 1) Renaming View/Download/Upload to View/Download/Edit. 2) Adding new option View/Download/Upload. So if user wants to give provide all permissions, View/Download/Edit option could be opted. If the user wants to have an option where no edit and delete to be granted for link shared, the View/Download/Upload could be used. Signed-off-by: Sujith H --- apps/files/js/file-upload.js | 24 ++++++++++++++++--- .../lib/Controller/Share20OcsController.php | 2 ++ .../lib/Controllers/ShareController.php | 1 + apps/files_sharing/templates/public.php | 1 + .../tests/Controllers/ShareControllerTest.php | 1 + core/js/sharedialoglinkshareview.js | 18 ++++++++++---- .../specs/sharedialoglinkshareviewSpec.js | 2 +- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 2056097b3825..5a9b055cf13d 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -829,7 +829,11 @@ OC.Uploader.prototype = _.extend({ return true; } var fileInfo = fileList.findFile(file.name); - if (fileInfo) { + var sharePermission = $("#sharePermission").val(); + if (sharePermission !== undefined) { + sharePermission &= (OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_DELETE); + } + if (fileInfo && (sharePermission !== (OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE))) { conflicts.push([ // original _.extend(fileInfo, { @@ -839,13 +843,24 @@ OC.Uploader.prototype = _.extend({ upload ]); return false; + } else { + /** + * The public link with view-download-upload option. Here we would + * not overwrite the files. Instead create new file by autorenaming, + * if the file already exists. + * + */ + if (fileInfo) { + callbacks.onAutoRenameForPublicLink(upload); + } } return true; }); + if (conflicts.length) { // wait for template loading - OC.dialogs.fileexists(null, null, null, this).done(function() { - _.each(conflicts, function(conflictData) { + OC.dialogs.fileexists(null, null, null, this).done(function () { + _.each(conflicts, function (conflictData) { OC.dialogs.fileexists(conflictData[1], conflictData[0], conflictData[1].getFile(), this); }); }); @@ -1097,6 +1112,9 @@ OC.Uploader.prototype = _.extend({ onNoConflicts: function (selection) { self.submitUploads(selection.uploads); }, + onAutoRenameForPublicLink: function(upload) { + self.onAutorename(upload); + }, onSkipConflicts: function (selection) { //TODO mark conflicting files as toskip }, diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index 26a64db9f168..48df7756322c 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -449,6 +449,8 @@ public function createShare() { } elseif ($permissions === \OCP\Constants::PERMISSION_CREATE || $permissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)) { $share->setPermissions($permissions); + } elseif ($permissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE)) { + $share->setPermissions($permissions); } else { // because when "publicUpload" is passed usually no permissions are set, // which defaults to ALL. But in the case of link shares we default to READ... diff --git a/apps/files_sharing/lib/Controllers/ShareController.php b/apps/files_sharing/lib/Controllers/ShareController.php index 3d32b4a93b0d..0d29cca25417 100644 --- a/apps/files_sharing/lib/Controllers/ShareController.php +++ b/apps/files_sharing/lib/Controllers/ShareController.php @@ -364,6 +364,7 @@ public function showShare($token, $path = '') { } $shareTmpl['canDownload'] = !!($share->getPermissions() & \OCP\Constants::PERMISSION_READ > 0); + $shareTmpl['sharePermission'] = $share->getPermissions(); $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $token]); $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]); $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 04434aa7ab0d..f3d69b3483ea 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -50,6 +50,7 @@ +
' + - '{{#if publicUploadPossible}}' + - '