Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Adjust share management to properly work with spaces #1013

Merged
merged 5 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/change-share-spaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Adjust share management to properly work with spaces
kulmann marked this conversation as resolved.
Show resolved Hide resolved

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
1 change: 1 addition & 0 deletions src/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 55 additions & 2 deletions src/shareManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ShareInfo = require('./shareInfo.js')
* <li>shareFileWithLink</li>
* <li>updateShare</li>
* <li>shareFileWithUser</li>
* <li>shareSpaceWithUser</li>
* <li>shareFileWithGroup</li>
* <li>getShares</li>
* <li>isShared</li>
Expand Down Expand Up @@ -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.<ShareInfo>} instance of class ShareInfo
* @returns {Promise.<error>} 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)
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
}

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
Expand Down Expand Up @@ -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.<status>} boolean: true if successful
* @returns {Promise.<error>} 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 => {
Expand Down