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
|
<!--
- @copyright Copyright (c) 2021 Marco Ambrosini <marcoambrosini@icloud.com>
-
- @author Marco Ambrosini <marcoambrosini@icloud.com>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div class="conversation-permissions-editor">
<h4 class="conversation-permissions-editor__title">
{{ t('spreed', 'Edit the default permissions for participants in this conversation. These settings do not affect moderators.') }}
</h4>
<p>{{ t('spreed', 'Warning: Every time permissions are modified in this section, custom permissions previously assigned to individual participants will be lost.') }}</p>
<!-- All permissions -->
<div class="conversation-permissions-editor__setting">
<CheckboxRadioSwitch :checked.sync="radioValue"
:disabled="loading"
value="all"
name="permission_radio"
type="radio"
@update:checked="handleSubmitPermissions">
{{ t('spreed', 'All permissions') }}
</CheckboxRadioSwitch>
<span v-show="loading && radioValue === 'all'" class="icon-loading-small" />
</div>
<p>{{ t('spreed', 'Participants have permissions to start a call, join a call, enable audio and video, and share screen.') }}</p>
<!-- No permissions -->
<div class="conversation-permissions-editor__setting">
<CheckboxRadioSwitch :checked.sync="radioValue"
value="restricted"
:disabled="loading"
name="permission_radio"
type="radio"
@update:checked="handleSubmitPermissions">
{{ t('spreed', 'Restricted') }}
</CheckboxRadioSwitch>
<span v-show="loading && radioValue === 'restricted'" class="icon-loading-small" />
</div>
<p>{{ t('spreed', 'Participants can join calls, but cannot enable audio nor video nor share screen until a moderator manually grants them permissions.') }}</p>
<!-- Advanced permissions -->
<div class="conversation-permissions-editor__setting--advanced">
<CheckboxRadioSwitch :checked.sync="radioValue"
value="advanced"
:disabled="loading"
name="permission_radio"
type="radio"
@update:checked="showPermissionsEditor = true">
{{ t('spreed', 'Advanced permissions') }}
</CheckboxRadioSwitch>
<!-- Edit advanced permissions -->
<button v-show="showEditButton"
:aria-label="t('spreed', 'Edit permissions')"
class="nc-button nc-button__main"
@click="showPermissionsEditor = true">
<Pencil :size="20" />
</button>
</div>
<PermissionEditor v-if="showPermissionsEditor"
:conversation-name="conversationName"
:permissions="conversationPermissions"
:loading="loading"
@close="handleClosePermissionsEditor"
@submit="handleSubmitPermissions" />
</div>
</template>
<script>
import PermissionEditor from '../PermissionsEditor/PermissionsEditor.vue'
import CheckboxRadioSwitch from '@nextcloud/vue/dist/Components/CheckboxRadioSwitch'
import Pencil from 'vue-material-design-icons/Pencil.vue'
import { PARTICIPANT } from '../../constants.js'
import { showError, showSuccess } from '@nextcloud/dialogs'
const PERMISSIONS = PARTICIPANT.PERMISSIONS
export default {
name: 'ConversationPermissionsSettings',
components: {
PermissionEditor,
CheckboxRadioSwitch,
Pencil,
},
props: {
token: {
type: String,
default: null,
},
},
data() {
return {
showPermissionsEditor: false,
isEditingPermissions: false,
loading: false,
radioValue: '',
}
},
computed: {
/**
* The participant's name.
*/
conversationName() {
return this.$store.getters.conversation(this.token).name
},
/**
* The current conversation permissions.
*/
conversationPermissions() {
return this.$store.getters.conversation(this.token).defaultPermissions
},
/**
* Hides and shows the edit button for advanced permissions.
*/
showEditButton() {
return this.radioValue === 'advanced' && !this.showPermissionsEditor
},
},
mounted() {
/**
* Set the initial radio value.
*/
this.setCurrentRadioValue()
},
methods: {
/**
* Binary sum all the permissions and make the request to change them.
*
* @param {string | number} value - The permissions value, which is a
* string (e.g. 'restricted' or 'all') unless this method is called by
* the click event emitted by the `permissionsEditor` component, in
* which case it's a number indicating the permissions value.
*/
async handleSubmitPermissions(value) {
let permissions
// Compute the permissions value
switch (value) {
case 'all':
permissions = PERMISSIONS.MAX_DEFAULT
break
case 'restricted':
permissions = PERMISSIONS.CALL_JOIN
break
default:
permissions = value
}
this.loading = true
// Make the store call
try {
await this.$store.dispatch('setConversationPermissions', {
token: this.token,
permissions,
})
showSuccess(t('spreed', 'Default permissions modified for {conversationName}', { conversationName: this.conversationName }))
// Modify the radio buttons value
this.radioValue = this.getPermissionRadioValue(permissions)
this.showPermissionsEditor = false
} catch (error) {
console.debug(error)
showError(t('spreed', 'Could not modify default permissions for {conversationName}', { conversationName: this.conversationName }))
// Go back to the previous radio value
this.radioValue = this.getPermissionRadioValue(this.conversationPermissions)
} finally {
this.loading = false
}
},
/**
* Get the radio button string value given a permission number.
*
* @param {number} value - The permissions value.
*/
getPermissionRadioValue(value) {
switch (value) {
case PERMISSIONS.MAX_DEFAULT:
return 'all'
case PERMISSIONS.CALL_JOIN:
return 'restricted'
default:
return 'advanced'
}
},
/**
* Set the radio value that corresponds to the current default
* permissions in the store.
*/
setCurrentRadioValue() {
this.radioValue = this.getPermissionRadioValue(this.conversationPermissions)
},
/**
* Hides the modal and resets conversation permissions to the previous
* value.
*/
handleClosePermissionsEditor() {
this.showPermissionsEditor = false
this.setCurrentRadioValue()
},
},
}
</script>
<style lang="scss" scoped>
@import '../../assets/buttons';
::v-deep .mx-input {
margin: 0;
}
.conversation-permissions-editor {
&__setting {
display: flex;
justify-content: space-between;
&--advanced {
display: flex;
justify-content: flex-start;
// Edit button
button {
margin-left: 16px;
}
}
}
}
p {
color: var(--color-text-lighter);
margin-bottom: 16px;
}
</style>
|