-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathSharingTabSidebar.vue
More file actions
290 lines (279 loc) · 7.84 KB
/
SharingTabSidebar.vue
File metadata and controls
290 lines (279 loc) · 7.84 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<NcSelectUsers v-model="addAcl"
:options="formatedSharees"
:loading="isLoading"
@search="(search) => asyncFind(search)" />
<ul id="shareWithList"
class="shareWithList">
<li>
<NcAvatar :user="board.owner.uid" />
<span class="username">
{{ board.owner.displayname }}
<span v-if="!isCurrentUser(board.owner.uid)" class="board-owner-label">
{{ t('deck', 'Board owner') }}
</span>
</span>
</li>
<li v-for="acl in board.acl" :key="acl.id" :data-cy="'acl-participant:' + acl.participant.uid">
<NcAvatar v-if="acl.type===0" :user="acl.participant.uid" />
<div v-if="acl.type===1" class="avatardiv icon icon-group" />
<div v-if="acl.type===7" class="avatardiv icon icon-circles" />
<div v-if="acl.type===6" class="avatardiv icon" />
<span class="username">
{{ acl.participant.displayname || acl.participant }}
<span v-if="acl.type===1">{{ t('deck', '(Group)') }}</span>
<span v-if="acl.type===7">{{ t('deck', '(Team)') }}</span>
<span v-if="acl.type===6">{{ t('deck', '(remote)') }}</span>
</span>
<NcActionCheckbox v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0) && (canManage || (canEdit && canShare))"
:checked="acl.permissionEdit"
data-cy="action:permission-edit"
@change="clickEditAcl(acl)">
{{ t('deck', 'Can edit') }}
</NcActionCheckbox>
<NcActions v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0)" :force-menu="true">
<NcActionCheckbox v-if="canManage || canShare"
:checked="acl.permissionShare"
data-cy="action:permission-share"
@change="clickShareAcl(acl)">
{{ t('deck', 'Can share') }}
</NcActionCheckbox>
<NcActionCheckbox v-if="canManage"
:checked="acl.permissionManage"
data-cy="action:permission-manage"
@change="clickManageAcl(acl)">
{{ t('deck', 'Can manage') }}
</NcActionCheckbox>
<NcActionCheckbox v-if="acl.type === 0 && isCurrentUser(board.owner.uid)"
:checked="acl.owner"
data-cy="action:permission-owner"
@change="clickTransferOwner(acl.participant.uid)">
{{ t('deck', 'Owner') }}
</NcActionCheckbox>
<NcActionButton v-if="canManage"
icon="icon-delete"
data-cy="action:acl-delete"
@click="clickDeleteAcl(acl)">
{{ t('deck', 'Delete') }}
</NcActionButton>
</NcActions>
</li>
</ul>
<NcRelatedResourcesPanel v-if="board.id"
provider-id="deck"
:item-id="board.id" />
<NcCollectionList v-if="projectsEnabled && board.id"
:id="`${board.id}`"
:name="board.title"
type="deck" />
</div>
</template>
<script>
import { NcCollectionList, NcAvatar, NcActions, NcActionButton, NcActionCheckbox, NcRelatedResourcesPanel, NcSelectUsers } from '@nextcloud/vue'
import { mapGetters, mapState } from 'vuex'
import { getCurrentUser } from '@nextcloud/auth'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import debounce from 'lodash/debounce.js'
const SOURCE_TO_SHARE_TYPE = {
users: 0,
groups: 1,
emails: 4,
remotes: 6,
circles: 7,
}
export default {
name: 'SharingTabSidebar',
components: {
NcAvatar,
NcActions,
NcActionButton,
NcActionCheckbox,
NcSelectUsers,
NcCollectionList,
NcRelatedResourcesPanel,
},
props: {
board: {
type: Object,
default: undefined,
},
},
data() {
return {
isLoading: false,
isSearching: false,
addAcl: null,
addAclForAPI: null,
newOwner: null,
projectsEnabled: loadState('core', 'projects_enabled', false),
}
},
computed: {
...mapState([
'sharees',
]),
...mapGetters([
'canEdit',
'canManage',
'canShare',
]),
isCurrentUser() {
return (uid) => uid === getCurrentUser().uid
},
formatedSharees() {
const result = this.unallocatedSharees.map(item => {
const res = {
...item,
displayName: item.displayname || item.name || item.label || item.id,
user: item.id,
subname: item.shareWithDisplayNameUnique || item.subline || item.id, // NcSelectUser does its own pattern matching to filter things out
type: SOURCE_TO_SHARE_TYPE[item.source]
}
return res
}).slice(0, 10)
return result
},
unallocatedSharees() {
return this.sharees.filter((sharee) => {
const foundIndex = this.board.acl.findIndex((acl) => {
if (acl.participant.uid === sharee.id && acl.type === SOURCE_TO_SHARE_TYPE[sharee.source]) {
return true
}
if (acl.participant.id === sharee.id && acl.type === SOURCE_TO_SHARE_TYPE[sharee.source]) {
return true
}
return false
})
if (foundIndex === -1) {
return true
}
return false
})
},
},
watch: {
addAcl: {
handler() {
if (this.addAcl) {
this.clickAddAcl()
}
},
},
},
mounted() {
this.asyncFind('', () => {})
},
methods: {
debouncedFind: debounce(async function(query) {
this.isSearching = true
await this.$store.dispatch('loadSharees', query)
this.isSearching = false
}, 300),
async asyncFind(query) {
this.isLoading = true
await this.debouncedFind(query)
this.isLoading = false
},
async clickAddAcl() {
this.addAclForAPI = {
type: SOURCE_TO_SHARE_TYPE[this.addAcl.source],
participant: this.addAcl.id,
permissionEdit: false,
permissionShare: false,
permissionManage: false,
}
this.isLoading = true
try {
await this.$store.dispatch('addAclToCurrentBoard', this.addAclForAPI)
} catch (e) {
const errorMessage = t('deck', 'Failed to create share with {displayName}', { displayName: this.addAcl.displayName })
console.error(errorMessage, e)
showError(errorMessage)
}
this.addAcl = null
this.isLoading = false
},
clickEditAcl(acl) {
this.addAclForAPI = Object.assign({}, acl)
this.addAclForAPI.permissionEdit = !acl.permissionEdit
this.$store.dispatch('updateAclFromCurrentBoard', this.addAclForAPI)
},
clickShareAcl(acl) {
this.addAclForAPI = Object.assign({}, acl)
this.addAclForAPI.permissionShare = !acl.permissionShare
this.$store.dispatch('updateAclFromCurrentBoard', this.addAclForAPI)
},
clickManageAcl(acl) {
this.addAclForAPI = Object.assign({}, acl)
this.addAclForAPI.permissionManage = !acl.permissionManage
this.$store.dispatch('updateAclFromCurrentBoard', this.addAclForAPI)
},
clickDeleteAcl(acl) {
this.$store.dispatch('deleteAclFromCurrentBoard', acl)
},
clickTransferOwner(newOwner) {
OC.dialogs.confirmDestructive(
t('deck', 'Are you sure you want to transfer the board {title} to {user}?', { title: this.board.title, user: newOwner }),
t('deck', 'Transfer the board.'),
{
type: OC.dialogs.YES_NO_BUTTONS,
confirm: t('deck', 'Transfer'),
confirmClasses: 'error',
cancel: t('deck', 'Cancel'),
},
async (result) => {
if (result) {
try {
this.isLoading = true
await this.$store.dispatch('transferOwnership', {
boardId: this.board.id,
newOwner,
})
const successMessage = t('deck', 'The board has been transferred to {user}', { user: newOwner })
showSuccess(successMessage)
this.$router.push({ name: 'main' })
} catch (e) {
const errorMessage = t('deck', 'Failed to transfer the board to {user}', { user: newOwner.user })
showError(errorMessage)
} finally {
this.isLoading = false
}
}
},
true,
)
},
},
}
</script>
<style scoped>
#shareWithList {
margin-bottom: 20px;
}
#shareWithList li {
display: flex;
align-items: center;
}
.username {
padding: 12px 9px;
flex-grow: 1;
}
.board-owner-label {
opacity: .7;
}
.avatarLabel {
padding: 6px
}
.avatardiv {
background-color: var(--color-background-dark);
border-radius: 16px;
width: 32px;
height: 32px;
}
</style>