From 5a004e47f7575af6fa795cab7290c90ba1356df2 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 9 Jun 2026 11:33:26 +0200 Subject: [PATCH] fix(files_sharing): Use share id in file actions Signed-off-by: provokateurin --- .../src/files_actions/acceptShareAction.spec.ts | 15 ++++++++++----- .../src/files_actions/acceptShareAction.ts | 2 +- .../src/files_actions/rejectShareAction.spec.ts | 15 ++++++++++----- .../src/files_actions/rejectShareAction.ts | 2 +- .../src/files_actions/restoreShareAction.spec.ts | 12 ++++++++---- .../src/files_actions/restoreShareAction.ts | 2 +- apps/files_sharing/src/services/SharingService.ts | 2 ++ 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/apps/files_sharing/src/files_actions/acceptShareAction.spec.ts b/apps/files_sharing/src/files_actions/acceptShareAction.spec.ts index 9598db7f5436e..3956df517e9b9 100644 --- a/apps/files_sharing/src/files_actions/acceptShareAction.spec.ts +++ b/apps/files_sharing/src/files_actions/acceptShareAction.spec.ts @@ -151,6 +151,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -164,7 +165,7 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/1') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) @@ -183,6 +184,7 @@ describe('Accept share action execute tests', () => { attributes: { remote: 3, share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -196,7 +198,7 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/1') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) @@ -214,6 +216,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -226,6 +229,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '2', }, root: '/files/admin', }) @@ -239,8 +243,8 @@ describe('Accept share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.post).toBeCalledTimes(2) - expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') - expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/456') + expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/1') + expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/2') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -260,6 +264,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -273,7 +278,7 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(false) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/1') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/files_actions/acceptShareAction.ts b/apps/files_sharing/src/files_actions/acceptShareAction.ts index a9ddb18a9be45..0368dec4bd6f3 100644 --- a/apps/files_sharing/src/files_actions/acceptShareAction.ts +++ b/apps/files_sharing/src/files_actions/acceptShareAction.ts @@ -25,7 +25,7 @@ export const action: IFileAction = { const isRemote = !!node.attributes.remote const url = generateOcsUrl('apps/files_sharing/api/v1/{shareBase}/pending/{id}', { shareBase: isRemote ? 'remote_shares' : 'shares', - id: node.id, + id: node.attributes['share-id'], }) await axios.post(url) diff --git a/apps/files_sharing/src/files_actions/rejectShareAction.spec.ts b/apps/files_sharing/src/files_actions/rejectShareAction.spec.ts index 638b088ee13fa..b3a3577d0577d 100644 --- a/apps/files_sharing/src/files_actions/rejectShareAction.spec.ts +++ b/apps/files_sharing/src/files_actions/rejectShareAction.spec.ts @@ -195,6 +195,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -208,7 +209,7 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(true) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/1') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) @@ -227,6 +228,7 @@ describe('Reject share action execute tests', () => { attributes: { remote: 3, share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -240,7 +242,7 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(true) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/1') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) @@ -258,6 +260,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -270,6 +273,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '2', }, root: '/files/admin', }) @@ -283,8 +287,8 @@ describe('Reject share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.delete).toBeCalledTimes(2) - expect(axios.delete).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') - expect(axios.delete).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/456') + expect(axios.delete).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/1') + expect(axios.delete).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/2') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -304,6 +308,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -317,7 +322,7 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(false) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/1') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/files_actions/rejectShareAction.ts b/apps/files_sharing/src/files_actions/rejectShareAction.ts index 62cfb55948289..5458e12baafee 100644 --- a/apps/files_sharing/src/files_actions/rejectShareAction.ts +++ b/apps/files_sharing/src/files_actions/rejectShareAction.ts @@ -42,7 +42,7 @@ export const action: IFileAction = { const node = nodes[0] const isRemote = !!node.attributes.remote const shareBase = isRemote ? 'remote_shares' : 'shares' - const id = node.id + const id = node.attributes['share-id'] let url: string if (node.attributes.accepted === 0) { url = generateOcsUrl('apps/files_sharing/api/v1/{shareBase}/pending/{id}', { diff --git a/apps/files_sharing/src/files_actions/restoreShareAction.spec.ts b/apps/files_sharing/src/files_actions/restoreShareAction.spec.ts index 959eeb0ac2805..0a3b5149ef3b6 100644 --- a/apps/files_sharing/src/files_actions/restoreShareAction.spec.ts +++ b/apps/files_sharing/src/files_actions/restoreShareAction.spec.ts @@ -152,6 +152,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -165,7 +166,7 @@ describe('Restore share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/1') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) @@ -183,6 +184,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -195,6 +197,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '2', }, root: '/files/admin', }) @@ -208,8 +211,8 @@ describe('Restore share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.post).toBeCalledTimes(2) - expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') - expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/456') + expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/1') + expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/2') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -228,6 +231,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { share_type: ShareType.User, + 'share-id': '1', }, root: '/files/admin', }) @@ -241,7 +245,7 @@ describe('Restore share action execute tests', () => { expect(exec).toBe(false) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/1') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/files_actions/restoreShareAction.ts b/apps/files_sharing/src/files_actions/restoreShareAction.ts index 2edb65e27a4b0..10ff034c21ec8 100644 --- a/apps/files_sharing/src/files_actions/restoreShareAction.ts +++ b/apps/files_sharing/src/files_actions/restoreShareAction.ts @@ -24,7 +24,7 @@ export const action: IFileAction = { try { const node = nodes[0] const url = generateOcsUrl('apps/files_sharing/api/v1/deletedshares/{id}', { - id: node.id, + id: node.attributes['share-id'], }) await axios.post(url) diff --git a/apps/files_sharing/src/services/SharingService.ts b/apps/files_sharing/src/services/SharingService.ts index aaa2eab0e6c01..662d577d6a6ec 100644 --- a/apps/files_sharing/src/services/SharingService.ts +++ b/apps/files_sharing/src/services/SharingService.ts @@ -106,6 +106,8 @@ async function ocsEntryToNode(ocsEntry: any, unmounted = false): Promise