version_naming.cy.ts 4.8 KB

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