From bfffd559e8faad30ad4002410215b4012e5351a7 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 18 Feb 2022 10:25:15 +0100 Subject: [PATCH 1/5] Adjust share management to properly work with spaces --- src/helperFunctions.js | 1 + src/shareManagement.js | 57 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/helperFunctions.js b/src/helperFunctions.js index 7c5790613..7ff68bf6b 100644 --- a/src/helperFunctions.js +++ b/src/helperFunctions.js @@ -29,6 +29,7 @@ class helpers { this.OCS_SHARE_TYPE_GROUP = 1 this.OCS_SHARE_TYPE_LINK = 3 this.OCS_SHARE_TYPE_REMOTE = 6 + this.OCS_SHARE_TYPE_SPACE = 7 this.instance = null this._authHeader = null diff --git a/src/shareManagement.js b/src/shareManagement.js index 99e664bbe..c11d3520b 100644 --- a/src/shareManagement.js +++ b/src/shareManagement.js @@ -13,6 +13,7 @@ const ShareInfo = require('./shareInfo.js') *
  • shareFileWithLink
  • *
  • updateShare
  • *
  • shareFileWithUser
  • + *
  • shareSpaceWithUser
  • *
  • shareFileWithGroup
  • *
  • getShares
  • *
  • isShared
  • @@ -123,6 +124,49 @@ class Shares { }) } + /** + * Shares a space with specified user + * @param {string} path path to the remote file share + * @param {string} username name of the user to share with + * @param {string} spaceId id of the space + * @param {object} optionalParams {permissions: integer, expirationDate: ISO Date, remoteUser: boolean, attributes: assoc array (at free disposal)} + * @returns {Promise.} instance of class ShareInfo + * @returns {Promise.} string: error message, if any. + */ + shareSpaceWithUser (path, username, spaceId, optionalParams) { + const postData = { + shareType: this.helpers.OCS_SHARE_TYPE_SPACE, + shareWith: username, + space_ref: spaceId + } + + if (path) { + postData.path = this.helpers._normalizePath(path) + } + + if (optionalParams) { + if (optionalParams.permissions) { + postData.permissions = optionalParams.permissions + } + + if (optionalParams.expirationDate) { + postData.expireDate = optionalParams.expirationDate + } + + if (optionalParams.attributes) { + postData.attributes = optionalParams.attributes + } + } + + return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData) + .then(data => { + const shareData = data.data.ocs.data + const share = new ShareInfo(shareData) + + return Promise.resolve(share) + }) + } + /** * Shares a remote file with specified group * @param {string} path path to the remote file share @@ -371,14 +415,23 @@ class Shares { /** * Deletes a share * @param {number} shareId ID of the share to delete + * @param {object} urlParams {shareWith: string} * @returns {Promise.} boolean: true if successful * @returns {Promise.} string: error message, if any. */ - deleteShare (shareId) { + deleteShare (shareId, urlParams) { + let urlParamString = '' + if (urlParams) { + urlParamString = '?' + if (urlParams.shareWith) { + urlParamString += `shareWith=${urlParams.shareWith}` + } + } + return new Promise((resolve, reject) => { /* jshint unused: false */ this.helpers._makeOCSrequest('DELETE', this.helpers.OCS_SERVICE_SHARE, - 'shares/' + encodeURIComponent(shareId.toString()) + 'shares/' + encodeURIComponent(shareId.toString()) + urlParamString ).then(() => { resolve(true) }).catch(error => { From 9f6f7e23045afcadeb642bb01605428af72de4d9 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 18 Feb 2022 10:27:53 +0100 Subject: [PATCH 2/5] Add changelog item --- changelog/unreleased/change-share-spaces | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/change-share-spaces diff --git a/changelog/unreleased/change-share-spaces b/changelog/unreleased/change-share-spaces new file mode 100644 index 000000000..3cab10077 --- /dev/null +++ b/changelog/unreleased/change-share-spaces @@ -0,0 +1,5 @@ +Change: Adjust share management to properly work with spaces + +This includes a new method `shareSpaceWithUser` as well as the possibility to pass URL params to the `deleteShare` method. + +https://github.com/owncloud/owncloud-sdk/pull/1013 From 9b0b5a58dbba99d51b421d6077352c3e4dafbdda Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Tue, 1 Mar 2022 14:19:55 +0100 Subject: [PATCH 3/5] Fix changelog type --- .../{change-share-spaces => enhancement-share-spaces} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename changelog/unreleased/{change-share-spaces => enhancement-share-spaces} (72%) diff --git a/changelog/unreleased/change-share-spaces b/changelog/unreleased/enhancement-share-spaces similarity index 72% rename from changelog/unreleased/change-share-spaces rename to changelog/unreleased/enhancement-share-spaces index 3cab10077..63f16ab77 100644 --- a/changelog/unreleased/change-share-spaces +++ b/changelog/unreleased/enhancement-share-spaces @@ -1,4 +1,4 @@ -Change: Adjust share management to properly work with spaces +Enhancement: Adjust share management to properly work with spaces This includes a new method `shareSpaceWithUser` as well as the possibility to pass URL params to the `deleteShare` method. From c2162d11cb6dbab0d7d6ba8e07c0985536f4f971 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 2 Mar 2022 13:41:27 +0100 Subject: [PATCH 4/5] Introduce new _getOptionalParams helper method for shares --- src/shareManagement.js | 71 ++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/src/shareManagement.js b/src/shareManagement.js index c11d3520b..0a1f4c97b 100644 --- a/src/shareManagement.js +++ b/src/shareManagement.js @@ -91,28 +91,14 @@ class Shares { shareFileWithUser (path, username, optionalParams) { path = this.helpers._normalizePath(path) - const postData = { + let postData = { shareType: this.helpers.OCS_SHARE_TYPE_USER, shareWith: username, path: path } if (optionalParams) { - if (optionalParams.permissions) { - postData.permissions = optionalParams.permissions - } - - if (optionalParams.expirationDate) { - postData.expireDate = optionalParams.expirationDate - } - - if (optionalParams.attributes) { - postData.attributes = optionalParams.attributes - } - - if (optionalParams.remoteUser) { - postData.shareType = this.helpers.OCS_SHARE_TYPE_REMOTE - } + postData = { ...postData, ...this._getOptionalParams(optionalParams) } } return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData) @@ -134,7 +120,7 @@ class Shares { * @returns {Promise.} string: error message, if any. */ shareSpaceWithUser (path, username, spaceId, optionalParams) { - const postData = { + let postData = { shareType: this.helpers.OCS_SHARE_TYPE_SPACE, shareWith: username, space_ref: spaceId @@ -145,17 +131,7 @@ class Shares { } if (optionalParams) { - if (optionalParams.permissions) { - postData.permissions = optionalParams.permissions - } - - if (optionalParams.expirationDate) { - postData.expireDate = optionalParams.expirationDate - } - - if (optionalParams.attributes) { - postData.attributes = optionalParams.attributes - } + postData = { ...postData, ...this._getOptionalParams(optionalParams) } } return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData) @@ -178,24 +154,14 @@ class Shares { shareFileWithGroup (path, groupName, optionalParams) { path = this.helpers._normalizePath(path) - const postData = { + let postData = { shareType: this.helpers.OCS_SHARE_TYPE_GROUP, shareWith: groupName, path: path } if (optionalParams) { - if (optionalParams.permissions) { - postData.permissions = optionalParams.permissions - } - - if (optionalParams.expirationDate) { - postData.expireDate = optionalParams.expirationDate - } - - if (optionalParams.attributes) { - postData.attributes = optionalParams.attributes - } + postData = { ...postData, ...this._getOptionalParams(optionalParams) } } return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData) @@ -473,6 +439,31 @@ class Shares { return json.ocs.data }) } + + /** + * @param {object} optionalParams + * @returns {object} + */ + _getOptionalParams (optionalParams) { + const data = {} + if (optionalParams.permissions) { + data.permissions = optionalParams.permissions + } + + if (optionalParams.expirationDate) { + data.expireDate = optionalParams.expirationDate + } + + if (optionalParams.attributes) { + data.attributes = optionalParams.attributes + } + + if (optionalParams.remoteUser) { + data.shareType = this.helpers.OCS_SHARE_TYPE_REMOTE + } + + return data + } } module.exports = Shares From 8d60abdd44c9c07469f2f2b94e60fe8e8cfc2975 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Thu, 3 Mar 2022 10:14:26 +0100 Subject: [PATCH 5/5] Bump version to 2.1.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83996a830..e080ddfde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "owncloud-sdk", - "version": "2.0.1", + "version": "2.1.0-alpha.1", "description": "ownCloud client library for JavaScript", "keywords": [ "owncloud",