version_naming.cy.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { nameVersion, openVersionsPanel, uploadThreeVersions, doesNotHaveAction, setupTestSharedFileFromUser } from './filesVersionsUtils'
  7. import { getRowForFile } from '../files/FilesUtils'
  8. describe('Versions naming', () => {
  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('Names the versions', () => {
  23. nameVersion(2, 'v1')
  24. cy.get('#tab-version_vue').within(() => {
  25. cy.get('[data-files-versions-version]').eq(2).contains('v1')
  26. cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
  27. })
  28. nameVersion(1, 'v2')
  29. cy.get('#tab-version_vue').within(() => {
  30. cy.get('[data-files-versions-version]').eq(1).contains('v2')
  31. })
  32. nameVersion(0, 'v3')
  33. cy.get('#tab-version_vue').within(() => {
  34. cy.get('[data-files-versions-version]').eq(0).contains('v3 (Current version)')
  35. })
  36. })
  37. context('Name versions of shared file', () => {
  38. context('with edit permission', () => {
  39. before(() => {
  40. setupTestSharedFileFromUser(user, randomFileName, { update: true })
  41. openVersionsPanel(randomFileName)
  42. })
  43. it('Names the versions', () => {
  44. nameVersion(2, 'v1 - shared')
  45. cy.get('#tab-version_vue').within(() => {
  46. cy.get('[data-files-versions-version]').eq(2).contains('v1 - shared')
  47. cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
  48. })
  49. nameVersion(1, 'v2 - shared')
  50. cy.get('#tab-version_vue').within(() => {
  51. cy.get('[data-files-versions-version]').eq(1).contains('v2 - shared')
  52. })
  53. nameVersion(0, 'v3 - shared')
  54. cy.get('#tab-version_vue').within(() => {
  55. cy.get('[data-files-versions-version]').eq(0).contains('v3 - shared (Current version)')
  56. })
  57. })
  58. })
  59. context('without edit permission', () => {
  60. it('Does not show action', () => {
  61. setupTestSharedFileFromUser(user, randomFileName, { update: false })
  62. openVersionsPanel(randomFileName)
  63. cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
  64. cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="label"]').should('not.exist')
  65. doesNotHaveAction(1, 'label')
  66. doesNotHaveAction(2, 'label')
  67. })
  68. it('Does not work without update permission through direct API access', () => {
  69. let hostname: string
  70. let fileId: string|undefined
  71. let versionId: string|undefined
  72. setupTestSharedFileFromUser(user, randomFileName, { update: false })
  73. .then(recipient => {
  74. openVersionsPanel(randomFileName)
  75. cy.url().then(url => { hostname = new URL(url).hostname })
  76. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  77. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  78. cy.then(() => {
  79. cy.logout()
  80. cy.request({
  81. method: 'PROPPATCH',
  82. auth: { user: recipient.userId, pass: recipient.password },
  83. headers: {
  84. cookie: '',
  85. },
  86. body: `<?xml version="1.0"?>
  87. <d:propertyupdate xmlns:d="DAV:"
  88. xmlns:oc="http://owncloud.org/ns"
  89. xmlns:nc="http://nextcloud.org/ns"
  90. xmlns:ocs="http://open-collaboration-services.org/ns">
  91. <d:set>
  92. <d:prop>
  93. <nc:version-label>not authorized labeling</nc:version-label>
  94. </d:prop>
  95. </d:set>
  96. </d:propertyupdate>`,
  97. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  98. failOnStatusCode: false,
  99. })
  100. .then(({ status }) => {
  101. expect(status).to.equal(403)
  102. })
  103. })
  104. })
  105. })
  106. })
  107. })
  108. })