version_restoration.cy.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import type { User } from '@nextcloud/cypress'
  6. import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, restoreVersion, uploadThreeVersions } from './filesVersionsUtils'
  7. import { getRowForFile } from '../files/FilesUtils'
  8. describe('Versions restoration', () => {
  9. let randomFileName = ''
  10. let user: User
  11. before(() => {
  12. randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
  13. cy.createRandomUser()
  14. .then((_user) => {
  15. user = _user
  16. uploadThreeVersions(user, randomFileName)
  17. cy.login(user)
  18. cy.visit('/apps/files')
  19. openVersionsPanel(randomFileName)
  20. })
  21. })
  22. it('Current version does not have restore action', () => {
  23. doesNotHaveAction(0, 'restore')
  24. })
  25. it('Restores initial version', () => {
  26. restoreVersion(2)
  27. cy.get('#tab-version_vue').within(() => {
  28. cy.get('[data-files-versions-version]').should('have.length', 3)
  29. cy.get('[data-files-versions-version]').eq(0).contains('Current version')
  30. cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
  31. })
  32. })
  33. it('Downloads versions and assert there content', () => {
  34. assertVersionContent(0, 'v1')
  35. assertVersionContent(1, 'v3')
  36. assertVersionContent(2, 'v2')
  37. })
  38. context('Restore versions of shared file', () => {
  39. it('Works with update permission', () => {
  40. setupTestSharedFileFromUser(user, randomFileName, { update: true })
  41. openVersionsPanel(randomFileName)
  42. it('Restores initial version', () => {
  43. restoreVersion(2)
  44. cy.get('#tab-version_vue').within(() => {
  45. cy.get('[data-files-versions-version]').should('have.length', 3)
  46. cy.get('[data-files-versions-version]').eq(0).contains('Current version')
  47. cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
  48. })
  49. })
  50. it('Downloads versions and assert there content', () => {
  51. assertVersionContent(0, 'v1')
  52. assertVersionContent(1, 'v3')
  53. assertVersionContent(2, 'v2')
  54. })
  55. })
  56. it('Does not show action without delete permission', () => {
  57. setupTestSharedFileFromUser(user, randomFileName, { update: false })
  58. openVersionsPanel(randomFileName)
  59. cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
  60. cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="restore"]').should('not.exist')
  61. doesNotHaveAction(1, 'restore')
  62. doesNotHaveAction(2, 'restore')
  63. })
  64. it('Does not work without update permission through direct API access', () => {
  65. let hostname: string
  66. let fileId: string|undefined
  67. let versionId: string|undefined
  68. setupTestSharedFileFromUser(user, randomFileName, { update: false })
  69. .then(recipient => {
  70. openVersionsPanel(randomFileName)
  71. cy.url().then(url => { hostname = new URL(url).hostname })
  72. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  73. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  74. cy.then(() => {
  75. cy.logout()
  76. cy.request({
  77. method: 'MOVE',
  78. auth: { user: recipient.userId, pass: recipient.password },
  79. headers: {
  80. cookie: '',
  81. Destination: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/restore/target`,
  82. },
  83. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  84. failOnStatusCode: false,
  85. })
  86. .then(({ status }) => {
  87. expect(status).to.equal(403)
  88. })
  89. })
  90. })
  91. })
  92. })
  93. })