summaryrefslogtreecommitdiff
path: root/packages/frontend/src/pages/admin/roles.vue
blob: e65a3c5ba888387e79cd4466c9c1ceaf58812707 (plain)
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<PageWithHeader :actions="headerActions" :tabs="headerTabs">
	<div class="_spacer" style="--MI_SPACER-w: 700px;">
		<div class="_gaps">
			<MkFolder>
				<template #label>{{ i18n.ts._role.baseRole }}</template>
				<template #footer>
					<MkButton primary rounded @click="updateBaseRole">{{ i18n.ts.save }}</MkButton>
				</template>
				<div class="_gaps_s">
					<MkInput v-model="baseRoleQ" type="search">
						<template #prefix><i class="ti ti-search"></i></template>
					</MkInput>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.rateLimitFactor, 'rateLimitFactor'])">
						<template #label>{{ i18n.ts._role._options.rateLimitFactor }}</template>
						<template #suffix>{{ Math.floor(policies.rateLimitFactor * 100) }}%</template>
						<MkRange :modelValue="policies.rateLimitFactor * 100" :min="30" :max="300" :step="10" :textConverter="(v) => `${v}%`" @update:modelValue="v => policies.rateLimitFactor = (v / 100)">
							<template #caption>{{ i18n.ts._role._options.descriptionOfRateLimitFactor }}</template>
						</MkRange>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.gtlAvailable, 'gtlAvailable'])">
						<template #label>{{ i18n.ts._role._options.gtlAvailable }}</template>
						<template #suffix>{{ policies.gtlAvailable ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.gtlAvailable">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.ltlAvailable, 'ltlAvailable'])">
						<template #label>{{ i18n.ts._role._options.ltlAvailable }}</template>
						<template #suffix>{{ policies.ltlAvailable ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.ltlAvailable">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canPublicNote, 'canPublicNote'])">
						<template #label>{{ i18n.ts._role._options.canPublicNote }}</template>
						<template #suffix>{{ policies.canPublicNote ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canPublicNote">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.chatAvailability, 'chatAvailability'])">
						<template #label>{{ i18n.ts._role._options.chatAvailability }}</template>
						<template #suffix>{{ policies.chatAvailability === 'available' ? i18n.ts.yes : policies.chatAvailability === 'readonly' ? i18n.ts.readonly : i18n.ts.no }}</template>
						<MkSelect
							v-model="policies.chatAvailability"
							:items="[
								{ label: i18n.ts.enabled, value: 'available' },
								{ label: i18n.ts.readonly, value: 'readonly' },
								{ label: i18n.ts.disabled, value: 'unavailable' },
							]"
						>
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSelect>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.mentionMax, 'mentionLimit'])">
						<template #label>{{ i18n.ts._role._options.mentionMax }}</template>
						<template #suffix>{{ policies.mentionLimit }}</template>
						<MkInput v-model="policies.mentionLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canInvite, 'canInvite'])">
						<template #label>{{ i18n.ts._role._options.canInvite }}</template>
						<template #suffix>{{ policies.canInvite ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canInvite">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.inviteLimit, 'inviteLimit'])">
						<template #label>{{ i18n.ts._role._options.inviteLimit }}</template>
						<template #suffix>{{ policies.inviteLimit }}</template>
						<MkInput v-model="policies.inviteLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.inviteLimitCycle, 'inviteLimitCycle'])">
						<template #label>{{ i18n.ts._role._options.inviteLimitCycle }}</template>
						<template #suffix>{{ policies.inviteLimitCycle + i18n.ts._time.minute }}</template>
						<MkInput v-model="policies.inviteLimitCycle" type="number">
							<template #suffix>{{ i18n.ts._time.minute }}</template>
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.inviteExpirationTime, 'inviteExpirationTime'])">
						<template #label>{{ i18n.ts._role._options.inviteExpirationTime }}</template>
						<template #suffix>{{ policies.inviteExpirationTime + i18n.ts._time.minute }}</template>
						<MkInput v-model="policies.inviteExpirationTime" type="number">
							<template #suffix>{{ i18n.ts._time.minute }}</template>
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canManageAvatarDecorations, 'canManageAvatarDecorations'])">
						<template #label>{{ i18n.ts._role._options.canManageAvatarDecorations }}</template>
						<template #suffix>{{ policies.canManageAvatarDecorations ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canManageAvatarDecorations">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canManageCustomEmojis, 'canManageCustomEmojis'])">
						<template #label>{{ i18n.ts._role._options.canManageCustomEmojis }}</template>
						<template #suffix>{{ policies.canManageCustomEmojis ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canManageCustomEmojis">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canSearchNotes, 'canSearchNotes'])">
						<template #label>{{ i18n.ts._role._options.canSearchNotes }}</template>
						<template #suffix>{{ policies.canSearchNotes ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canSearchNotes">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canSearchUsers, 'canSearchUsers'])">
						<template #label>{{ i18n.ts._role._options.canSearchUsers }}</template>
						<template #suffix>{{ policies.canSearchUsers ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canSearchUsers">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canUseTranslator, 'canUseTranslator'])">
						<template #label>{{ i18n.ts._role._options.canUseTranslator }}</template>
						<template #suffix>{{ policies.canUseTranslator ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canUseTranslator">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.driveCapacity, 'driveCapacityMb'])">
						<template #label>{{ i18n.ts._role._options.driveCapacity }}</template>
						<template #suffix>{{ policies.driveCapacityMb }}MB</template>
						<MkInput v-model="policies.driveCapacityMb" type="number">
							<template #suffix>MB</template>
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.maxFileSize, 'maxFileSizeMb'])">
						<template #label>{{ i18n.ts._role._options.maxFileSize }}</template>
						<template #suffix>{{ policies.maxFileSizeMb }}MB</template>
						<MkInput v-model="policies.maxFileSizeMb" type="number">
							<template #suffix>MB</template>
							<template #caption>
								<div><i class="ti ti-alert-triangle" style="color: var(--MI_THEME-warn);"></i> {{ i18n.ts._role._options.maxFileSize_caption }}</div>
							</template>
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.uploadableFileTypes, 'uploadableFileTypes'])">
						<template #label>{{ i18n.ts._role._options.uploadableFileTypes }}</template>
						<template #suffix>...</template>
						<MkTextarea :modelValue="policies.uploadableFileTypes.join('\n')" @update:modelValue="v => policies.uploadableFileTypes = v.split('\n')">
							<template #caption>
								<div>{{ i18n.ts._role._options.uploadableFileTypes_caption }}</div>
								<div><i class="ti ti-alert-triangle" style="color: var(--MI_THEME-warn);"></i> {{ i18n.tsx._role._options.uploadableFileTypes_caption2({ x: 'application/octet-stream' }) }}</div>
							</template>
						</MkTextarea>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.alwaysMarkNsfw, 'alwaysMarkNsfw'])">
						<template #label>{{ i18n.ts._role._options.alwaysMarkNsfw }}</template>
						<template #suffix>{{ policies.alwaysMarkNsfw ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.alwaysMarkNsfw">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canUpdateBioMedia, 'canUpdateBioMedia'])">
						<template #label>{{ i18n.ts._role._options.canUpdateBioMedia }}</template>
						<template #suffix>{{ policies.canUpdateBioMedia ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canUpdateBioMedia">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.pinMax, 'pinLimit'])">
						<template #label>{{ i18n.ts._role._options.pinMax }}</template>
						<template #suffix>{{ policies.pinLimit }}</template>
						<MkInput v-model="policies.pinLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.antennaMax, 'antennaLimit'])">
						<template #label>{{ i18n.ts._role._options.antennaMax }}</template>
						<template #suffix>{{ policies.antennaLimit }}</template>
						<MkInput v-model="policies.antennaLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.wordMuteMax, 'wordMuteLimit'])">
						<template #label>{{ i18n.ts._role._options.wordMuteMax }}</template>
						<template #suffix>{{ policies.wordMuteLimit }}</template>
						<MkInput v-model="policies.wordMuteLimit" type="number">
							<template #suffix>chars</template>
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.webhookMax, 'webhookLimit'])">
						<template #label>{{ i18n.ts._role._options.webhookMax }}</template>
						<template #suffix>{{ policies.webhookLimit }}</template>
						<MkInput v-model="policies.webhookLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.clipMax, 'clipLimit'])">
						<template #label>{{ i18n.ts._role._options.clipMax }}</template>
						<template #suffix>{{ policies.clipLimit }}</template>
						<MkInput v-model="policies.clipLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.noteEachClipsMax, 'noteEachClipsLimit'])">
						<template #label>{{ i18n.ts._role._options.noteEachClipsMax }}</template>
						<template #suffix>{{ policies.noteEachClipsLimit }}</template>
						<MkInput v-model="policies.noteEachClipsLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.userListMax, 'userListLimit'])">
						<template #label>{{ i18n.ts._role._options.userListMax }}</template>
						<template #suffix>{{ policies.userListLimit }}</template>
						<MkInput v-model="policies.userListLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.userEachUserListsMax, 'userEachUserListsLimit'])">
						<template #label>{{ i18n.ts._role._options.userEachUserListsMax }}</template>
						<template #suffix>{{ policies.userEachUserListsLimit }}</template>
						<MkInput v-model="policies.userEachUserListsLimit" type="number">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canHideAds, 'canHideAds'])">
						<template #label>{{ i18n.ts._role._options.canHideAds }}</template>
						<template #suffix>{{ policies.canHideAds ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canHideAds">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.avatarDecorationLimit, 'avatarDecorationLimit'])">
						<template #label>{{ i18n.ts._role._options.avatarDecorationLimit }}</template>
						<template #suffix>{{ policies.avatarDecorationLimit }}</template>
						<MkInput v-model="avatarDecorationLimit" type="number" :min="0" :max="16" @update:modelValue="updateAvatarDecorationLimit">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportAntennas, 'canImportAntennas'])">
						<template #label>{{ i18n.ts._role._options.canImportAntennas }}</template>
						<template #suffix>{{ policies.canImportAntennas ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canImportAntennas">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportBlocking, 'canImportBlocking'])">
						<template #label>{{ i18n.ts._role._options.canImportBlocking }}</template>
						<template #suffix>{{ policies.canImportBlocking ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canImportBlocking">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportFollowing, 'canImportFollowing'])">
						<template #label>{{ i18n.ts._role._options.canImportFollowing }}</template>
						<template #suffix>{{ policies.canImportFollowing ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canImportFollowing">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportMuting, 'canImportMuting'])">
						<template #label>{{ i18n.ts._role._options.canImportMuting }}</template>
						<template #suffix>{{ policies.canImportMuting ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canImportMuting">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportUserLists, 'canImportUserList'])">
						<template #label>{{ i18n.ts._role._options.canImportUserLists }}</template>
						<template #suffix>{{ policies.canImportUserLists ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.canImportUserLists">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.noteDraftLimit, 'noteDraftLimit'])">
						<template #label>{{ i18n.ts._role._options.noteDraftLimit }}</template>
						<template #suffix>{{ policies.noteDraftLimit }}</template>
						<MkInput v-model="policies.noteDraftLimit" type="number" :min="0">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.scheduledNoteLimit, 'scheduledNoteLimit'])">
						<template #label>{{ i18n.ts._role._options.scheduledNoteLimit }}</template>
						<template #suffix>{{ policies.scheduledNoteLimit }}</template>
						<MkInput v-model="policies.scheduledNoteLimit" type="number" :min="0">
						</MkInput>
					</MkFolder>

					<MkFolder v-if="matchQuery([i18n.ts._role._options.watermarkAvailable, 'watermarkAvailable'])">
						<template #label>{{ i18n.ts._role._options.watermarkAvailable }}</template>
						<template #suffix>{{ policies.watermarkAvailable ? i18n.ts.yes : i18n.ts.no }}</template>
						<MkSwitch v-model="policies.watermarkAvailable">
							<template #label>{{ i18n.ts.enable }}</template>
						</MkSwitch>
					</MkFolder>
				</div>
			</MkFolder>
			<MkButton primary rounded @click="create"><i class="ti ti-plus"></i> {{ i18n.ts._role.new }}</MkButton>
			<div class="_gaps_s">
				<MkFoldableSection>
					<template #header>{{ i18n.ts._role.manualRoles }}</template>
					<div class="_gaps_s">
						<MkRolePreview v-for="role in roles.filter(x => x.target === 'manual')" :key="role.id" :role="role" :forModeration="true"/>
					</div>
				</MkFoldableSection>
				<MkFoldableSection>
					<template #header>{{ i18n.ts._role.conditionalRoles }}</template>
					<div class="_gaps_s">
						<MkRolePreview v-for="role in roles.filter(x => x.target === 'conditional')" :key="role.id" :role="role" :forModeration="true"/>
					</div>
				</MkFoldableSection>
			</div>
		</div>
	</div>
