Implement project memberships teams and permission model
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
<script setup lang="ts">
|
||||
import { Form, Head, Link } from '@inertiajs/vue3';
|
||||
import ProjectController from '@/actions/App/Http/Controllers/ProjectController';
|
||||
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 { access, index, show } from '@/routes/projects';
|
||||
import type { BreadcrumbItem, ProjectAccessPageProps } from '@/types';
|
||||
|
||||
const props = defineProps<ProjectAccessPageProps>();
|
||||
|
||||
const breadcrumbs: BreadcrumbItem[] = [
|
||||
{
|
||||
title: 'Projects',
|
||||
href: index(),
|
||||
},
|
||||
{
|
||||
title: props.project.name,
|
||||
href: show(props.project.id),
|
||||
},
|
||||
{
|
||||
title: 'Access',
|
||||
href: access(props.project.id),
|
||||
},
|
||||
];
|
||||
|
||||
const hasPermission = (
|
||||
permissions: Record<string, string[]>,
|
||||
actorId: number,
|
||||
permission: string,
|
||||
) => (permissions[actorId] ?? []).includes(permission);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :breadcrumbs="breadcrumbs">
|
||||
<Head :title="`${project.name} access`" />
|
||||
|
||||
<div class="flex flex-1 flex-col gap-6 p-4">
|
||||
<div
|
||||
class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"
|
||||
>
|
||||
<div class="space-y-3">
|
||||
<Badge variant="outline" class="px-3 py-1">
|
||||
{{ project.key }}
|
||||
</Badge>
|
||||
<Heading
|
||||
:title="`${project.name} access`"
|
||||
description="Assign direct user permissions or inherited team permissions for this project."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button as-child variant="outline">
|
||||
<Link :href="show(project.id)">Back to project</Link>
|
||||
</Button>
|
||||
</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>User permissions</CardTitle>
|
||||
<CardDescription>
|
||||
Direct assignments apply only to the selected user
|
||||
inside this project.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent class="p-0">
|
||||
<div class="overflow-x-auto">
|
||||
<table
|
||||
class="min-w-full divide-y divide-border text-sm"
|
||||
>
|
||||
<thead
|
||||
class="bg-muted/40 text-left text-muted-foreground"
|
||||
>
|
||||
<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">
|
||||
Permissions
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-right font-medium"
|
||||
>
|
||||
Action
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-border">
|
||||
<tr
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="bg-background align-top"
|
||||
>
|
||||
<td
|
||||
class="px-4 py-4 font-medium text-foreground"
|
||||
>
|
||||
{{ user.name }}
|
||||
</td>
|
||||
<td class="px-4 py-4 text-muted-foreground">
|
||||
{{ user.email }}
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<Form
|
||||
v-bind="
|
||||
ProjectController.updateUserPermissions.form(
|
||||
[project.id, user.id],
|
||||
)
|
||||
"
|
||||
class="flex flex-wrap gap-3"
|
||||
v-slot="{ processing }"
|
||||
>
|
||||
<label
|
||||
v-for="option in permissionOptions"
|
||||
:key="`${user.id}-${option.value}`"
|
||||
class="inline-flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="permissions[]"
|
||||
:value="option.value"
|
||||
:checked="
|
||||
hasPermission(
|
||||
directPermissions,
|
||||
user.id,
|
||||
option.value,
|
||||
)
|
||||
"
|
||||
class="size-4 rounded border-input text-primary focus:ring-ring"
|
||||
/>
|
||||
<span>{{ option.label }}</span>
|
||||
</label>
|
||||
|
||||
<div class="w-full sm:hidden" />
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="processing"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Form>
|
||||
</td>
|
||||
<td
|
||||
class="px-4 py-4 text-right text-muted-foreground"
|
||||
>
|
||||
Direct
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card class="gap-0 overflow-hidden">
|
||||
<CardHeader class="border-b">
|
||||
<CardTitle>Team permissions</CardTitle>
|
||||
<CardDescription>
|
||||
Team assignments are inherited by every current and
|
||||
future member of that team.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent class="p-0">
|
||||
<div
|
||||
v-if="teams.length === 0"
|
||||
class="p-6 text-sm text-muted-foreground"
|
||||
>
|
||||
No teams exist yet. Create teams first to assign
|
||||
inherited permissions.
|
||||
</div>
|
||||
|
||||
<div v-else class="overflow-x-auto">
|
||||
<table
|
||||
class="min-w-full divide-y divide-border text-sm"
|
||||
>
|
||||
<thead
|
||||
class="bg-muted/40 text-left text-muted-foreground"
|
||||
>
|
||||
<tr>
|
||||
<th class="px-4 py-3 font-medium">Team</th>
|
||||
<th class="px-4 py-3 font-medium">
|
||||
Members
|
||||
</th>
|
||||
<th class="px-4 py-3 font-medium">
|
||||
Permissions
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-right font-medium"
|
||||
>
|
||||
Action
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-border">
|
||||
<tr
|
||||
v-for="team in teams"
|
||||
:key="team.id"
|
||||
class="bg-background align-top"
|
||||
>
|
||||
<td
|
||||
class="px-4 py-4 font-medium text-foreground"
|
||||
>
|
||||
{{ team.name }}
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Badge
|
||||
v-for="member in team.users"
|
||||
:key="member.id"
|
||||
variant="secondary"
|
||||
>
|
||||
{{ member.name }}
|
||||
</Badge>
|
||||
<span
|
||||
v-if="team.users.length === 0"
|
||||
class="text-muted-foreground"
|
||||
>
|
||||
No members assigned
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<Form
|
||||
v-bind="
|
||||
ProjectController.updateTeamPermissions.form(
|
||||
[project.id, team.id],
|
||||
)
|
||||
"
|
||||
class="flex flex-wrap gap-3"
|
||||
v-slot="{ processing }"
|
||||
>
|
||||
<label
|
||||
v-for="option in permissionOptions"
|
||||
:key="`${team.id}-${option.value}`"
|
||||
class="inline-flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="permissions[]"
|
||||
:value="option.value"
|
||||
:checked="
|
||||
hasPermission(
|
||||
teamPermissions,
|
||||
team.id,
|
||||
option.value,
|
||||
)
|
||||
"
|
||||
class="size-4 rounded border-input text-primary focus:ring-ring"
|
||||
/>
|
||||
<span>{{ option.label }}</span>
|
||||
</label>
|
||||
|
||||
<div class="w-full sm:hidden" />
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="processing"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Form>
|
||||
</td>
|
||||
<td
|
||||
class="px-4 py-4 text-right text-muted-foreground"
|
||||
>
|
||||
Inherited
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
Reference in New Issue
Block a user