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

Add the space_ref param for link- and user-shares #1027

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changelog/unreleased/enhancement-share-spaces
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ This includes the following changes:

https://github.com/owncloud/owncloud-sdk/pull/1013
https://github.com/owncloud/owncloud-sdk/pull/1025
https://github.com/owncloud/owncloud-sdk/pull/1027
61 changes: 35 additions & 26 deletions src/shareManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Shares {
}

if (optionalParams) {
if (optionalParams.spaceRef) {
postData.space_ref = optionalParams.spaceRef
delete postData.path
}

if (optionalParams.permissions) {
postData.permissions = optionalParams.permissions
}
Expand Down Expand Up @@ -90,7 +95,6 @@ class Shares {
*/
shareFileWithUser (path, username, optionalParams) {
path = this.helpers._normalizePath(path)
const urlParams = new URLSearchParams()

let postData = {
shareType: this.helpers.OCS_SHARE_TYPE_USER,
Expand All @@ -100,16 +104,14 @@ class Shares {

if (optionalParams) {
if (optionalParams.spaceRef) {
urlParams.append('space_ref', optionalParams.spaceRef)
postData.space_ref = optionalParams.spaceRef
delete postData.path
}

postData = { ...postData, ...this._getOptionalParams(optionalParams) }
}

const urlPath = urlParams.toString() ? `shares?${urlParams.toString()}` : 'shares'

return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, urlPath, postData)
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)
Expand Down Expand Up @@ -169,6 +171,11 @@ class Shares {
}

if (optionalParams) {
if (optionalParams.spaceRef) {
postData.space_ref = optionalParams.spaceRef
delete postData.path
}

postData = { ...postData, ...this._getOptionalParams(optionalParams) }
}

Expand All @@ -194,35 +201,37 @@ class Shares {
const send = {}

if (path !== '') {
data += '?'

send.path = this.helpers._normalizePath(path)
optionalParams = this.helpers._convertObjectToBool(optionalParams)
}

if (optionalParams) {
if (optionalParams.spaceRef) {
send.space_ref = optionalParams.spaceRef
delete send.path
}
optionalParams = this.helpers._convertObjectToBool(optionalParams)

if (optionalParams.reshares && typeof (optionalParams.reshares) === 'boolean') {
send.reshares = optionalParams.reshares
}
if (optionalParams) {
if (optionalParams.spaceRef) {
send.space_ref = optionalParams.spaceRef
delete send.path
}

if (optionalParams.subfiles && typeof (optionalParams.subfiles) === 'boolean') {
send.subfiles = optionalParams.subfiles
}
if (optionalParams.reshares && typeof (optionalParams.reshares) === 'boolean') {
send.reshares = optionalParams.reshares
}

/* jshint camelcase: false */
if (optionalParams.shared_with_me && typeof (optionalParams.shared_with_me) === 'boolean') {
send.shared_with_me = optionalParams.shared_with_me
if (optionalParams.state) {
send.state = optionalParams.state
}
if (optionalParams.subfiles && typeof (optionalParams.subfiles) === 'boolean') {
send.subfiles = optionalParams.subfiles
}

/* jshint camelcase: false */
if (optionalParams.shared_with_me && typeof (optionalParams.shared_with_me) === 'boolean') {
send.shared_with_me = optionalParams.shared_with_me
if (optionalParams.state) {
send.state = optionalParams.state
}
/* jshint camelcase: true */
}
/* jshint camelcase: true */
}

if (Object.keys(send).length) {
data += '?'
let urlString = ''
for (const key in send) {
urlString += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(send[key])
Expand Down