Skip to content

Commit 9f2b0f7

Browse files
Merge pull request nextcloud#50204 from nextcloud/backport/50192/stable30
[stable30] fix(files_sharing): Stop overwriting the share expiration date with the default expiration date
2 parents 692764e + 8cc90e4 commit 9f2b0f7

13 files changed

+157
-18
lines changed

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,7 @@ export default {
588588
},
589589
},
590590
mounted() {
591-
if (this.share) {
592-
this.defaultExpirationDateEnabled = this.config.defaultExpirationDate instanceof Date
593-
this.share.expireDate = this.defaultExpirationDateEnabled ? this.formatDateToString(this.config.defaultExpirationDate) : ''
594-
}
591+
this.defaultExpirationDateEnabled = this.config.defaultExpirationDate instanceof Date
595592
},
596593
597594
methods: {

apps/files_sharing/src/mixins/SharesMixin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
return this.config.isDefaultExpireDateEnforced
129129
}
130130
if (this.isRemoteShare) {
131-
return this.config.isDefaultRemoteExpireDateEnforced
131+
return this.config.isDefaultRemoteExpireDateEnforced
132132
}
133133
return this.config.isDefaultInternalExpireDateEnforced
134134
},
@@ -209,9 +209,10 @@ export default {
209209
*
210210
* @param {Date} date
211211
*/
212-
onExpirationChange: debounce(function(date) {
212+
onExpirationChange(date) {
213213
this.share.expireDate = this.formatDateToString(new Date(date))
214-
}, 500),
214+
},
215+
215216
/**
216217
* Uncheck expire date
217218
* We need this method because @update:checked

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
:value="new Date(share.expireDate ?? dateTomorrow)"
145145
:min="dateTomorrow"
146146
:max="maxExpirationDateEnforced"
147-
:hide-label="true"
147+
hide-label
148+
:label="t('files_sharing', 'Expiration date')"
148149
:placeholder="t('files_sharing', 'Expiration date')"
149150
type="date"
150151
@input="onExpirationChange" />

cypress/e2e/files_sharing/FilesSharingUtils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ShareSetting {
1212
share: boolean
1313
download: boolean
1414
note: string
15+
expiryDate: Date
1516
}
1617

1718
export function createShare(fileName: string, username: string, shareSettings: Partial<ShareSetting> = {}) {
@@ -31,15 +32,20 @@ export function createShare(fileName: string, username: string, shareSettings: P
3132
updateShare(fileName, 0, shareSettings)
3233
}
3334

35+
export function openSharingDetails(index: number) {
36+
cy.get('#app-sidebar-vue').within(() => {
37+
cy.get('[data-cy-files-sharing-share-actions]').eq(index).click()
38+
cy.get('[data-cy-files-sharing-share-permissions-bundle="custom"]').click()
39+
})
40+
}
41+
3442
export function updateShare(fileName: string, index: number, shareSettings: Partial<ShareSetting> = {}) {
3543
openSharingPanel(fileName)
44+
openSharingDetails(index)
3645

3746
cy.intercept({ times: 1, method: 'PUT', url: '**/apps/files_sharing/api/v1/shares/*' }).as('updateShare')
3847

3948
cy.get('#app-sidebar-vue').within(() => {
40-
cy.get('[data-cy-files-sharing-share-actions]').eq(index).click()
41-
cy.get('[data-cy-files-sharing-share-permissions-bundle="custom"]').click()
42-
4349
if (shareSettings.download !== undefined) {
4450
cy.get('[data-cy-files-sharing-share-permissions-checkbox="download"]').find('input').as('downloadCheckbox')
4551
if (shareSettings.download) {
@@ -89,10 +95,19 @@ export function updateShare(fileName: string, index: number, shareSettings: Part
8995
cy.findByRole('textbox', { name: /note to recipient/i }).type(shareSettings.note)
9096
}
9197

98+
if (shareSettings.expiryDate !== undefined) {
99+
cy.findByRole('checkbox', { name: /expiration date/i })
100+
.check({ force: true, scrollBehavior: 'nearest' })
101+
cy.get('#share-date-picker')
102+
.type(`${shareSettings.expiryDate.getFullYear()}-${String(shareSettings.expiryDate.getMonth() + 1).padStart(2, '0')}-${String(shareSettings.expiryDate.getDate()).padStart(2, '0')}`)
103+
}
104+
92105
cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' })
93106

94107
cy.wait('@updateShare')
95108
})
109+
// close all toasts
110+
cy.get('.toast-success').findAllByRole('button').click({ force: true, multiple: true })
96111
}
97112

98113
export function openSharingPanel(fileName: string) {
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { User } from '@nextcloud/cypress'
7+
import { randomBytes } from 'crypto'
8+
import { closeSidebar } from '../files/FilesUtils.ts'
9+
import { createShare, openSharingDetails, openSharingPanel, updateShare } from './FilesSharingUtils.ts'
10+
11+
describe('files_sharing: Expiry date', () => {
12+
const expectedDefaultDate = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000)
13+
const expectedDefaultDateString = `${expectedDefaultDate.getFullYear()}-${String(expectedDefaultDate.getMonth() + 1).padStart(2, '0')}-${String(expectedDefaultDate.getDate()).padStart(2, '0')}`
14+
const fortnight = new Date(Date.now() + 14 * 24 * 60 * 60 * 1000)
15+
const fortnightString = `${fortnight.getFullYear()}-${String(fortnight.getMonth() + 1).padStart(2, '0')}-${String(fortnight.getDate()).padStart(2, '0')}`
16+
17+
let alice: User
18+
let bob: User
19+
20+
before(() => {
21+
// Ensure we have the admin setting setup for default dates with 2 days in the future
22+
cy.runOccCommand('config:app:set --value yes core shareapi_default_internal_expire_date')
23+
cy.runOccCommand('config:app:set --value 2 core shareapi_internal_expire_after_n_days')
24+
25+
cy.createRandomUser().then((user) => {
26+
alice = user
27+
cy.login(alice)
28+
})
29+
cy.createRandomUser().then((user) => {
30+
bob = user
31+
})
32+
})
33+
34+
after(() => {
35+
cy.runOccCommand('config:app:delete core shareapi_default_internal_expire_date')
36+
cy.runOccCommand('config:app:delete core shareapi_enforce_internal_expire_date')
37+
cy.runOccCommand('config:app:delete core shareapi_internal_expire_after_n_days')
38+
})
39+
40+
beforeEach(() => {
41+
cy.runOccCommand('config:app:delete core shareapi_enforce_internal_expire_date')
42+
})
43+
44+
it('See default expiry date is set and enforced', () => {
45+
// Enforce the date
46+
cy.runOccCommand('config:app:set --value yes core shareapi_enforce_internal_expire_date')
47+
const dir = prepareDirectory()
48+
49+
validateExpiryDate(dir, expectedDefaultDateString)
50+
cy.findByRole('checkbox', { name: /expiration date/i })
51+
.should('be.checked')
52+
.and('be.disabled')
53+
})
54+
55+
it('See default expiry date is set also if not enforced', () => {
56+
const dir = prepareDirectory()
57+
58+
validateExpiryDate(dir, expectedDefaultDateString)
59+
cy.findByRole('checkbox', { name: /expiration date/i })
60+
.should('be.checked')
61+
.and('not.be.disabled')
62+
.check({ force: true, scrollBehavior: 'nearest' })
63+
})
64+
65+
it('Can set custom expiry date', () => {
66+
const dir = prepareDirectory()
67+
updateShare(dir, 0, { expiryDate: fortnight })
68+
validateExpiryDate(dir, fortnightString)
69+
})
70+
71+
it('Custom expiry date survives reload', () => {
72+
const dir = prepareDirectory()
73+
updateShare(dir, 0, { expiryDate: fortnight })
74+
validateExpiryDate(dir, fortnightString)
75+
76+
cy.visit('/apps/files')
77+
validateExpiryDate(dir, fortnightString)
78+
})
79+
80+
/**
81+
* Regression test for https://github.com/nextcloud/server/pull/50192
82+
* Ensure that admin default settings do not always override the user set value.
83+
*/
84+
it('Custom expiry date survives unrelated update', () => {
85+
const dir = prepareDirectory()
86+
updateShare(dir, 0, { expiryDate: fortnight })
87+
validateExpiryDate(dir, fortnightString)
88+
89+
closeSidebar()
90+
updateShare(dir, 0, { note: 'Only note changed' })
91+
validateExpiryDate(dir, fortnightString)
92+
93+
cy.visit('/apps/files')
94+
validateExpiryDate(dir, fortnightString)
95+
})
96+
97+
/**
98+
* Prepare directory, login and share to bob
99+
*/
100+
function prepareDirectory(): string {
101+
const name = randomBytes(4)
102+
.toString('hex')
103+
cy.mkdir(alice, `/${name}`)
104+
cy.login(alice)
105+
cy.visit('/apps/files')
106+
createShare(name, bob.userId)
107+
return name
108+
}
109+
110+
/**
111+
* Validate expiry date on a share
112+
*
113+
* @param filename The filename to validate
114+
* @param expectedDate The expected date in YYYY-MM-dd
115+
*/
116+
function validateExpiryDate(filename: string, expectedDate: string) {
117+
openSharingPanel(filename)
118+
openSharingDetails(0)
119+
120+
cy.get('#share-date-picker')
121+
.should('exist')
122+
.and('have.value', expectedDate)
123+
}
124+
125+
})

dist/7692-7692.js renamed to dist/7170-7170.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/7170-7170.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/7170-7170.js.map.license

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7170-7170.js.license

dist/7692-7692.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)