|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed } from 'vue' |
| 3 | +import Button from 'primevue/button' |
| 4 | +import Tag from 'primevue/tag' |
| 5 | +import type { AdminRoleRecord, AdminUserRecord } from '@/types/admin' |
| 6 | +
|
| 7 | +const props = defineProps<{ |
| 8 | + users: AdminUserRecord[] |
| 9 | + roles: AdminRoleRecord[] |
| 10 | + canManageUsers: boolean |
| 11 | + canManageApiKeys: boolean |
| 12 | +}>() |
| 13 | +
|
| 14 | +defineEmits<{ |
| 15 | + create: [] |
| 16 | + edit: [user: AdminUserRecord] |
| 17 | + remove: [user: AdminUserRecord] |
| 18 | + createApiKey: [user: AdminUserRecord] |
| 19 | +}>() |
| 20 | +
|
| 21 | +const roleNameMap = computed(() => new Map(props.roles.map((role) => [role.id, role.name]))) |
| 22 | +
|
| 23 | +function previewPermissions(permissions: string[]) { |
| 24 | + return permissions.slice(0, 4) |
| 25 | +} |
| 26 | +</script> |
| 27 | + |
| 28 | +<template> |
| 29 | + <section class="mb-8"> |
| 30 | + <div class="flex items-center justify-between gap-3 mb-3"> |
| 31 | + <div> |
| 32 | + <h2 class="text-lg font-semibold">Users</h2> |
| 33 | + <p class="text-sm opacity-70"> |
| 34 | + Manage local users, direct permissions, and role assignments. |
| 35 | + </p> |
| 36 | + </div> |
| 37 | + |
| 38 | + <Button |
| 39 | + v-if="canManageUsers" |
| 40 | + size="small" |
| 41 | + icon="ti ti-user-plus" |
| 42 | + label="Add user" |
| 43 | + @click="$emit('create')" |
| 44 | + /> |
| 45 | + </div> |
| 46 | + |
| 47 | + <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4"> |
| 48 | + <div |
| 49 | + v-for="user of users" |
| 50 | + :key="user.id" |
| 51 | + class="rounded-2xl border app-border px-4 py-4 flex flex-col gap-3" |
| 52 | + > |
| 53 | + <div class="flex items-start justify-between gap-3"> |
| 54 | + <div> |
| 55 | + <h3 class="font-semibold">{{ user.name }}</h3> |
| 56 | + <div class="text-sm opacity-70">{{ user.email }}</div> |
| 57 | + </div> |
| 58 | + |
| 59 | + <Tag |
| 60 | + :value=" |
| 61 | + user.disabled ? 'Disabled' : user.authProvider === 'openid' ? 'OpenID' : 'Local' |
| 62 | + " |
| 63 | + :severity="user.disabled ? 'danger' : 'secondary'" |
| 64 | + /> |
| 65 | + </div> |
| 66 | + |
| 67 | + <div class="flex flex-wrap gap-2"> |
| 68 | + <Tag |
| 69 | + v-for="roleId of user.roleIds" |
| 70 | + :key="roleId" |
| 71 | + :value="roleNameMap.get(roleId) || roleId" |
| 72 | + severity="info" |
| 73 | + /> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div class="flex flex-wrap gap-2"> |
| 77 | + <Tag |
| 78 | + v-for="permission of previewPermissions(user.permissions)" |
| 79 | + :key="permission" |
| 80 | + :value="permission" |
| 81 | + severity="secondary" |
| 82 | + /> |
| 83 | + <Tag |
| 84 | + v-if="user.permissions.length > 4" |
| 85 | + :value="`+${user.permissions.length - 4} more`" |
| 86 | + severity="contrast" |
| 87 | + /> |
| 88 | + </div> |
| 89 | + |
| 90 | + <div class="flex items-center gap-2 pt-1"> |
| 91 | + <Button |
| 92 | + v-if="canManageUsers" |
| 93 | + icon="ti ti-edit" |
| 94 | + label="Edit" |
| 95 | + size="small" |
| 96 | + severity="secondary" |
| 97 | + @click="$emit('edit', user)" |
| 98 | + /> |
| 99 | + <Button |
| 100 | + v-if="canManageApiKeys" |
| 101 | + icon="ti ti-key" |
| 102 | + label="API key" |
| 103 | + size="small" |
| 104 | + severity="secondary" |
| 105 | + @click="$emit('createApiKey', user)" |
| 106 | + /> |
| 107 | + <Button |
| 108 | + v-if="canManageUsers" |
| 109 | + icon="ti ti-trash" |
| 110 | + label="Delete" |
| 111 | + size="small" |
| 112 | + severity="danger" |
| 113 | + text |
| 114 | + @click="$emit('remove', user)" |
| 115 | + /> |
| 116 | + </div> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + </section> |
| 120 | +</template> |
0 commit comments