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

Respect optional quicklink param for shareFileWithLink #1042

Merged
merged 3 commits into from
May 2, 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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"env": {
"browser": true,
"es6": true,
"jasmine": true
"jasmine": true,
"jest": true
},
"extends": [
"standard"
Expand Down
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-quicklink
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Create quicklink

We've added the option to define if a share link is of type quicklink or not.

https://github.com/owncloud/owncloud-sdk/pull/1041
https://github.com/owncloud/web/issues/6605
https://github.com/owncloud/core/pull/39167
https://github.com/cs3org/reva/pull/2715
17 changes: 9 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
*/

module.exports = {
coverageDirectory: "coverage",
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [
"node_modules/",
"vendor/",
"tests/"
'node_modules/',
'vendor/',
'tests/'
],
globalSetup: "<rootDir>/jest.setup.js",
"setupFiles": [
"<rootDir>/jest.init.js"
globalSetup: '<rootDir>/jest.setup.js',
setupFiles: [
'<rootDir>/jest.init.js'
],
testEnvironment: 'node',
testMatch: [
'**/tests/*.spec.js',
'**/tests/*Test.js',
'**/tests/**/*Test.js'
]
};
}
17 changes: 16 additions & 1 deletion src/shareManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,23 @@ class Shares {
path: path
}

const reflectClassicAttribute = (key, scope, value, exclusive = true) => {
const attributes = [...postData.attributes || []]
const current = attributes.findIndex(v => v.scope === scope && v.key === key)

if (current !== -1 && exclusive) {
attributes.splice(current, 1)
}

attributes.push({ key, scope, value })
postData.attributes = attributes
}

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

if (optionalParams.permissions) {
postData.permissions = optionalParams.permissions
}
Expand All @@ -74,6 +85,10 @@ class Shares {
if (optionalParams.attributes) {
postData.attributes = optionalParams.attributes
}
if (optionalParams.quicklink) {
postData.quicklink = optionalParams.quicklink
fschade marked this conversation as resolved.
Show resolved Hide resolved
reflectClassicAttribute('isQuickLink', 'files_sharing', postData.quicklink)
}
}

return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_SHARE, 'shares', postData)
Expand Down
75 changes: 75 additions & 0 deletions tests/shareManagement.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Shares from '../src/shareManagement.js'

jest.mock('../src/xmlParser', () => ({
xml2js: (data) => ({ ocs: data })
}))

describe('shareManagement', () => {
describe('shareFileWithLink', () => {
it('creates a quicklink which is ocis and oc10 compliant', async () => {
const mr = jest.fn(async function () {
return { body: arguments[3] }
})
const shares = new Shares({ _makeOCSrequest: mr, _normalizePath: jest.fn(p => p) })

await shares.shareFileWithLink('/any', { quicklink: true })
expect(mr.mock.calls[0][3].quicklink).toBe(true)
expect(mr.mock.calls[0][3].attributes.length).toBe(1)
expect(mr.mock.calls[0][3].attributes[0].key).toBe('isQuickLink')
expect(mr.mock.calls[0][3].attributes[0].scope).toBe('files_sharing')
expect(mr.mock.calls[0][3].attributes[0].value).toBe(true)

await shares.shareFileWithLink('/any', { quicklink: false })
expect(mr.mock.calls[1][3].quicklink).toBeUndefined()
expect(mr.mock.calls[1][3].attributes).toBeUndefined()

await shares.shareFileWithLink('/any', {
quicklink: true,
attributes: [{ key: 'isQuickLink', scope: 'files_sharing', value: true }]
})
expect(mr.mock.calls[2][3].quicklink).toBe(true)
expect(mr.mock.calls[2][3].attributes.length).toBe(1)
expect(mr.mock.calls[2][3].attributes[0].key).toBe('isQuickLink')
expect(mr.mock.calls[2][3].attributes[0].scope).toBe('files_sharing')
expect(mr.mock.calls[2][3].attributes[0].value).toBe(true)

await shares.shareFileWithLink('/any', {
quicklink: true,
attributes: [{ key: 'other', scope: 'files_sharing', value: true }]
})
expect(mr.mock.calls[3][3].quicklink).toBe(true)
expect(mr.mock.calls[3][3].attributes.length).toBe(2)
expect(mr.mock.calls[3][3].attributes[0].key).toBe('other')
expect(mr.mock.calls[3][3].attributes[1].key).toBe('isQuickLink')
expect(mr.mock.calls[3][3].attributes[1].scope).toBe('files_sharing')
expect(mr.mock.calls[3][3].attributes[1].value).toBe(true)

await shares.shareFileWithLink('/any', {
quicklink: true,
attributes: [
{ key: 'key_1', scope: 'scope_1', value: true },
{ key: 'key_2', scope: 'scope_2', value: true },
{ key: 'key_3', scope: 'scope_3', value: true },
{ key: 'key_4', scope: 'scope_4', value: true },
{ key: 'key_5', scope: 'scope_5', value: true }
]
})
expect(mr.mock.calls[4][3].attributes.length).toBe(6)

await shares.shareFileWithLink('/any', {
quicklink: true,
attributes: [
{ key: 'key_1', scope: 'scope_1', value: true },
{ key: 'key_2', scope: 'scope_2', value: true },
{ key: 'key_3', scope: 'scope_3', value: true },
{ key: 'isQuickLink', scope: 'files_sharing', value: false },
{ key: 'key_5', scope: 'scope_5', value: true }
]
})
expect(mr.mock.calls[5][3].attributes.length).toBe(5)
expect(mr.mock.calls[5][3].attributes[4].key).toBe('isQuickLink')
expect(mr.mock.calls[5][3].attributes[4].scope).toBe('files_sharing')
expect(mr.mock.calls[5][3].attributes[4].value).toBe(true)
})
})
})