Skip to content

Commit

Permalink
Renaming and adding new options for public link
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sharidas committed Mar 7, 2019
1 parent 75e9d6f commit 1127ef3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
24 changes: 21 additions & 3 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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
},
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/lib/Controllers/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/templates/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<input type="hidden" name="mimetypeIcon" value="<?php p(\OC::$server->getMimeTypeDetector()->mimeTypeIcon($_['mimetype'])); ?>" id="mimetypeIcon">
<input type="hidden" name="filesize" value="<?php p($_['nonHumanFileSize']); ?>" id="filesize">
<input type="hidden" name="maxSizeAnimateGif" value="<?php p($_['maxSizeAnimateGif']); ?>" id="maxSizeAnimateGif">
<input type="hidden" name="sharePermission" value="<?php p($_['sharePermission']); ?>" id="sharePermission">

<header>
<div id="header" class="<?php p((isset($_['folder']) ? 'share-folder' : 'share-file')) ?>" data-protected="<?php p($_['protected']) ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public function testShowShare() {
'shareUrl' => null,
'previewImage' => null,
'canDownload' => true,
'sharePermission' => true
];

$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
Expand Down
18 changes: 14 additions & 4 deletions core/js/sharedialoglinkshareview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
'<label class="bold" for="sharingDialogAllowPublicRead-{{cid}}">{{publicReadLabel}}</label>' +
'<p><em>{{publicReadDescription}}</em></p>' +
'</div>' +
'{{#if publicUploadPossible}}' +
'<div id="allowPublicReadWrite-{{cid}}" class="public-link-modal--item">' +
'<div id="allowPublicRead-{{cid}}" class="public-link-modal--item">' +
'<input type="radio" value="{{publicReadWriteValue}}" name="publicPermissions" id="sharingDialogAllowPublicReadWrite-{{cid}}" class="checkbox publicPermissions" {{#if publicReadWriteSelected}}checked{{/if}} />' +
'<label class="bold" for="sharingDialogAllowPublicReadWrite-{{cid}}">{{publicReadWriteLabel}}</label>' +
'<p><em>{{publicReadWriteDescription}}</em></p>' +
'</div>' +
'{{#if publicUploadPossible}}' +
'<div id="allowpublicUploadWrite-{{cid}}" class="public-link-modal--item">' +
'<input type="radio" value="{{publicUploadWriteValue}}" name="publicPermissions" id="sharingDialogAllowpublicUploadWrite-{{cid}}" class="checkbox publicPermissions" {{#if publicUploadWriteSelected}}checked{{/if}} />' +
'<label class="bold" for="sharingDialogAllowpublicUploadWrite-{{cid}}">{{publicUploadWriteLabel}}</label>' +
'<p><em>{{publicUploadWriteDescription}}</em></p>' +
'</div>' +
'<div id="allowPublicUploadWrapper-{{cid}}" class="public-link-modal--item">' +
'<input type="radio" value="{{publicUploadValue}}" name="publicPermissions" id="sharingDialogAllowPublicUpload-{{cid}}" class="checkbox publicPermissions" {{#if publicUploadSelected}}checked{{/if}} />' +
'<label class="bold" for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' +
Expand Down Expand Up @@ -258,8 +263,13 @@
publicReadValue : OC.PERMISSION_READ,
publicReadSelected : this.model.get('permissions') === OC.PERMISSION_READ,

publicReadWriteLabel : t('core', 'Download / View / Upload'),
publicReadWriteDescription : t('core', 'Recipients can view, download, edit, delete and upload contents.'),
publicUploadWriteLabel : t('core', 'Download / View / Upload'),
publicUploadWriteDescription : t('core', 'Recipients can view, download and upload contents.'),
publicUploadWriteValue : OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE,
publicUploadWriteSelected : this.model.get('permissions') === (OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE),

publicReadWriteLabel : t('core', 'Download / View / Edit'),
publicReadWriteDescription : t('core', 'Recipients can view, download and edit contents.'),
publicReadWriteValue : OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_DELETE,
publicReadWriteSelected : this.model.get('permissions') >= (OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_DELETE),

Expand Down
2 changes: 1 addition & 1 deletion core/js/tests/specs/sharedialoglinkshareviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('OC.Share.ShareDialogLinkShareView', function() {
permissions: OC.PERMISSION_READ | OC.PERMISSION_CREATE
});
view.render();
expect(view.$('.publicPermissions').length).toEqual(3);
expect(view.$('.publicPermissions').length).toEqual(4);
});
it('renders checkbox disabled when public upload is disallowed by user', function() {
publicUploadConfigStub.returns(true);
Expand Down

0 comments on commit 1127ef3

Please sign in to comment.