version_deletion.cy.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import type { User } from '@nextcloud/cypress'
  6. import { doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
  7. import { navigateToFolder, getRowForFile } from '../files/FilesUtils'
  8. describe('Versions restoration', () => {
  9. const folderName = 'shared_folder'
  10. const randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
  11. const randomFilePath = `/${folderName}/${randomFileName}`
  12. let user: User
  13. let versionCount = 0
  14. before(() => {
  15. cy.createRandomUser()
  16. .then((_user) => {
  17. user = _user
  18. cy.mkdir(user, `/${folderName}`)
  19. uploadThreeVersions(user, randomFilePath)
  20. uploadThreeVersions(user, randomFilePath)
  21. versionCount = 6
  22. cy.login(user)
  23. cy.visit('/apps/files')
  24. navigateToFolder(folderName)
  25. openVersionsPanel(randomFilePath)
  26. })
  27. })
  28. it('Delete initial version', () => {
  29. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  30. deleteVersion(2)
  31. versionCount--
  32. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  33. })
  34. context('Delete versions of shared file', () => {
  35. it('Works with delete permission', () => {
  36. setupTestSharedFileFromUser(user, folderName, { delete: true })
  37. navigateToFolder(folderName)
  38. openVersionsPanel(randomFilePath)
  39. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  40. deleteVersion(2)
  41. versionCount--
  42. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  43. })
  44. it('Does not work without delete permission', () => {
  45. setupTestSharedFileFromUser(user, folderName, { delete: false })
  46. navigateToFolder(folderName)
  47. openVersionsPanel(randomFilePath)
  48. doesNotHaveAction(0, 'delete')
  49. doesNotHaveAction(1, 'delete')
  50. doesNotHaveAction(2, 'delete')
  51. })
  52. it('Does not work without delete permission through direct API access', () => {
  53. let hostname: string
  54. let fileId: string|undefined
  55. let versionId: string|undefined
  56. setupTestSharedFileFromUser(user, folderName, { delete: false })
  57. .then(recipient => {
  58. navigateToFolder(folderName)
  59. openVersionsPanel(randomFilePath)
  60. cy.url().then(url => { hostname = new URL(url).hostname })
  61. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  62. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  63. cy.then(() => {
  64. cy.logout()
  65. cy.request({
  66. method: 'DELETE',
  67. auth: { user: recipient.userId, pass: recipient.password },
  68. headers: {
  69. cookie: '',
  70. },
  71. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  72. failOnStatusCode: false,
  73. })
  74. .then(({ status }) => {
  75. expect(status).to.equal(403)
  76. })
  77. })
  78. })
  79. })
  80. })
  81. })