diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-06-02 11:31:21 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-07-28 16:53:23 +0200 |
commit | a11c6e7cc3eec18cba62ebd32e0b8653d97ed929 (patch) | |
tree | bafafff8804d17ec7a0fa41f908bea6a761aa962 /apps/files_sharing/src/models/Share.js | |
parent | 92e60e38589f47bdd71114b2c54217ba6fdc7dd2 (diff) | |
download | nextcloud-server-a11c6e7cc3eec18cba62ebd32e0b8653d97ed929.tar.gz nextcloud-server-a11c6e7cc3eec18cba62ebd32e0b8653d97ed929.zip |
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 <vincent@nextcloud.com>
Diffstat (limited to 'apps/files_sharing/src/models/Share.js')
-rw-r--r-- | apps/files_sharing/src/models/Share.js | 60 |
1 files changed, 60 insertions, 0 deletions
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 } @@ -97,6 +105,17 @@ export default class Share { } /** + * 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 |