version_deletion.cy.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @copyright Copyright (c) 2024 Louis Chmn <louis@chmn.me>
  3. *
  4. * @author Louis Chmn <louis@chmn.me>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import type { User } from '@nextcloud/cypress'
  23. import { doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
  24. import { navigateToFolder, getRowForFile } from '../files/FilesUtils'
  25. describe('Versions restoration', () => {
  26. const folderName = 'shared_folder'
  27. const randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
  28. const randomFilePath = `/${folderName}/${randomFileName}`
  29. let user: User
  30. let versionCount = 0
  31. before(() => {
  32. cy.createRandomUser()
  33. .then((_user) => {
  34. user = _user
  35. cy.mkdir(user, `/${folderName}`)
  36. uploadThreeVersions(user, randomFilePath)
  37. uploadThreeVersions(user, randomFilePath)
  38. versionCount = 6
  39. cy.login(user)
  40. cy.visit('/apps/files')
  41. navigateToFolder(folderName)
  42. openVersionsPanel(randomFilePath)
  43. })
  44. })
  45. it('Delete initial version', () => {
  46. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  47. deleteVersion(2)
  48. versionCount--
  49. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  50. })
  51. context('Delete versions of shared file', () => {
  52. it('Works with delete permission', () => {
  53. setupTestSharedFileFromUser(user, folderName, { delete: true })
  54. navigateToFolder(folderName)
  55. openVersionsPanel(randomFilePath)
  56. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  57. deleteVersion(2)
  58. versionCount--
  59. cy.get('[data-files-versions-version]').should('have.length', versionCount)
  60. })
  61. it('Does not work without delete permission', () => {
  62. setupTestSharedFileFromUser(user, folderName, { delete: false })
  63. navigateToFolder(folderName)
  64. openVersionsPanel(randomFilePath)
  65. doesNotHaveAction(0, 'delete')
  66. doesNotHaveAction(1, 'delete')
  67. doesNotHaveAction(2, 'delete')
  68. })
  69. it('Does not work without delete permission through direct API access', () => {
  70. let hostname: string
  71. let fileId: string|undefined
  72. let versionId: string|undefined
  73. setupTestSharedFileFromUser(user, folderName, { delete: false })
  74. .then(recipient => {
  75. navigateToFolder(folderName)
  76. openVersionsPanel(randomFilePath)
  77. cy.url().then(url => { hostname = new URL(url).hostname })
  78. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  79. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  80. cy.then(() => {
  81. cy.logout()
  82. cy.request({
  83. method: 'DELETE',
  84. auth: { user: recipient.userId, pass: recipient.password },
  85. headers: {
  86. cookie: '',
  87. },
  88. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  89. failOnStatusCode: false,
  90. })
  91. .then(({ status }) => {
  92. expect(status).to.equal(403)
  93. })
  94. })
  95. })
  96. })
  97. })
  98. })