</PageWithHeader>
</template>

<script lang="ts" setup>
import { computed, reactive, ref } from 'vue';
import * as Misskey from 'misskey-js';
import MkInput from '@/components/MkInput.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkButton from '@/components/MkButton.vue';
import MkSelect from '@/components/MkSelect.vue';
import MkRange from '@/components/MkRange.vue';
import MkRolePreview from '@/components/MkRolePreview.vue';
import * as os from '@/os.js';
import { misskeyApi } from '@/utility/misskey-api.js';
import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js';
import { instance, fetchInstance } from '@/instance.js';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import { useRouter } from '@/router.js';
import { deepClone } from '@/utility/clone.js';
import MkTextarea from '@/components/MkTextarea.vue';

const router = useRouter();
const baseRoleQ = ref('');

const roles = await misskeyApi('admin/roles/list');

const policies = reactive(deepClone(instance.policies));

const avatarDecorationLimit = computed({
	get: () => Math.min(16, Math.max(0, policies.avatarDecorationLimit)),
	set: (value) => {
		policies.avatarDecorationLimit = Math.min(Number(value), 16);
	},
});

function updateAvatarDecorationLimit(value: string | number) {
	avatarDecorationLimit.value = Number(value);
}

function matchQuery(keywords: string[]): boolean {
	if (baseRoleQ.value.trim().length === 0) return true;
	return keywords.some(keyword => keyword.toLowerCase().includes(baseRoleQ.value.toLowerCase()));
}

async function updateBaseRole() {
	await os.apiWithDialog('admin/roles/update-default-policies', {
		//@ts-expect-error misskey-js側の型定義が不十分
		policies,
	});
	fetchInstance(true);
}

function create() {
	router.push('/admin/roles/new');
}

const headerActions = computed(() => []);

const headerTabs = computed(() => []);

definePage(() => ({
	title: i18n.ts.roles,
	icon: 'ti ti-badges',
}));
</script>

<style lang="scss" module>

</style>