diff options
Diffstat (limited to 'apps/files_sharing/src/models/Share.js')
-rw-r--r-- | apps/files_sharing/src/models/Share.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/files_sharing/src/models/Share.js b/apps/files_sharing/src/models/Share.js index 5644ce0c2b3..e6512c67f8c 100644 --- a/apps/files_sharing/src/models/Share.js +++ b/apps/files_sharing/src/models/Share.js @@ -43,6 +43,15 @@ 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 + '"') + } + } + ocsData.attributes = ocsData.attributes ?? [] + // store state this._share = ocsData } @@ -97,6 +106,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 +547,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 |