199 lines
9.6 KiB
Vue
199 lines
9.6 KiB
Vue
<script setup lang="ts">
|
|
import { Form, Head } from '@inertiajs/vue3';
|
|
import { FolderPlus, Shield, Users } from 'lucide-vue-next';
|
|
import UserManagementController from '@/actions/App/Http/Controllers/Admin/UserManagementController';
|
|
import Heading from '@/components/Heading.vue';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from '@/components/ui/card';
|
|
import AppLayout from '@/layouts/AppLayout.vue';
|
|
import { index as adminUsers } from '@/routes/admin/users';
|
|
import type { AdminUsersPageProps, BreadcrumbItem } from '@/types';
|
|
|
|
const props = defineProps<AdminUsersPageProps>();
|
|
|
|
const breadcrumbs: BreadcrumbItem[] = [
|
|
{
|
|
title: 'User management',
|
|
href: adminUsers(),
|
|
},
|
|
];
|
|
|
|
const hasPermission = (actorId: number, permission: string) =>
|
|
(props.directPermissions[actorId] ?? []).includes(permission);
|
|
</script>
|
|
|
|
<template>
|
|
<AppLayout :breadcrumbs="breadcrumbs">
|
|
<Head title="User management" />
|
|
|
|
<div class="flex flex-1 flex-col gap-6 p-4">
|
|
<div class="flex items-start justify-between gap-4">
|
|
<Heading
|
|
title="User management"
|
|
description="Assign the global permissions that unlock platform-wide administration and project creation."
|
|
/>
|
|
|
|
<Badge variant="outline" class="gap-1.5 px-3 py-1">
|
|
<Users class="size-3.5" />
|
|
Admin-only area
|
|
</Badge>
|
|
</div>
|
|
|
|
<div
|
|
v-if="status"
|
|
class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-900 dark:border-emerald-900/70 dark:bg-emerald-950/40 dark:text-emerald-100"
|
|
>
|
|
{{ status }}
|
|
</div>
|
|
|
|
<Card class="gap-0 overflow-hidden">
|
|
<CardHeader class="border-b">
|
|
<CardTitle>Users</CardTitle>
|
|
<CardDescription>
|
|
Global permissions are assigned directly to users and
|
|
apply across the entire application.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
|
|
<CardContent class="p-0">
|
|
<div
|
|
v-if="users.length === 0"
|
|
class="text-muted-foreground p-6 text-sm"
|
|
>
|
|
No users exist yet.
|
|
</div>
|
|
|
|
<div v-else class="overflow-x-auto">
|
|
<table class="divide-border min-w-full divide-y text-sm">
|
|
<thead
|
|
class="bg-muted/40 text-muted-foreground text-left"
|
|
>
|
|
<tr>
|
|
<th class="px-4 py-3 font-medium">User</th>
|
|
<th class="px-4 py-3 font-medium">Email</th>
|
|
<th class="px-4 py-3 font-medium">
|
|
Current access
|
|
</th>
|
|
<th
|
|
class="px-4 py-3 text-right font-medium"
|
|
>
|
|
Action
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-border divide-y">
|
|
<tr
|
|
v-for="user in users"
|
|
:key="user.id"
|
|
class="bg-background align-top"
|
|
>
|
|
<td class="px-4 py-4">
|
|
<div class="text-foreground font-medium">
|
|
{{ user.name }}
|
|
</div>
|
|
</td>
|
|
<td class="text-muted-foreground px-4 py-4">
|
|
{{ user.email }}
|
|
</td>
|
|
<td class="px-4 py-4">
|
|
<div class="flex flex-wrap gap-2">
|
|
<Badge
|
|
v-if="
|
|
hasPermission(
|
|
user.id,
|
|
'global:admin',
|
|
)
|
|
"
|
|
class="gap-1.5"
|
|
>
|
|
<Shield class="size-3.5" />
|
|
Global admin
|
|
</Badge>
|
|
<Badge
|
|
v-if="
|
|
hasPermission(
|
|
user.id,
|
|
'project:create',
|
|
)
|
|
"
|
|
variant="secondary"
|
|
class="gap-1.5"
|
|
>
|
|
<FolderPlus class="size-3.5" />
|
|
Project create
|
|
</Badge>
|
|
<span
|
|
v-if="
|
|
(directPermissions[
|
|
user.id
|
|
] ?? []).length === 0
|
|
"
|
|
class="text-muted-foreground"
|
|
>
|
|
No direct global permissions
|
|
</span>
|
|
</div>
|
|
</td>
|
|
<td class="px-4 py-4">
|
|
<div class="flex justify-end">
|
|
<Form
|
|
v-bind="
|
|
UserManagementController.update.form(
|
|
user.id,
|
|
)
|
|
"
|
|
class="flex flex-wrap justify-end gap-3"
|
|
v-slot="{ processing }"
|
|
>
|
|
<label
|
|
v-for="option in permissionOptions"
|
|
:key="
|
|
`${user.id}-${option.value}`
|
|
"
|
|
class="border-border inline-flex items-center gap-2 rounded-lg border px-3 py-2 text-sm"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
name="permissions[]"
|
|
:value="option.value"
|
|
:checked="
|
|
hasPermission(
|
|
user.id,
|
|
option.value,
|
|
)
|
|
"
|
|
class="border-input text-primary focus:ring-ring size-4 rounded"
|
|
/>
|
|
<span>{{ option.label }}</span>
|
|
</label>
|
|
|
|
<div class="w-full sm:hidden" />
|
|
|
|
<Button
|
|
type="submit"
|
|
size="sm"
|
|
variant="outline"
|
|
:disabled="processing"
|
|
>
|
|
Save
|
|
</Button>
|
|
</Form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</AppLayout>
|
|
</template>
|