refactor share permission logic into own method to reuse it for the share tab

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2016-10-10 10:15:42 +02:00 committed by Roeland Jago Douma
parent bc1cb8a6d0
commit 9e5e120ef9
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
3 changed files with 27 additions and 14 deletions

View File

@ -36,19 +36,7 @@
var oldCreateRow = fileList._createRow; var oldCreateRow = fileList._createRow;
fileList._createRow = function(fileData) { fileList._createRow = function(fileData) {
var tr = oldCreateRow.apply(this, arguments); var tr = oldCreateRow.apply(this, arguments);
var sharePermissions = fileData.permissions; var sharePermissions = OCA.Sharing.Util.getSharePermissions(fileData);
if (fileData.mountType && fileData.mountType === "external-root"){
// for external storages we can't use the permissions of the mountpoint
// instead we show all permissions and only use the share permissions from the mountpoint to handle resharing
sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE);
}
if (fileData.type === 'file') {
// files can't be shared with delete permissions
sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE;
// create permissions don't mean anything for files
sharePermissions = sharePermissions & ~OC.PERMISSION_CREATE;
}
tr.attr('data-share-permissions', sharePermissions); tr.attr('data-share-permissions', sharePermissions);
if (fileData.shareOwner) { if (fileData.shareOwner) {
tr.attr('data-share-owner', fileData.shareOwner); tr.attr('data-share-owner', fileData.shareOwner);
@ -251,6 +239,27 @@
text += ', +' + (count - maxRecipients); text += ', +' + (count - maxRecipients);
} }
return text; return text;
},
/**
* @param {Array} fileData
* @returns {String}
*/
getSharePermissions: function(fileData) {
var sharePermissions = fileData.permissions;
if (fileData.mountType && fileData.mountType === "external-root"){
// for external storages we can't use the permissions of the mountpoint
// instead we show all permissions and only use the share permissions from the mountpoint to handle resharing
sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE);
}
if (fileData.type === 'file') {
// files can't be shared with delete permissions
sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE;
// create permissions don't mean anything for files
sharePermissions = sharePermissions & ~OC.PERMISSION_CREATE;
}
return sharePermissions;
} }
}; };
})(); })();

View File

@ -50,6 +50,10 @@
if (this.model) { if (this.model) {
this.$el.html(this.template()); this.$el.html(this.template());
if (_.isUndefined(this.model.get('sharePermissions'))) {
this.model.set('sharePermissions', OCA.Sharing.Util.getSharePermissions(this.model.attributes));
}
// TODO: the model should read these directly off the passed fileInfoModel // TODO: the model should read these directly off the passed fileInfoModel
var attributes = { var attributes = {
itemType: this.model.isDirectory() ? 'folder' : 'file', itemType: this.model.isDirectory() ? 'folder' : 'file',

View File

@ -54,7 +54,7 @@ module.exports = function(config) {
'apps/files_sharing/js/app.js', 'apps/files_sharing/js/app.js',
'apps/files_sharing/js/sharedfilelist.js', 'apps/files_sharing/js/sharedfilelist.js',
'apps/files_sharing/js/share.js', 'apps/files_sharing/js/share.js',
'apps/files_sharing/js/external.js', 'apps/files_sharing/js/sharebreadcrumbview.js',
'apps/files_sharing/js/public.js', 'apps/files_sharing/js/public.js',
'apps/files_sharing/js/sharetabview.js' 'apps/files_sharing/js/sharetabview.js'
], ],