TransferOwnershipDialogue.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!--
  2. - @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. -
  4. - @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  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. <template>
  22. <div>
  23. <h3>{{ t('files', 'Transfer ownership') }} </h3>
  24. <p>
  25. {{ t('files', 'Here you can select a directory that is transferred to another user. It may take some time until the process is done.') }}
  26. </p>
  27. <form @submit.prevent="submit">
  28. <ol>
  29. <li>
  30. <div class="step-header">
  31. {{ t('files', 'Directory to move') }}
  32. </div>
  33. <span v-if="directory === undefined">{{ t('files', 'No directory selected') }}</span>
  34. <span v-else>{{ directory }}</span>
  35. <button class="primary" @click.prevent="start">
  36. {{ t('files', 'Select') }}
  37. </button>
  38. <span class="error">{{ directoryPickerError }}</span>
  39. </li>
  40. <li>
  41. <div class="step-header">
  42. {{ t('files', 'Target user') }}
  43. </div>
  44. <input id="files-transfer-user" v-model="uid" type="text">
  45. </li>
  46. <li>
  47. <input type="submit"
  48. class="primary"
  49. :value="t('files', 'Submit')"
  50. :disabled="!canSubmit">
  51. <span class="error">{{ submitError }}</span>
  52. </li>
  53. </ol>
  54. </form>
  55. </div>
  56. </template>
  57. <script>
  58. import axios from '@nextcloud/axios'
  59. import { generateOcsUrl } from '@nextcloud/router'
  60. import { getFilePickerBuilder } from '@nextcloud/dialogs'
  61. import logger from '../logger'
  62. const picker = getFilePickerBuilder(t('files', 'Select directory to transfer'))
  63. .setMultiSelect(false)
  64. .setModal(true)
  65. .setType(1)
  66. .allowDirectories()
  67. .build()
  68. export default {
  69. name: 'TransferOwnershipDialogue',
  70. data() {
  71. return {
  72. directory: undefined,
  73. directoryPickerError: undefined,
  74. submitError: undefined,
  75. uid: ''
  76. }
  77. },
  78. computed: {
  79. canSubmit() {
  80. return !!this.directory && !!this.uid
  81. }
  82. },
  83. methods: {
  84. start() {
  85. this.directoryPickerError = undefined
  86. picker.pick()
  87. .then(dir => dir === '' ? '/' : dir)
  88. .then(dir => {
  89. logger.debug(`path ${dir} selected for transfer ownership`)
  90. if (!dir.startsWith('/')) {
  91. throw new Error(t('files', 'Invalid path selected'))
  92. }
  93. // /ocs/v2.php/apps/files/api/v1/transferownership
  94. // /ocs/v2.php/apps/files/api/v1/transferownership
  95. this.directory = dir
  96. }).catch(error => {
  97. logger.error(`Selecting dir for transfer aborted: ${error.message || 'Unknown error'}`, { error })
  98. this.directoryPickerError = error.message || t('files', 'Unknown error')
  99. })
  100. },
  101. submit() {
  102. if (!this.canSubmit) {
  103. logger.warn('ignoring form submit')
  104. }
  105. this.submitError = undefined
  106. const data = {
  107. path: this.directory,
  108. recipient: this.uid
  109. }
  110. logger.debug('submit transfer ownership form', data)
  111. const url = generateOcsUrl('apps/files/api/v1/', 2) + 'transferownership'
  112. axios.post(url, data)
  113. .then(resp => resp.data)
  114. .then(data => {
  115. logger.info('Transfer ownership request sent', { data })
  116. this.directory = undefined
  117. this.recipient = undefined
  118. OCP.Toast.success(t('files', 'Ownership transfer request sent'))
  119. })
  120. .catch(error => {
  121. logger.error('Could not send ownership transfer request', { error })
  122. this.submitError = error.message || t('files', 'Unknown error')
  123. })
  124. }
  125. }
  126. }
  127. </script>
  128. <style scoped>
  129. </style>