Skip to content

Commit 68f67d5

Browse files
committed
fix: Reset share state when cancelling the edition
The SharingDetailsTab receives a share object and uses it as the model to be edited from the UI components. Therefore, when the edition is cancelled, the share object should be returned to its original state. Otherwise any UI using the share object would still show the modified state. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent 858d236 commit 68f67d5

5 files changed

Lines changed: 144 additions & 1 deletion

File tree

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ export default {
398398
creating: false,
399399
initialToken: this.share.token,
400400
loadingToken: false,
401+
initialPermissions: undefined,
402+
initialExpireDate: undefined,
403+
initialNote: undefined,
404+
initialLabel: undefined,
405+
initialHideDownload: undefined,
406+
initialSendPasswordByTalk: undefined,
407+
initialHasDownloadPermission: undefined,
401408
402409
externalShareActions: getSidebarActions(),
403410
// legacy
@@ -865,6 +872,14 @@ export default {
865872
},
866873
867874
beforeMount() {
875+
this.initialPermissions = this.share.permissions
876+
this.initialExpireDate = this.share.expireDate
877+
this.initialNote = this.share.note
878+
this.initialLabel = this.share.label
879+
this.initialHideDownload = this.share.hideDownload
880+
this.initialSendPasswordByTalk = this.share.sendPasswordByTalk
881+
this.initialHasDownloadPermission = this.share.hasDownloadPermission
882+
868883
this.initializePermissions()
869884
this.initializeAttributes()
870885
logger.debug('Share object received', { share: this.share })
@@ -929,6 +944,16 @@ export default {
929944
930945
cancel() {
931946
this.share.token = this.initialToken
947+
this.share.permissions = this.initialPermissions
948+
this.share.expireDate = this.initialExpireDate
949+
this.share.note = this.initialNote
950+
this.share.label = this.initialLabel
951+
this.share.hideDownload = this.initialHideDownload
952+
this.share.sendPasswordByTalk = this.initialSendPasswordByTalk
953+
this.share.hasDownloadPermission = this.initialHasDownloadPermission
954+
955+
this.$set(this.share, 'newPassword', undefined)
956+
932957
this.$emit('close-sharing-details')
933958
},
934959

build/eslint-baseline-legacy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"apps/files_sharing/src/views/SharingDetailsTab.vue": {
1818
"vue/no-mutating-props": {
19-
"count": 24
19+
"count": 31
2020
}
2121
},
2222
"apps/files_sharing/src/views/SharingLinkList.vue": {

tests/playwright/e2e/files_sharing/public-share/share-editor.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,53 @@ test.describe('files_sharing: Link share editor', () => {
5656
await sharingTab.openAdvancedSettings()
5757
await expect(sharingTab.checkbox('Hide download')).toBeChecked()
5858
})
59+
60+
test('cancelling the edition resets to the previous state', async ({ page, filesListPage, sharingTab }) => {
61+
await openSharingPanel(filesListPage, sharingTab, 'test')
62+
63+
await sharingTab.openLinkShareDetails()
64+
await sharingTab.openAdvancedSettings()
65+
await expect(sharingTab.labelInput()).toHaveValue('')
66+
await sharingTab.labelInput().fill('The label')
67+
await expect(sharingTab.checkbox('Set password')).not.toBeChecked()
68+
await sharingTab.setCheckbox('Set password', true)
69+
// A password is automatically generated and added to the input
70+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
71+
await sharingTab.setCheckbox('Set expiration date', true)
72+
// A default expiration date is automatically added to the input
73+
await expect(sharingTab.checkbox('Hide download')).not.toBeChecked()
74+
await sharingTab.setCheckbox('Hide download', true)
75+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
76+
await sharingTab.setCheckbox('Note to recipient', true)
77+
await sharingTab.noteInput().fill('The note')
78+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
79+
await sharingTab.setCheckbox('Custom permissions', true)
80+
await expect(sharingTab.checkbox('Edit')).not.toBeChecked()
81+
await sharingTab.setCheckbox('Edit', true)
82+
await sharingTab.cancel()
83+
84+
// Back to the original state when the editor is opened again …
85+
await sharingTab.openLinkShareDetails()
86+
await sharingTab.openAdvancedSettings()
87+
await expect(sharingTab.labelInput()).toHaveValue('')
88+
await expect(sharingTab.checkbox('Set password')).not.toBeChecked()
89+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
90+
await expect(sharingTab.checkbox('Hide download')).not.toBeChecked()
91+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
92+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
93+
94+
// … and after a reload, i.e. it was not stored
95+
await page.reload()
96+
await openSharingPanel(filesListPage, sharingTab, 'test')
97+
await sharingTab.openLinkShareDetails()
98+
await sharingTab.openAdvancedSettings()
99+
await expect(sharingTab.labelInput()).toHaveValue('')
100+
await expect(sharingTab.checkbox('Set password')).not.toBeChecked()
101+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
102+
await expect(sharingTab.checkbox('Hide download')).not.toBeChecked()
103+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
104+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
105+
})
59106
})
60107

61108
test.describe('files_sharing: Email share editor', () => {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { expect, test } from '../../support/fixtures/sharing-page.ts'
7+
import { mkdir } from '../../support/utils/dav.ts'
8+
import { createShare, openSharingPanel } from '../../support/utils/sharing.ts'
9+
10+
test.describe('files_sharing: User share editor', () => {
11+
test.beforeEach(async ({ page, user, recipient, filesListPage }) => {
12+
await mkdir(page.request, user, '/test')
13+
await createShare(page.request, '/test', recipient.userId)
14+
await filesListPage.open()
15+
})
16+
17+
test('cancelling the edition resets to the previous state', async ({ page, filesListPage, sharingTab }) => {
18+
await openSharingPanel(filesListPage, sharingTab, 'test')
19+
20+
await sharingTab.openShareDetails()
21+
await sharingTab.openAdvancedSettings()
22+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
23+
await sharingTab.setCheckbox('Set expiration date', true)
24+
// A default expiration date is automatically added to the input
25+
await expect(sharingTab.checkbox('Allow download and sync')).toBeChecked()
26+
await sharingTab.setCheckbox('Allow download and sync', false)
27+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
28+
await sharingTab.setCheckbox('Note to recipient', true)
29+
await sharingTab.noteInput().fill('The note')
30+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
31+
await sharingTab.setCheckbox('Custom permissions', true)
32+
await expect(sharingTab.checkbox('Edit')).toBeChecked()
33+
await sharingTab.setCheckbox('Edit', false)
34+
await sharingTab.cancel()
35+
36+
// Back to the original state when the editor is opened again …
37+
await sharingTab.openShareDetails()
38+
await sharingTab.openAdvancedSettings()
39+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
40+
await expect(sharingTab.checkbox('Allow download and sync')).toBeChecked()
41+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
42+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
43+
44+
// … and after a reload, i.e. it was not stored
45+
await page.reload()
46+
await openSharingPanel(filesListPage, sharingTab, 'test')
47+
await sharingTab.openShareDetails()
48+
await sharingTab.openAdvancedSettings()
49+
await expect(sharingTab.checkbox('Set expiration date')).not.toBeChecked()
50+
await expect(sharingTab.checkbox('Allow download and sync')).toBeChecked()
51+
await expect(sharingTab.checkbox('Note to recipient')).not.toBeChecked()
52+
await expect(sharingTab.checkbox('Custom permissions')).not.toBeChecked()
53+
})
54+
})

tests/playwright/support/sections/SharingTab.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,21 @@ export class SharingTab {
272272
const body = await (await saved).json() as { ocs: { data: { id: number, permissions: number, url?: string } } }
273273
return body.ocs.data
274274
}
275+
276+
/**
277+
* The editor's cancel button.
278+
*/
279+
private cancelButton(): Locator {
280+
return this.panel().getByRole('button', { name: 'Cancel' })
281+
}
282+
283+
/**
284+
* Leave the open editor without saving the changes.
285+
* Returns once the button is no longer visible and therefore the share list
286+
* is back.
287+
*/
288+
async cancel(): Promise<void> {
289+
await this.cancelButton().click()
290+
await expect(this.cancelButton()).toBeHidden()
291+
}
275292
}

0 commit comments

Comments
 (0)