From a11c6e7cc3eec18cba62ebd32e0b8653d97ed929 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 2 Jun 2022 11:31:21 +0200 Subject: Add share attrs + download permission support in frontend Added download permission checkbox in frontend Added share attributes parsing and setting in frontend. Signed-off-by: Vincent Petry --- apps/files/src/services/FileInfo.js | 1 + apps/files_sharing/src/components/SharingEntry.vue | 42 ++++++++++++++- apps/files_sharing/src/mixins/SharesMixin.js | 8 ++- apps/files_sharing/src/models/Share.js | 60 ++++++++++++++++++++++ apps/files_sharing/src/share.js | 5 ++ core/src/files/client.js | 17 ++++++ core/src/files/fileinfo.js | 16 ++++++ 7 files changed, 147 insertions(+), 2 deletions(-) diff --git a/apps/files/src/services/FileInfo.js b/apps/files/src/services/FileInfo.js index 8b62063e134..c09af45f495 100644 --- a/apps/files/src/services/FileInfo.js +++ b/apps/files/src/services/FileInfo.js @@ -47,6 +47,7 @@ export default async function(url) { + diff --git a/apps/files_sharing/src/components/SharingEntry.vue b/apps/files_sharing/src/components/SharingEntry.vue index 25baf536f2f..e4754b86f4f 100644 --- a/apps/files_sharing/src/components/SharingEntry.vue +++ b/apps/files_sharing/src/components/SharingEntry.vue @@ -78,6 +78,12 @@ {{ t('files_sharing', 'Allow resharing') }} + + {{ t('files_sharing', 'Allow download') }} + + (properties[p] = this.share[p].toString())) + propertyNames.forEach(name => { + if ((typeof this.share[name]) === 'object') { + properties[name] = JSON.stringify(this.share[name]) + } else { + properties[name] = this.share[name].toString() + } + }) this.updateQueue.add(async () => { this.saving = true diff --git a/apps/files_sharing/src/models/Share.js b/apps/files_sharing/src/models/Share.js index 5644ce0c2b3..0e96987c005 100644 --- a/apps/files_sharing/src/models/Share.js +++ b/apps/files_sharing/src/models/Share.js @@ -43,6 +43,14 @@ export default class Share { ocsData.hide_download = !!ocsData.hide_download ocsData.mail_send = !!ocsData.mail_send + if (ocsData.attributes) { + try { + ocsData.attributes = JSON.parse(ocsData.attributes) + } catch (e) { + console.warn('Could not parse share attributes returned by server: "' + ocsData.attributes + '"') + } + } + // store state this._share = ocsData } @@ -96,6 +104,17 @@ export default class Share { return this._share.permissions } + /** + * Get the share attributes + * + * @return {Array} + * @readonly + * @memberof Share + */ + get attributes() { + return this._share.attributes + } + /** * Set the share permissions * See OC.PERMISSION_* variables @@ -527,6 +546,47 @@ export default class Share { return !!((this.permissions & OC.PERMISSION_SHARE)) } + /** + * Does this share have download permissions + * + * @return {boolean} + * @readonly + * @memberof Share + */ + get hasDownloadPermission() { + for (const i in this._share.attributes) { + const attr = this._share.attributes[i] + if (attr.scope === 'permissions' && attr.key === 'download') { + return attr.enabled + } + } + + return true + } + + set hasDownloadPermission(enabled) { + this.setAttribute('permissions', 'download', !!enabled) + } + + setAttribute(scope, key, enabled) { + const attrUpdate = { + scope, + key, + enabled, + } + + // try and replace existing + for (const i in this._share.attributes) { + const attr = this._share.attributes[i] + if (attr.scope === attrUpdate.scope && attr.key === attrUpdate.key) { + this._share.attributes[i] = attrUpdate + return + } + } + + this._share.attributes.push(attrUpdate) + } + // PERMISSIONS Shortcuts for the CURRENT USER // ! the permissions above are the share settings, // ! meaning the permissions for the recipient diff --git a/apps/files_sharing/src/share.js b/apps/files_sharing/src/share.js index c533e7b8109..76c007b5218 100644 --- a/apps/files_sharing/src/share.js +++ b/apps/files_sharing/src/share.js @@ -92,7 +92,11 @@ import { getCapabilities } from '@nextcloud/capabilities' delete fileActions.actions.all.Details delete fileActions.actions.all.Goto } + if (_.isFunction(fileData.canDownload) && !fileData.canDownload()) { + delete fileActions.actions.all.Download + } tr.attr('data-share-permissions', sharePermissions) + tr.attr('data-share-attributes', JSON.stringify(fileData.shareAttributes)) if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner) tr.attr('data-share-owner-id', fileData.shareOwnerId) @@ -113,6 +117,7 @@ import { getCapabilities } from '@nextcloud/capabilities' var oldElementToFile = fileList.elementToFile fileList.elementToFile = function($el) { var fileInfo = oldElementToFile.apply(this, arguments) + fileInfo.shareAttributes = JSON.parse($el.attr('data-share-attributes') || '[]') fileInfo.sharePermissions = $el.attr('data-share-permissions') || undefined fileInfo.shareOwner = $el.attr('data-share-owner') || undefined fileInfo.shareOwnerId = $el.attr('data-share-owner-id') || undefined diff --git a/core/src/files/client.js b/core/src/files/client.js index 630e9fb98ad..2c71fbe46e1 100644 --- a/core/src/files/client.js +++ b/core/src/files/client.js @@ -104,6 +104,7 @@ import escapeHTML from 'escape-html' Client.PROPERTY_GETCONTENTLENGTH = '{' + Client.NS_DAV + '}getcontentlength' Client.PROPERTY_ISENCRYPTED = '{' + Client.NS_DAV + '}is-encrypted' Client.PROPERTY_SHARE_PERMISSIONS = '{' + Client.NS_OCS + '}share-permissions' + Client.PROPERTY_SHARE_ATTRIBUTES = '{' + Client.NS_NEXTCLOUD + '}share-attributes' Client.PROPERTY_QUOTA_AVAILABLE_BYTES = '{' + Client.NS_DAV + '}quota-available-bytes' Client.PROTOCOL_HTTP = 'http' @@ -160,6 +161,10 @@ import escapeHTML from 'escape-html' * Share permissions */ [Client.NS_OCS, 'share-permissions'], + /** + * Share attributes + */ + [Client.NS_NEXTCLOUD, 'share-attributes'], ] /** @@ -416,6 +421,18 @@ import escapeHTML from 'escape-html' data.sharePermissions = parseInt(sharePermissionsProp) } + const shareAttributesProp = props[Client.PROPERTY_SHARE_ATTRIBUTES] + if (!_.isUndefined(shareAttributesProp)) { + try { + data.shareAttributes = JSON.parse(shareAttributesProp) + } catch (e) { + console.warn('Could not parse share attributes returned by server: "' + shareAttributesProp + '"') + data.shareAttributes = []; + } + } else { + data.shareAttributes = []; + } + const mounTypeProp = props['{' + Client.NS_NEXTCLOUD + '}mount-type'] if (!_.isUndefined(mounTypeProp)) { data.mountType = mounTypeProp diff --git a/core/src/files/fileinfo.js b/core/src/files/fileinfo.js index ea49e8c1447..3fe90f82ac9 100644 --- a/core/src/files/fileinfo.js +++ b/core/src/files/fileinfo.js @@ -155,7 +155,23 @@ */ sharePermissions: null, + /** + * @type Array + */ + shareAttributes: [], + quotaAvailableBytes: -1, + + canDownload: function() { + for (const i in this.shareAttributes) { + const attr = this.shareAttributes[i] + if (attr.scope === 'permissions' && attr.key === 'download') { + return attr.enabled + } + } + + return true + }, } if (!OC.Files) { -- cgit v1.2.3