Skip to content

Commit

Permalink
Merge pull request #3224 from nextcloud/backport/3213/stable30
Browse files Browse the repository at this point in the history
[stable30] fix: Do not expire labeled versions
  • Loading branch information
artonge authored Sep 15, 2024
2 parents a454490 + 9528ed3 commit ccbb0c0
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 159 deletions.
13 changes: 13 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export default defineConfig({
}
})

// This allows to store global data (e.g. the name of a snapshot)
// because Cypress.env() and other options are local to the current spec file.
const data = {}
on('task', {
setVariable({ key, value }) {
data[key] = value
return null
},
getVariable({ key }) {
return data[key] ?? null
},
})

// Before the browser launches
// starting Nextcloud testing container
const ip = await startNextcloud(process.env.BRANCH)
Expand Down
51 changes: 50 additions & 1 deletion cypress/e2e/files_versions/filesVersionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,56 @@
*/
/* eslint-disable jsdoc/require-jsdoc */
import type { User } from '@nextcloud/cypress'
import path from 'path'
import { addUserToGroup, createGroup, createGroupFolder, PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'

type SetupInfo = {
dataSnapshot: string
dbSnapshot: string
groupName: string
groupFolderName: string
fileName: string
filePath: string
user: User
}

export function setupFilesVersions(): Cypress.Chainable<SetupInfo> {
return cy.task('getVariable', { key: 'files-versions-data' })
.then((_setupInfo) => {
const setupInfo = _setupInfo as SetupInfo || {}

if (setupInfo.dataSnapshot && setupInfo.dbSnapshot) {
cy.restoreDB(setupInfo.dbSnapshot)
cy.restoreData(setupInfo.dataSnapshot)
} else {
setupInfo.groupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
setupInfo.groupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
setupInfo.fileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
setupInfo.filePath = `${setupInfo.groupFolderName}/${setupInfo.fileName}`

cy.createRandomUser().then(_user => { setupInfo.user = _user })
createGroup(setupInfo.groupName)

cy.then(() => {
addUserToGroup(setupInfo.groupName, setupInfo.user.userId)
createGroupFolder(setupInfo.groupFolderName, setupInfo.groupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(setupInfo.user, setupInfo.filePath)
})
.then(() => cy.backupDB().then((value) => { setupInfo.dbSnapshot = value }))
.then(() => cy.backupData([setupInfo.user.userId]).then((value) => { setupInfo.dataSnapshot = value }))
.then(() => cy.task('setVariable', { key: 'files-versions-data', value: setupInfo }))
}

return cy.then(() => {
cy.login(setupInfo.user)
cy.visit('/apps/files')
navigateToFolder(setupInfo.groupFolderName)
openVersionsPanel(setupInfo.filePath)
return cy.wrap(setupInfo)
})
})
}

export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'
import { setupFilesVersions } from './filesVersionsUtils'

describe('Versions creation', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Opens the versions panel and sees the versions', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_deletion.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { openVersionsPanel, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { deleteVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions restoration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Delete initial version', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_download.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { assertVersionContent, setupFilesVersions } from './filesVersionsUtils'

describe('Versions download', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Download versions and assert their content', () => {
Expand Down
52 changes: 52 additions & 0 deletions cypress/e2e/files_versions/version_expiration.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { closeSidebar } from '../files/filesUtils'
import { assertVersionContent, nameVersion, openVersionsPanel, setupFilesVersions } from './filesVersionsUtils'

describe('Versions expiration', () => {
let randomFilePath: string

beforeEach(() => {
setupFilesVersions()
.then(({ filePath }) => {
randomFilePath = filePath
})
})

it('Expire all versions', () => {
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
cy.runOccCommand('groupfolders:expire')
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
closeSidebar()
openVersionsPanel(randomFilePath)

cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 1)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
})

assertVersionContent(0, 'v3')
})

it('Expire versions v2', () => {
nameVersion(2, 'v1')

cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
cy.runOccCommand('groupfolders:expire')
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
closeSidebar()
openVersionsPanel(randomFilePath)

cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 2)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
cy.get('[data-files-versions-version]').eq(1).contains('v1')
})

assertVersionContent(0, 'v3')
assertVersionContent(1, 'v1')
})
})
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_naming.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { nameVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions naming', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Names the versions', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_restoration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, doesNotHaveAction, openVersionsPanel, restoreVersion, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { assertVersionContent, doesNotHaveAction, restoreVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions restoration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
setupFilesVersions()
})

it('Current version does not have restore action', () => {
Expand All @@ -52,7 +24,7 @@ describe('Versions restoration', () => {
})
})

it('Downloads versions and assert there content', () => {
it('Downloads versions and assert their content', () => {
assertVersionContent(0, 'v1')
assertVersionContent(1, 'v3')
assertVersionContent(2, 'v2')
Expand Down
Loading

0 comments on commit ccbb0c0

Please sign in to comment.