2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-01-12 13:02:26 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-29 10:13:12 +02:00
|
|
|
<MkSpacer :contentMax="700">
|
2023-01-12 13:02:26 +01:00
|
|
|
<div class="_gaps">
|
|
|
|
<div class="_buttons">
|
|
|
|
<MkButton primary rounded @click="edit"><i class="ti ti-pencil"></i> {{ i18n.ts.edit }}</MkButton>
|
|
|
|
<MkButton danger rounded @click="del"><i class="ti ti-trash"></i> {{ i18n.ts.delete }}</MkButton>
|
|
|
|
</div>
|
|
|
|
<MkFolder>
|
|
|
|
<template #icon><i class="ti ti-info-circle"></i></template>
|
|
|
|
<template #label>{{ i18n.ts.info }}</template>
|
2023-05-29 10:13:12 +02:00
|
|
|
<XEditor :modelValue="role" readonly/>
|
2023-01-12 13:02:26 +01:00
|
|
|
</MkFolder>
|
2023-05-29 10:13:12 +02:00
|
|
|
<MkFolder v-if="role.target === 'manual'" defaultOpen>
|
2023-01-12 13:02:26 +01:00
|
|
|
<template #icon><i class="ti ti-users"></i></template>
|
|
|
|
<template #label>{{ i18n.ts.users }}</template>
|
2023-02-22 06:43:18 +01:00
|
|
|
<template #suffix>{{ role.usersCount }}</template>
|
2023-01-12 13:02:26 +01:00
|
|
|
<div class="_gaps">
|
|
|
|
<MkButton primary rounded @click="assign"><i class="ti ti-plus"></i> {{ i18n.ts.assign }}</MkButton>
|
|
|
|
|
2023-02-22 06:43:18 +01:00
|
|
|
<MkPagination :pagination="usersPagination">
|
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
2023-06-09 07:00:53 +02:00
|
|
|
<img :src="infoImageUrl" class="_ghost"/>
|
2023-02-22 06:43:18 +01:00
|
|
|
<div>{{ i18n.ts.noUsers }}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items }">
|
|
|
|
<div class="_gaps_s">
|
2023-03-01 06:22:53 +01:00
|
|
|
<div v-for="item in items" :key="item.user.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedItems.includes(item.id) }]">
|
|
|
|
<div :class="$style.userItemMain">
|
2023-08-13 14:02:25 +02:00
|
|
|
<MkA :class="$style.userItemMainBody" :to="`/admin/user/${item.user.id}`">
|
2023-03-01 06:22:53 +01:00
|
|
|
<MkUserCardMini :user="item.user"/>
|
|
|
|
</MkA>
|
|
|
|
<button class="_button" :class="$style.userToggle" @click="toggleItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button>
|
|
|
|
<button class="_button" :class="$style.unassign" @click="unassign(item.user, $event)"><i class="ti ti-x"></i></button>
|
|
|
|
</div>
|
|
|
|
<div v-if="expandedItems.includes(item.id)" :class="$style.userItemSub">
|
|
|
|
<div>Assigned: <MkTime :time="item.createdAt" mode="detail"/></div>
|
2023-07-20 03:54:41 +02:00
|
|
|
<div v-if="item.expiresAt">Period: {{ new Date(item.expiresAt).toLocaleString() }}</div>
|
2023-03-01 06:22:53 +01:00
|
|
|
<div v-else>Period: {{ i18n.ts.indefinitely }}</div>
|
|
|
|
</div>
|
2023-02-22 06:43:18 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
2023-01-12 13:02:26 +01:00
|
|
|
</div>
|
|
|
|
</MkFolder>
|
2023-01-13 03:07:51 +01:00
|
|
|
<MkInfo v-else>{{ i18n.ts._role.isConditionalRole }}</MkInfo>
|
2023-01-12 13:02:26 +01:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, reactive } from 'vue';
|
|
|
|
import XHeader from './_header_.vue';
|
|
|
|
import XEditor from './roles.editor.vue';
|
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { useRouter } from '@/router.js';
|
2023-01-12 13:02:26 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkUserCardMini from '@/components/MkUserCardMini.vue';
|
2023-01-13 03:07:51 +01:00
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2023-02-22 06:43:18 +01:00
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { infoImageUrl } from '@/instance.js';
|
2023-01-12 13:02:26 +01:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
id?: string;
|
|
|
|
}>();
|
|
|
|
|
2023-02-22 06:43:18 +01:00
|
|
|
const usersPagination = {
|
|
|
|
endpoint: 'admin/roles/users' as const,
|
|
|
|
limit: 20,
|
|
|
|
params: computed(() => ({
|
|
|
|
roleId: props.id,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2023-03-01 06:22:53 +01:00
|
|
|
let expandedItems = $ref([]);
|
|
|
|
|
2023-01-12 13:02:26 +01:00
|
|
|
const role = reactive(await os.api('admin/roles/show', {
|
|
|
|
roleId: props.id,
|
|
|
|
}));
|
|
|
|
|
|
|
|
function edit() {
|
|
|
|
router.push('/admin/roles/' + role.id + '/edit');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('deleteAreYouSure', { x: role.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.apiWithDialog('admin/roles/delete', {
|
|
|
|
roleId: role.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
router.push('/admin/roles');
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:20:03 +01:00
|
|
|
async function assign() {
|
|
|
|
const user = await os.selectUser({
|
2023-01-15 21:29:44 +01:00
|
|
|
includeSelf: true,
|
2023-01-12 13:02:26 +01:00
|
|
|
});
|
2023-03-01 02:20:03 +01:00
|
|
|
|
|
|
|
const { canceled: canceled2, result: period } = await os.select({
|
|
|
|
title: i18n.ts.period,
|
|
|
|
items: [{
|
|
|
|
value: 'indefinitely', text: i18n.ts.indefinitely,
|
|
|
|
}, {
|
|
|
|
value: 'oneHour', text: i18n.ts.oneHour,
|
|
|
|
}, {
|
|
|
|
value: 'oneDay', text: i18n.ts.oneDay,
|
|
|
|
}, {
|
|
|
|
value: 'oneWeek', text: i18n.ts.oneWeek,
|
|
|
|
}, {
|
|
|
|
value: 'oneMonth', text: i18n.ts.oneMonth,
|
|
|
|
}],
|
|
|
|
default: 'indefinitely',
|
|
|
|
});
|
|
|
|
if (canceled2) return;
|
|
|
|
|
|
|
|
const expiresAt = period === 'indefinitely' ? null
|
|
|
|
: period === 'oneHour' ? Date.now() + (1000 * 60 * 60)
|
|
|
|
: period === 'oneDay' ? Date.now() + (1000 * 60 * 60 * 24)
|
|
|
|
: period === 'oneWeek' ? Date.now() + (1000 * 60 * 60 * 24 * 7)
|
|
|
|
: period === 'oneMonth' ? Date.now() + (1000 * 60 * 60 * 24 * 30)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
await os.apiWithDialog('admin/roles/assign', { roleId: role.id, userId: user.id, expiresAt });
|
2023-03-01 06:22:53 +01:00
|
|
|
//role.users.push(user);
|
2023-01-12 13:02:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function unassign(user, ev) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.unassign,
|
|
|
|
icon: 'ti ti-x',
|
|
|
|
danger: true,
|
|
|
|
action: async () => {
|
|
|
|
await os.apiWithDialog('admin/roles/unassign', { roleId: role.id, userId: user.id });
|
2023-03-01 06:22:53 +01:00
|
|
|
//role.users = role.users.filter(u => u.id !== user.id);
|
2023-01-12 13:02:26 +01:00
|
|
|
},
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
2023-03-01 06:22:53 +01:00
|
|
|
async function toggleItem(item) {
|
|
|
|
if (expandedItems.includes(item.id)) {
|
|
|
|
expandedItems = expandedItems.filter(x => x !== item.id);
|
|
|
|
} else {
|
|
|
|
expandedItems.push(item.id);
|
|
|
|
}
|
2023-03-01 02:20:03 +01:00
|
|
|
}
|
|
|
|
|
2023-01-12 13:02:26 +01:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => ({
|
|
|
|
title: i18n.ts.role + ': ' + role.name,
|
|
|
|
icon: 'ti ti-badge',
|
|
|
|
})));
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2023-03-01 06:22:53 +01:00
|
|
|
.userItemMain {
|
2023-01-12 13:02:26 +01:00
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
2023-03-01 06:22:53 +01:00
|
|
|
.userItemSub {
|
|
|
|
padding: 6px 12px;
|
|
|
|
font-size: 85%;
|
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
}
|
|
|
|
|
|
|
|
.userItemMainBody {
|
2023-01-12 13:02:26 +01:00
|
|
|
flex: 1;
|
2023-02-23 00:29:16 +01:00
|
|
|
min-width: 0;
|
2023-03-01 06:22:53 +01:00
|
|
|
margin-right: 8px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
2023-01-12 13:02:26 +01:00
|
|
|
}
|
|
|
|
|
2023-03-01 06:22:53 +01:00
|
|
|
.userToggle,
|
2023-01-12 13:02:26 +01:00
|
|
|
.unassign {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
align-self: center;
|
|
|
|
}
|
2023-03-01 02:20:03 +01:00
|
|
|
|
2023-03-01 06:22:53 +01:00
|
|
|
.chevron {
|
|
|
|
display: block;
|
|
|
|
transition: transform 0.1s ease-out;
|
|
|
|
}
|
|
|
|
|
|
|
|
.userItem.userItemOpend {
|
|
|
|
.chevron {
|
|
|
|
transform: rotateX(180deg);
|
|
|
|
}
|
2023-03-01 02:20:03 +01:00
|
|
|
}
|
2023-01-12 13:02:26 +01:00
|
|
|
</style>
|