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