feat(KAN-48): rebuild project access and permission assignment
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { computed, watch } from 'vue';
|
||||
import {
|
||||
updateTeamPermissions,
|
||||
updateUserPermissions,
|
||||
} from '@/actions/App/Http/Controllers/ProjectController';
|
||||
import FormFeedback from '@/components/FormFeedback.vue';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useFormProtection } from '@/composables/useFormProtection';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import type { PermissionOption } from '@/types';
|
||||
import {
|
||||
projectPermissionDescriptions,
|
||||
projectPermissionLabels,
|
||||
} from '@/types/project-access';
|
||||
import type { ProjectAccessTarget } from '@/types/project-access';
|
||||
|
||||
const props = defineProps<{
|
||||
projectId: number;
|
||||
target: ProjectAccessTarget | null;
|
||||
permissionOptions: PermissionOption[];
|
||||
}>();
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
const { t } = useLocalization();
|
||||
const form = useForm({ permissions: [] as string[] });
|
||||
const protection = useFormProtection(form, {
|
||||
isDirty: () => props.target !== null && form.isDirty,
|
||||
});
|
||||
const selectionError = computed(
|
||||
() =>
|
||||
Object.entries(form.errors).find(([key]) =>
|
||||
key.startsWith('permissions'),
|
||||
)?.[1],
|
||||
);
|
||||
const options = computed(() =>
|
||||
props.permissionOptions
|
||||
.filter((option) => option.value in projectPermissionLabels)
|
||||
.map((option) => ({
|
||||
value: option.value,
|
||||
label: t(
|
||||
projectPermissionLabels[
|
||||
option.value as keyof typeof projectPermissionLabels
|
||||
],
|
||||
),
|
||||
description: t(
|
||||
projectPermissionDescriptions[
|
||||
option.value as keyof typeof projectPermissionDescriptions
|
||||
],
|
||||
),
|
||||
})),
|
||||
);
|
||||
watch(
|
||||
() => props.target,
|
||||
(target) => {
|
||||
form.defaults({ permissions: [...(target?.permissions ?? [])] });
|
||||
form.resetAndClearErrors();
|
||||
protection.clearFeedback();
|
||||
},
|
||||
);
|
||||
function close(open: boolean): void {
|
||||
if (open || form.processing || !protection.confirmLeave()) {
|
||||
return;
|
||||
}
|
||||
form.resetAndClearErrors();
|
||||
emit('close');
|
||||
}
|
||||
function submit(): void {
|
||||
if (!props.target || form.processing) {
|
||||
return;
|
||||
}
|
||||
const route =
|
||||
props.target.kind === 'user'
|
||||
? updateUserPermissions([props.projectId, props.target.id])
|
||||
: updateTeamPermissions([props.projectId, props.target.id]);
|
||||
protection.submit(route, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.defaults();
|
||||
form.resetAndClearErrors();
|
||||
emit('close');
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="target !== null" @update:open="close">
|
||||
<DialogContent
|
||||
:show-close-button="!form.processing"
|
||||
@escape-key-down="form.processing && $event.preventDefault()"
|
||||
@interact-outside="form.processing && $event.preventDefault()"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle class="break-words">{{
|
||||
t('projectAccess.editFor', { name: target?.name ?? '' })
|
||||
}}</DialogTitle>
|
||||
<DialogDescription>{{
|
||||
t(
|
||||
target?.kind === 'team'
|
||||
? 'projectAccess.teamHelp'
|
||||
: 'projectAccess.directHelp',
|
||||
)
|
||||
}}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form class="grid min-w-0 gap-5" @submit.prevent="submit">
|
||||
<FormFeedback
|
||||
:state="protection.state.value"
|
||||
:title="
|
||||
protection.responseStatus.value === 403
|
||||
? t('projectAccess.forbidden')
|
||||
: undefined
|
||||
"
|
||||
:description="
|
||||
protection.responseStatus.value === 403
|
||||
? t('projectAccess.forbiddenHelp')
|
||||
: undefined
|
||||
"
|
||||
:retryable="protection.responseStatus.value !== 403"
|
||||
@retry="submit"
|
||||
/>
|
||||
<fieldset
|
||||
:disabled="form.processing"
|
||||
class="grid min-w-0 gap-3"
|
||||
:aria-invalid="!!selectionError"
|
||||
aria-describedby="project-permission-error"
|
||||
>
|
||||
<legend class="mb-3 text-sm font-semibold">
|
||||
{{
|
||||
t(
|
||||
target?.kind === 'team'
|
||||
? 'projectAccess.teamPermissions'
|
||||
: 'projectAccess.directPermissions',
|
||||
)
|
||||
}}
|
||||
</legend>
|
||||
<label
|
||||
v-for="option in options"
|
||||
:key="option.value"
|
||||
class="hover:bg-accent flex cursor-pointer items-start gap-3 rounded-lg border p-3"
|
||||
>
|
||||
<input
|
||||
v-model="form.permissions"
|
||||
type="checkbox"
|
||||
:value="option.value"
|
||||
:aria-label="option.label"
|
||||
class="accent-primary focus-visible:ring-ring mt-0.5 size-5 shrink-0 focus-visible:ring-2"
|
||||
/>
|
||||
<span class="grid gap-1"
|
||||
><span class="text-sm font-medium">{{
|
||||
option.label
|
||||
}}</span
|
||||
><span class="text-muted-foreground text-xs">{{
|
||||
option.description
|
||||
}}</span></span
|
||||
>
|
||||
</label>
|
||||
<InputError
|
||||
id="project-permission-error"
|
||||
:message="selectionError"
|
||||
/>
|
||||
</fieldset>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('projectAccess.clearHelp') }}
|
||||
</p>
|
||||
<p
|
||||
v-if="target?.globalAdmin"
|
||||
class="bg-accent text-accent-foreground rounded-lg p-3 text-sm"
|
||||
>
|
||||
{{ t('projectAccess.globalHelp') }}
|
||||
</p>
|
||||
<p class="text-muted-foreground text-xs">
|
||||
{{ t('projectAccess.selfHelp') }}
|
||||
</p>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:disabled="form.processing"
|
||||
@click="close(false)"
|
||||
>{{ t('common.cancel') }}</Button
|
||||
>
|
||||
<Button type="submit" :disabled="form.processing">{{
|
||||
t('projectAccess.save')
|
||||
}}</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import { projectPermissionLabels } from '@/types/project-access';
|
||||
|
||||
defineProps<{ permissions: string[]; emptyLabel: string }>();
|
||||
const { t } = useLocalization();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
<template
|
||||
v-for="(label, value) in projectPermissionLabels"
|
||||
:key="value"
|
||||
>
|
||||
<Badge v-if="permissions.includes(value)" variant="secondary">{{
|
||||
t(label)
|
||||
}}</Badge>
|
||||
</template>
|
||||
<span
|
||||
v-if="permissions.length === 0"
|
||||
class="text-muted-foreground text-sm"
|
||||
>{{ emptyLabel }}</span
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,4 +1,58 @@
|
||||
export const en = {
|
||||
'projectAccess.pageTitle': '{project} · Project access',
|
||||
'projectAccess.title': 'Project access',
|
||||
'projectAccess.description':
|
||||
'Manage who can access {project} and see where their permissions come from.',
|
||||
'projectAccess.back': 'Back to project',
|
||||
'projectAccess.saved': 'Project permissions saved.',
|
||||
'projectAccess.howItWorks': 'How project access works',
|
||||
'projectAccess.additiveHelp':
|
||||
'Direct user permissions and permissions from every team are combined. Write includes read; administrator includes write and read.',
|
||||
'projectAccess.limitsHelp':
|
||||
'Project administrators can change project assignments here. Global permissions and team membership are managed separately.',
|
||||
'projectAccess.search': 'Search people or teams',
|
||||
'projectAccess.people': 'People and effective access',
|
||||
'projectAccess.effective': 'Effective permissions',
|
||||
'projectAccess.noAccess': 'No project access',
|
||||
'projectAccess.globalSource':
|
||||
'Global administrator · all project permissions',
|
||||
'projectAccess.direct': 'Direct:',
|
||||
'projectAccess.none': 'None',
|
||||
'projectAccess.viaTeam': 'Via {name}:',
|
||||
'projectAccess.editFor': 'Edit access for {name}',
|
||||
'projectAccess.editDirect': 'Edit direct access',
|
||||
'projectAccess.editTeam': 'Edit team access',
|
||||
'projectAccess.teamPermissions': 'Team permissions',
|
||||
'projectAccess.directPermissions': 'Direct permissions',
|
||||
'projectAccess.teamHelp':
|
||||
'These project permissions apply to every current and future member of the team.',
|
||||
'projectAccess.directHelp':
|
||||
'Change only this person’s direct project permissions. Team and global permissions continue to apply.',
|
||||
'projectAccess.noPeopleResults': 'No matching people',
|
||||
'projectAccess.noPeople': 'No people available',
|
||||
'projectAccess.noTeamResults': 'No matching teams',
|
||||
'projectAccess.noTeams': 'No teams yet',
|
||||
'projectAccess.noTeamsHelp':
|
||||
'Create a team and add members before assigning shared project access.',
|
||||
'projectAccess.noTeamAccess': 'No project permissions assigned',
|
||||
'projectAccess.read': 'Read',
|
||||
'projectAccess.write': 'Write',
|
||||
'projectAccess.admin': 'Administrator',
|
||||
'projectAccess.readHelp': 'View the project and its tickets.',
|
||||
'projectAccess.writeHelp': 'Create and edit tickets. Includes read access.',
|
||||
'projectAccess.adminHelp':
|
||||
'Manage project access and project administration. Includes write and read access.',
|
||||
'projectAccess.clearHelp':
|
||||
'Clear all selections to remove this assignment. Access granted by other teams, direct assignments or global administration is preserved.',
|
||||
'projectAccess.globalHelp':
|
||||
'This person is a global administrator. Changing these project assignments cannot remove their global access.',
|
||||
'projectAccess.selfHelp':
|
||||
'If you remove your own administrator access, you will return to Projects.',
|
||||
'projectAccess.save': 'Save permissions',
|
||||
'projectAccess.forbidden': 'Project access can no longer be changed',
|
||||
'projectAccess.forbiddenHelp':
|
||||
'Your administrator permission may have changed. Close this dialog and reopen the project to check your current access.',
|
||||
|
||||
'notifications.title': 'Notifications',
|
||||
'notifications.pageTitle': '{project} · Notifications',
|
||||
'notifications.description':
|
||||
|
||||
@@ -1,308 +1,344 @@
|
||||
<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 { Head, Link, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, Search, ShieldCheck, Users } from 'lucide-vue-next';
|
||||
import { computed, ref } from 'vue';
|
||||
import FeedbackState from '@/components/FeedbackState.vue';
|
||||
import ProjectAccessEditorDialog from '@/components/projects/ProjectAccessEditorDialog.vue';
|
||||
import ProjectPermissionBadges from '@/components/projects/ProjectPermissionBadges.vue';
|
||||
import UserAvatar from '@/components/ui/avatar/UserAvatar.vue';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { access, index, show } from '@/routes/projects/index';
|
||||
import { general as generalSettings } from '@/routes/projects/settings';
|
||||
import { access, index, show } from '@/routes/projects';
|
||||
import { general } from '@/routes/projects/settings';
|
||||
import type { BreadcrumbItem, ProjectAccessPageProps } from '@/types';
|
||||
import type { ProjectAccessTarget } from '@/types/project-access';
|
||||
|
||||
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);
|
||||
const page = usePage();
|
||||
const { t } = useLocalization();
|
||||
const search = ref('');
|
||||
const target = ref<ProjectAccessTarget | null>(null);
|
||||
const breadcrumbs = computed<BreadcrumbItem[]>(() => [
|
||||
{ title: t('navigation.projects'), href: index() },
|
||||
{ title: props.project.name, href: show(props.project.id) },
|
||||
{ title: t('navigation.access'), href: access(props.project.id) },
|
||||
]);
|
||||
const matches = (value: string) =>
|
||||
value.toLocaleLowerCase().includes(search.value.trim().toLocaleLowerCase());
|
||||
const visibleUsers = computed(() =>
|
||||
props.users.filter((user) => matches(`${user.name} ${user.email}`)),
|
||||
);
|
||||
const visibleTeams = computed(() =>
|
||||
props.teams.filter((team) => matches(team.name)),
|
||||
);
|
||||
const inheritedTeams = (userId: number) =>
|
||||
props.teams.filter(
|
||||
(team) =>
|
||||
team.user_ids.includes(userId) &&
|
||||
(props.teamPermissions[team.id] ?? []).length > 0,
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :breadcrumbs="breadcrumbs">
|
||||
<Head :title="`${project.name} access`" />
|
||||
|
||||
<div class="flex flex-1 flex-col gap-6 p-4">
|
||||
<div
|
||||
<Head
|
||||
:title="t('projectAccess.pageTitle', { project: project.name })"
|
||||
/>
|
||||
<main
|
||||
class="mx-auto flex w-full min-w-0 max-w-7xl flex-1 flex-col gap-6 p-4 sm:p-6 lg:p-8"
|
||||
>
|
||||
<header
|
||||
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">
|
||||
<div class="grid min-w-0 gap-2">
|
||||
<p
|
||||
class="text-primary break-all text-xs font-semibold uppercase tracking-wider"
|
||||
>
|
||||
{{ project.key }}
|
||||
</Badge>
|
||||
<Heading
|
||||
:title="`${project.name} access`"
|
||||
description="Assign direct user permissions or inherited team permissions for this project."
|
||||
/>
|
||||
</p>
|
||||
<h1 class="text-headline-mobile sm:text-headline">
|
||||
{{ t('projectAccess.title') }}
|
||||
</h1>
|
||||
<p
|
||||
class="text-muted-foreground max-w-2xl break-words text-sm"
|
||||
>
|
||||
{{
|
||||
t('projectAccess.description', {
|
||||
project: project.name,
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<div class="flex shrink-0 flex-wrap gap-2">
|
||||
<Button
|
||||
v-if="$page.props.auth.permissions.globalAdmin"
|
||||
v-if="page.props.auth.permissions.globalAdmin"
|
||||
as-child
|
||||
variant="outline"
|
||||
><Link :href="general(project.id)">{{
|
||||
t('navigation.general')
|
||||
}}</Link></Button
|
||||
>
|
||||
<Button as-child variant="outline"
|
||||
><Link :href="show(project.id)"
|
||||
><ArrowLeft class="size-4" aria-hidden="true" />{{
|
||||
t('projectAccess.back')
|
||||
}}</Link
|
||||
></Button
|
||||
>
|
||||
<Link :href="generalSettings(project.id)">
|
||||
General settings
|
||||
</Link>
|
||||
</Button>
|
||||
|
||||
<Button as-child variant="outline">
|
||||
<Link :href="show(project.id)">Back to project</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
</header>
|
||||
<FeedbackState
|
||||
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"
|
||||
state="success"
|
||||
:title="t('projectAccess.saved')"
|
||||
/>
|
||||
<aside
|
||||
class="bg-accent/60 flex items-start gap-3 rounded-xl border p-4"
|
||||
:aria-label="t('projectAccess.howItWorks')"
|
||||
>
|
||||
{{ status }}
|
||||
<ShieldCheck
|
||||
class="text-primary mt-0.5 size-5 shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="grid gap-1">
|
||||
<h2 class="text-sm font-semibold">
|
||||
{{ t('projectAccess.howItWorks') }}
|
||||
</h2>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('projectAccess.additiveHelp') }}
|
||||
</p>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('projectAccess.limitsHelp') }}
|
||||
</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="relative sm:max-w-md">
|
||||
<Label for="access-search" class="sr-only">{{
|
||||
t('projectAccess.search')
|
||||
}}</Label
|
||||
><Search
|
||||
class="text-muted-foreground pointer-events-none absolute left-3 top-3 size-4"
|
||||
aria-hidden="true"
|
||||
/><Input
|
||||
id="access-search"
|
||||
v-model="search"
|
||||
type="search"
|
||||
class="pl-9"
|
||||
:placeholder="t('projectAccess.search')"
|
||||
/>
|
||||
</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="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">
|
||||
Permissions
|
||||
</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="text-foreground px-4 py-4 font-medium"
|
||||
>
|
||||
{{ user.name }}
|
||||
</td>
|
||||
<td class="text-muted-foreground px-4 py-4">
|
||||
{{ 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="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(
|
||||
directPermissions,
|
||||
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>
|
||||
</td>
|
||||
<td
|
||||
class="text-muted-foreground px-4 py-4 text-right"
|
||||
>
|
||||
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="text-muted-foreground p-6 text-sm"
|
||||
<section
|
||||
class="grid min-w-0 gap-4"
|
||||
aria-labelledby="people-heading"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 id="people-heading" class="text-lg font-semibold">
|
||||
{{ t('projectAccess.people') }}
|
||||
</h2>
|
||||
<Badge variant="secondary">{{ users.length }}</Badge>
|
||||
</div>
|
||||
<FeedbackState
|
||||
v-if="visibleUsers.length === 0"
|
||||
state="empty"
|
||||
:title="
|
||||
t(
|
||||
users.length
|
||||
? 'projectAccess.noPeopleResults'
|
||||
: 'projectAccess.noPeople',
|
||||
)
|
||||
"
|
||||
/>
|
||||
<ul
|
||||
v-else
|
||||
class="bg-card min-w-0 divide-y rounded-xl border"
|
||||
:aria-label="t('projectAccess.people')"
|
||||
>
|
||||
<li
|
||||
v-for="user in visibleUsers"
|
||||
:key="user.id"
|
||||
class="grid min-w-0 gap-4 p-4 sm:p-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.3fr)_auto] lg:items-center"
|
||||
:data-user-id="user.id"
|
||||
>
|
||||
No teams exist yet. Create teams first to assign
|
||||
inherited permissions.
|
||||
</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">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-border divide-y">
|
||||
<tr
|
||||
v-for="team in teams"
|
||||
:key="team.id"
|
||||
class="bg-background align-top"
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<UserAvatar :user="user" class="size-10 shrink-0" />
|
||||
<div class="grid min-w-0 gap-1">
|
||||
<h3 class="break-words text-sm font-semibold">
|
||||
{{ user.name }}
|
||||
</h3>
|
||||
<p
|
||||
class="text-muted-foreground break-all text-xs"
|
||||
>
|
||||
<td
|
||||
class="text-foreground px-4 py-4 font-medium"
|
||||
>
|
||||
{{ 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="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(
|
||||
teamPermissions,
|
||||
team.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>
|
||||
</td>
|
||||
<td
|
||||
class="text-muted-foreground px-4 py-4 text-right"
|
||||
>
|
||||
Inherited
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{ user.email }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid min-w-0 gap-2">
|
||||
<p
|
||||
class="text-muted-foreground text-xs font-medium"
|
||||
>
|
||||
{{ t('projectAccess.effective') }}
|
||||
</p>
|
||||
<ProjectPermissionBadges
|
||||
:permissions="
|
||||
effectivePermissions[user.id] ?? []
|
||||
"
|
||||
:empty-label="t('projectAccess.noAccess')"
|
||||
/>
|
||||
<div
|
||||
class="text-muted-foreground grid gap-1 text-xs"
|
||||
>
|
||||
<span
|
||||
v-if="globalAdminUserIds.includes(user.id)"
|
||||
>{{ t('projectAccess.globalSource') }}</span
|
||||
>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span>{{ t('projectAccess.direct') }}</span
|
||||
><ProjectPermissionBadges
|
||||
:permissions="
|
||||
directPermissions[user.id] ?? []
|
||||
"
|
||||
:empty-label="t('projectAccess.none')"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-for="team in inheritedTeams(user.id)"
|
||||
:key="team.id"
|
||||
class="flex min-w-0 flex-wrap items-center gap-2"
|
||||
>
|
||||
<span class="break-words">{{
|
||||
t('projectAccess.viaTeam', {
|
||||
name: team.name,
|
||||
})
|
||||
}}</span
|
||||
><ProjectPermissionBadges
|
||||
:permissions="
|
||||
teamPermissions[team.id] ?? []
|
||||
"
|
||||
:empty-label="t('projectAccess.none')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:aria-label="
|
||||
t('projectAccess.editFor', { name: user.name })
|
||||
"
|
||||
@click="
|
||||
target = {
|
||||
kind: 'user',
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
permissions:
|
||||
directPermissions[user.id] ?? [],
|
||||
globalAdmin: globalAdminUserIds.includes(
|
||||
user.id,
|
||||
),
|
||||
}
|
||||
"
|
||||
>{{ t('projectAccess.editDirect') }}</Button
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="grid min-w-0 gap-4" aria-labelledby="teams-heading">
|
||||
<div class="grid gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 id="teams-heading" class="text-lg font-semibold">
|
||||
{{ t('projectAccess.teamPermissions') }}
|
||||
</h2>
|
||||
<Badge variant="secondary">{{ teams.length }}</Badge>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('projectAccess.teamHelp') }}
|
||||
</p>
|
||||
</div>
|
||||
<FeedbackState
|
||||
v-if="visibleTeams.length === 0"
|
||||
state="empty"
|
||||
:title="
|
||||
t(
|
||||
teams.length
|
||||
? 'projectAccess.noTeamResults'
|
||||
: 'projectAccess.noTeams',
|
||||
)
|
||||
"
|
||||
:description="
|
||||
teams.length
|
||||
? undefined
|
||||
: t('projectAccess.noTeamsHelp')
|
||||
"
|
||||
/>
|
||||
<ul
|
||||
v-else
|
||||
class="grid min-w-0 gap-4 lg:grid-cols-2"
|
||||
:aria-label="t('projectAccess.teamPermissions')"
|
||||
>
|
||||
<li
|
||||
v-for="team in visibleTeams"
|
||||
:key="team.id"
|
||||
class="bg-card grid min-w-0 gap-4 rounded-xl border p-5"
|
||||
:data-team-id="team.id"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span
|
||||
class="bg-accent text-primary flex size-10 shrink-0 items-center justify-center rounded-lg"
|
||||
><Users class="size-5" aria-hidden="true"
|
||||
/></span>
|
||||
<div class="min-w-0">
|
||||
<h3 class="break-words text-sm font-semibold">
|
||||
{{ team.name }}
|
||||
</h3>
|
||||
<p class="text-muted-foreground text-xs">
|
||||
{{
|
||||
t('teams.memberCount', {
|
||||
count: team.users.length,
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<ProjectPermissionBadges
|
||||
:permissions="teamPermissions[team.id] ?? []"
|
||||
:empty-label="t('projectAccess.noTeamAccess')"
|
||||
/>
|
||||
<p class="text-muted-foreground break-words text-xs">
|
||||
{{
|
||||
team.users
|
||||
.map((user) => user.name)
|
||||
.join(', ') || t('teams.noMembers')
|
||||
}}
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:aria-label="
|
||||
t('projectAccess.editFor', { name: team.name })
|
||||
"
|
||||
@click="
|
||||
target = {
|
||||
kind: 'team',
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
permissions: teamPermissions[team.id] ?? [],
|
||||
}
|
||||
"
|
||||
>{{ t('projectAccess.editTeam') }}</Button
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<ProjectAccessEditorDialog
|
||||
:project-id="project.id"
|
||||
:target="target"
|
||||
:permission-options="permissionOptions"
|
||||
@close="target = null"
|
||||
/>
|
||||
</main>
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
||||
@@ -117,6 +117,8 @@ export type PermissionOption = {
|
||||
|
||||
export type ProjectAccessPageProps = {
|
||||
directPermissions: Record<string, string[]>;
|
||||
effectivePermissions: Record<string, string[]>;
|
||||
globalAdminUserIds: number[];
|
||||
permissionOptions: PermissionOption[];
|
||||
project: ProjectModel;
|
||||
status?: string | null;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export const projectPermissionLabels = {
|
||||
'project:read': 'projectAccess.read',
|
||||
'project:write': 'projectAccess.write',
|
||||
'project:admin': 'projectAccess.admin',
|
||||
} as const;
|
||||
|
||||
export const projectPermissionDescriptions = {
|
||||
'project:read': 'projectAccess.readHelp',
|
||||
'project:write': 'projectAccess.writeHelp',
|
||||
'project:admin': 'projectAccess.adminHelp',
|
||||
} as const;
|
||||
|
||||
export type ProjectAccessTarget = {
|
||||
kind: 'user' | 'team';
|
||||
id: number;
|
||||
name: string;
|
||||
permissions: string[];
|
||||
globalAdmin?: boolean;
|
||||
};
|
||||
Reference in New Issue
Block a user