From 359477f9c8399859807739e01d35be082a154c64 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 21 Jan 2025 15:08:07 +0100 Subject: [PATCH] fix(files_sharing): Only clear permissions of pending federated shares Signed-off-by: provokateurin --- .../src/services/SharingService.spec.ts | 98 ++++++++++++++----- .../src/services/SharingService.ts | 9 +- 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/apps/files_sharing/src/services/SharingService.spec.ts b/apps/files_sharing/src/services/SharingService.spec.ts index 388b0a7cc26..6163f9310b9 100644 --- a/apps/files_sharing/src/services/SharingService.spec.ts +++ b/apps/files_sharing/src/services/SharingService.spec.ts @@ -278,7 +278,7 @@ describe('SharingService share to Node mapping', () => { tags: [window.OC.TAG_FAVORITE], } - const remoteFile = { + const remoteFileAccepted = { mimetype: 'text/markdown', mtime: 1688721600, permissions: 19, @@ -297,6 +297,25 @@ describe('SharingService share to Node mapping', () => { accepted: true, } + const remoteFilePending = { + mimetype: 'text/markdown', + mtime: 1688721600, + permissions: 19, + type: 'file', + file_id: 1234, + id: 4, + share_type: ShareType.User, + parent: null, + remote: 'http://exampe.com', + remote_id: '12345', + share_token: 'share-token', + name: '/test.md', + mountpoint: '/shares/test.md', + owner: 'owner-uid', + user: 'sharee-uid', + accepted: false, + } + test('File', async () => { jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ data: { @@ -356,33 +375,64 @@ describe('SharingService share to Node mapping', () => { expect(folder.attributes.favorite).toBe(1) }) - test('Remote file', async () => { - jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ - data: { - ocs: { - data: [remoteFile], + describe('Remote file', () => { + test('Accepted', async () => { + jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + data: { + ocs: { + data: [remoteFileAccepted], + }, }, - }, - })) + })) - const shares = await getContents(false, true, false, false) + const shares = await getContents(false, true, false, false) - expect(axios.get).toHaveBeenCalledTimes(1) - expect(shares.contents).toHaveLength(1) + expect(axios.get).toHaveBeenCalledTimes(1) + expect(shares.contents).toHaveLength(1) - const file = shares.contents[0] as File - expect(file).toBeInstanceOf(File) - expect(file.fileid).toBe(1234) - expect(file.source).toBe('http://localhost/remote.php/dav/files/test/shares/test.md') - expect(file.owner).toBe('owner-uid') - expect(file.mime).toBe('text/markdown') - expect(file.mtime?.getTime()).toBe(remoteFile.mtime * 1000) - // not available for remote shares - expect(file.size).toBe(undefined) - expect(file.permissions).toBe(0) - expect(file.root).toBe('/files/test') - expect(file.attributes).toBeInstanceOf(Object) - expect(file.attributes.favorite).toBe(0) + const file = shares.contents[0] as File + expect(file).toBeInstanceOf(File) + expect(file.fileid).toBe(1234) + expect(file.source).toBe('http://localhost/remote.php/dav/files/test/shares/test.md') + expect(file.owner).toBe('owner-uid') + expect(file.mime).toBe('text/markdown') + expect(file.mtime?.getTime()).toBe(remoteFileAccepted.mtime * 1000) + // not available for remote shares + expect(file.size).toBe(undefined) + expect(file.permissions).toBe(19) + expect(file.root).toBe('/files/test') + expect(file.attributes).toBeInstanceOf(Object) + expect(file.attributes.favorite).toBe(0) + }) + + test('Pending', async () => { + jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + data: { + ocs: { + data: [remoteFilePending], + }, + }, + })) + + const shares = await getContents(false, true, false, false) + + expect(axios.get).toHaveBeenCalledTimes(1) + expect(shares.contents).toHaveLength(1) + + const file = shares.contents[0] as File + expect(file).toBeInstanceOf(File) + expect(file.fileid).toBe(1234) + expect(file.source).toBe('http://localhost/remote.php/dav/files/test/shares/test.md') + expect(file.owner).toBe('owner-uid') + expect(file.mime).toBe('text/markdown') + expect(file.mtime?.getTime()).toBe(remoteFilePending.mtime * 1000) + // not available for remote shares + expect(file.size).toBe(undefined) + expect(file.permissions).toBe(0) + expect(file.root).toBe('/files/test') + expect(file.attributes).toBeInstanceOf(Object) + expect(file.attributes.favorite).toBe(0) + }) }) test('Empty', async () => { diff --git a/apps/files_sharing/src/services/SharingService.ts b/apps/files_sharing/src/services/SharingService.ts index e168f202fba..a2a2b88d282 100644 --- a/apps/files_sharing/src/services/SharingService.ts +++ b/apps/files_sharing/src/services/SharingService.ts @@ -37,9 +37,12 @@ const ocsEntryToNode = async function(ocsEntry: any): Promise