-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathTransferOwnership.vue
More file actions
223 lines (208 loc) Β· 4.94 KB
/
TransferOwnership.vue
File metadata and controls
223 lines (208 loc) Β· 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!--
- SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<NcButton
class="transfer-button"
alignment="start"
variant="tertiary"
wide
:disabled="locked || !isOwner"
@click="openModal">
<span class="transfer-button__text">{{
t('forms', 'Transfer ownership')
}}</span>
</NcButton>
<NcDialog
:open.sync="showModal"
content-classes="modal-content"
:name="t('forms', 'Transfer ownership')"
out-transition
@close="closeModal">
<template #default>
<!-- eslint-disable vue/no-v-html -->
<p
v-html="
t(
'forms',
'You\'re going to transfer the ownership of {name} to another account. Please select the account to which you want to transfer ownership.',
{
name: `<strong>${escapedString(form.title)}</strong>`,
},
undefined,
{ escape: false },
)
" />
<!-- eslint-enable vue/no-v-html -->
<NcSelectUsers
v-model="selected"
class="modal-content__select"
:loading="loading"
:options="options"
:placeholder="t('forms', 'Search for a user')"
@search="
(query) => asyncSearch(query, [SHARE_TYPES.SHARE_TYPE_USER])
">
<template #no-options>
{{ noResultText }}
</template>
</NcSelectUsers>
<br />
<!-- eslint-disable vue/no-v-html -->
<p
v-html="
t(
'forms',
'Type {text} to confirm.',
{
text: `<strong>${escapedString(confirmationString)}</strong>`,
},
undefined,
{ escape: false },
)
" />
<!-- eslint-enable vue/no-v-html -->
<NcTextField
:label="t('forms', 'Confirmation text')"
:value.sync="confirmationInput"
:success="confirmationInput === confirmationString" />
<br />
<p>
<strong>{{ t('forms', 'This can not be undone.') }}</strong>
</p>
</template>
<template #actions>
<NcButton
:disabled="!canTransfer"
variant="error"
@click="onOwnershipTransfer">
{{ t('forms', 'I understand, transfer this form') }}
</NcButton>
</template>
</NcDialog>
</div>
</template>
<script>
import { showSuccess, showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcDialog from '@nextcloud/vue/components/NcDialog'
import NcTextField from '@nextcloud/vue/components/NcTextField'
import NcSelectUsers from '@nextcloud/vue/components/NcSelectUsers'
import UserSearchMixin from '../../mixins/UserSearchMixin.js'
import logger from '../../utils/Logger.js'
export default {
components: {
NcButton,
NcDialog,
NcTextField,
NcSelectUsers,
},
mixins: [UserSearchMixin],
props: {
form: {
type: Object,
required: true,
},
isOwner: {
type: Boolean,
required: true,
},
locked: {
type: Boolean,
required: true,
},
},
data() {
return {
selected: null,
showModal: false,
confirmationInput: '',
loading: false,
}
},
computed: {
canTransfer() {
return (
this.confirmationInput === this.confirmationString && !!this.selected
)
},
confirmationString() {
return `${this.form.ownerId}/${this.form.title.replace(/\s/g, ' ').trim()}`
},
options() {
if (this.isValidQuery) {
// Suggestions without existing shares
return this.suggestions
}
// Recommendations without existing shares
return this.recommendations
},
},
methods: {
clearText() {
this.confirmationInput = ''
},
closeModal() {
this.showModal = false
},
escapedString(textToEscape) {
return '' + textToEscape.replace('<', '<').replace('>', '>')
},
openModal() {
this.showModal = true
},
async onOwnershipTransfer() {
this.showModal = false
if (this.form.id && this.selected.shareWith) {
try {
emit('forms:last-updated:set', this.form.id)
await axios.patch(
generateOcsUrl('apps/forms/api/v3/forms/{id}', {
id: this.form.id,
}),
{
keyValuePairs: {
ownerId: this.selected.shareWith,
},
},
)
showSuccess(
`${t('forms', 'This form is now owned by')} ${this.selected.displayName}`,
)
emit('forms:ownership-transfered', this.form.id)
} catch (error) {
logger.error('Error while transfering form ownership', {
error,
})
showError(
t('forms', 'An error occurred while transfering ownership'),
)
}
} else {
logger.error('Null parameters while transfering form ownership', {
selectedUser: this.selected,
})
showError(
t('forms', 'An error occurred while transfering ownership'),
)
}
},
},
}
</script>
<style lang="scss" scoped>
:deep(.modal-content) {
padding-inline: 18px;
display: flex;
flex-direction: column;
gap: 8px;
}
.transfer-button__text {
color: var(--color-error-text);
}
</style>