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

Commit

Permalink
Introduce new _getOptionalParams helper method for shares
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 2, 2022
1 parent 9b0b5a5 commit 1391a4c
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions src/shareManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,15 @@ 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
}
const formattedParams = this._getOptionalParams(optionalParams)
postData = { ...postData, formattedParams }
}

return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData)
Expand All @@ -134,7 +121,7 @@ class Shares {
* @returns {Promise.<error>} 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
Expand All @@ -145,17 +132,8 @@ 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
}
const formattedParams = this._getOptionalParams(optionalParams)
postData = { ...postData, formattedParams }
}

return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData)
Expand All @@ -178,24 +156,15 @@ 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
}
const formattedParams = this._getOptionalParams(optionalParams)
postData = { ...postData, formattedParams }
}

return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData)
Expand Down Expand Up @@ -473,6 +442,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

0 comments on commit 1391a4c

Please sign in to comment.