1
0

filesSharingUtils.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. /* eslint-disable jsdoc/require-jsdoc */
  6. import { triggerActionForFile } from '../files/FilesUtils'
  7. export interface ShareSetting {
  8. read: boolean
  9. update: boolean
  10. delete: boolean
  11. share: boolean
  12. download: boolean
  13. }
  14. export function createShare(fileName: string, username: string, shareSettings: Partial<ShareSetting> = {}) {
  15. openSharingPanel(fileName)
  16. cy.get('#app-sidebar-vue').within(() => {
  17. cy.get('#sharing-search-input').clear()
  18. cy.intercept({ times: 1, method: 'GET', url: '**/apps/files_sharing/api/v1/sharees?*' }).as('userSearch')
  19. cy.get('#sharing-search-input').type(username)
  20. cy.wait('@userSearch')
  21. })
  22. cy.get(`[user="${username}"]`).click()
  23. // HACK: Save the share and then update it, as permissions changes are currently not saved for new share.
  24. cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' })
  25. updateShare(fileName, 0, shareSettings)
  26. }
  27. export function updateShare(fileName: string, index: number, shareSettings: Partial<ShareSetting> = {}) {
  28. openSharingPanel(fileName)
  29. cy.get('#app-sidebar-vue').within(() => {
  30. cy.get('[data-cy-files-sharing-share-actions]').eq(index).click()
  31. cy.get('[data-cy-files-sharing-share-permissions-bundle="custom"]').click()
  32. if (shareSettings.download !== undefined) {
  33. cy.get('[data-cy-files-sharing-share-permissions-checkbox="download"]').find('input').as('downloadCheckbox')
  34. if (shareSettings.download) {
  35. // Force:true because the checkbox is hidden by the pretty UI.
  36. cy.get('@downloadCheckbox').check({ force: true, scrollBehavior: 'nearest' })
  37. } else {
  38. // Force:true because the checkbox is hidden by the pretty UI.
  39. cy.get('@downloadCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
  40. }
  41. }
  42. if (shareSettings.read !== undefined) {
  43. cy.get('[data-cy-files-sharing-share-permissions-checkbox="read"]').find('input').as('readCheckbox')
  44. if (shareSettings.read) {
  45. // Force:true because the checkbox is hidden by the pretty UI.
  46. cy.get('@readCheckbox').check({ force: true, scrollBehavior: 'nearest' })
  47. } else {
  48. // Force:true because the checkbox is hidden by the pretty UI.
  49. cy.get('@readCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
  50. }
  51. }
  52. if (shareSettings.update !== undefined) {
  53. cy.get('[data-cy-files-sharing-share-permissions-checkbox="update"]').find('input').as('updateCheckbox')
  54. if (shareSettings.update) {
  55. // Force:true because the checkbox is hidden by the pretty UI.
  56. cy.get('@updateCheckbox').check({ force: true, scrollBehavior: 'nearest' })
  57. } else {
  58. // Force:true because the checkbox is hidden by the pretty UI.
  59. cy.get('@updateCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
  60. }
  61. }
  62. if (shareSettings.delete !== undefined) {
  63. cy.get('[data-cy-files-sharing-share-permissions-checkbox="delete"]').find('input').as('deleteCheckbox')
  64. if (shareSettings.delete) {
  65. // Force:true because the checkbox is hidden by the pretty UI.
  66. cy.get('@deleteCheckbox').check({ force: true, scrollBehavior: 'nearest' })
  67. } else {
  68. // Force:true because the checkbox is hidden by the pretty UI.
  69. cy.get('@deleteCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
  70. }
  71. }
  72. cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' })
  73. })
  74. }
  75. export function openSharingPanel(fileName: string) {
  76. triggerActionForFile(fileName, 'details')
  77. cy.get('#app-sidebar-vue')
  78. .get('[aria-controls="tab-sharing"]')
  79. .click()
  80. }