Phase 6 (Teil 1): Dokumente und Organigramm
- Dokumente-Plugin: Ordnerbaum mit vererbten Rechten und Sichtbarkeit, Hochladen per Ziehen und Ablegen, Versionen, Suche, Pagebuilder-Block - Organigramm aus den Vorgesetzten, Vorgesetzte im Admin pflegbar - Personensuche im Kopf übernimmt nur noch Suchbegriffe des Verzeichnisses Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
21c706e5f5
commit
d6d5d4b0fe
110 changed files with 2209 additions and 208 deletions
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('document_folders', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('parent_id')->nullable()->constrained('document_folders')->restrictOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('description', 500)->nullable();
|
||||
$table->unsignedInteger('sort')->default(0);
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['parent_id', 'sort']);
|
||||
});
|
||||
|
||||
Schema::create('documents', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('folder_id')->constrained('document_folders')->restrictOnDelete();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
// Aktuelle Fassung; ältere bleiben in document_versions abrufbar.
|
||||
$table->unsignedBigInteger('current_version_id')->nullable();
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['folder_id', 'title']);
|
||||
});
|
||||
|
||||
Schema::create('document_versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('document_id')->constrained('documents')->cascadeOnDelete();
|
||||
$table->unsignedInteger('version');
|
||||
$table->string('name');
|
||||
$table->string('path');
|
||||
$table->string('mime', 150)->nullable();
|
||||
$table->unsignedBigInteger('size')->default(0);
|
||||
$table->string('note', 500)->nullable();
|
||||
$table->foreignId('uploaded_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->unique(['document_id', 'version']);
|
||||
$table->index('name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('document_versions');
|
||||
Schema::dropIfExists('documents');
|
||||
Schema::dropIfExists('document_folders');
|
||||
}
|
||||
};
|
||||
13
plugins-core/documents/plugin.json
Normal file
13
plugins-core/documents/plugin.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"slug": "documents",
|
||||
"name": "Dokumente",
|
||||
"version": "1.0.0",
|
||||
"description": "Dokumentenablage mit Ordnern, Versionen, Suche und Rechten je Ordner – z. B. Formulare, Dienstanweisungen, Handbücher.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\Documents\\",
|
||||
"class": "Inhaus\\Plugins\\Documents\\DocumentsPlugin",
|
||||
"requires": {
|
||||
"core": ">=0.8.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
32
plugins-core/documents/resources/js/blocks/FolderBlock.vue
Normal file
32
plugins-core/documents/resources/js/blocks/FolderBlock.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { ChevronRight, Download } from '@lucide/vue';
|
||||
import FileIcon from '../components/FileIcon.vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const formatSize = (bytes) => (bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="block.props">
|
||||
<div v-if="block.data.title" class="mb-3 flex items-center justify-between gap-4">
|
||||
<h3 class="text-lg font-semibold">{{ block.data.title }}</h3>
|
||||
<Link :href="block.props.folder_url" class="inline-flex items-center gap-0.5 text-[13px] font-medium text-brand-text hover:underline">Zum Ordner <ChevronRight class="size-3.5" /></Link>
|
||||
</div>
|
||||
<ul class="divide-y rounded-lg border bg-card">
|
||||
<li v-for="doc in block.props.documents" :key="doc.id">
|
||||
<a :href="doc.download_url" class="group flex items-center gap-3 px-4 py-3 hover:bg-accent/50">
|
||||
<FileIcon :extension="doc.extension" />
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-sm font-medium group-hover:underline">{{ doc.title }}</span>
|
||||
<span v-if="block.data.show_description && doc.description" class="block truncate text-[13px] text-muted-foreground">{{ doc.description }}</span>
|
||||
<span class="block text-xs text-muted-foreground">{{ doc.extension }} · {{ formatSize(doc.size) }}</span>
|
||||
</span>
|
||||
<Download class="size-4 shrink-0 text-muted-foreground" />
|
||||
</a>
|
||||
</li>
|
||||
<li v-if="!block.props.documents.length" class="px-4 py-3 text-sm text-muted-foreground">Keine Dokumente in diesem Ordner.</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
37
plugins-core/documents/resources/js/components/FileIcon.vue
Normal file
37
plugins-core/documents/resources/js/components/FileIcon.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { File, FileArchive, FileImage, FileSpreadsheet, FileText, Presentation } from '@lucide/vue';
|
||||
|
||||
/**
|
||||
* Symbol und Farbe nach Dateityp – so erkennt man Word, Excel, PDF auf einen Blick.
|
||||
*/
|
||||
const props = defineProps({
|
||||
extension: { type: String, default: '' },
|
||||
});
|
||||
|
||||
const kinds = {
|
||||
PDF: { icon: FileText, class: 'bg-red-50 text-red-700 dark:bg-red-950/50 dark:text-red-300' },
|
||||
DOC: { icon: FileText, class: 'bg-sky-50 text-sky-700 dark:bg-sky-950/50 dark:text-sky-300' },
|
||||
DOCX: { icon: FileText, class: 'bg-sky-50 text-sky-700 dark:bg-sky-950/50 dark:text-sky-300' },
|
||||
ODT: { icon: FileText, class: 'bg-sky-50 text-sky-700 dark:bg-sky-950/50 dark:text-sky-300' },
|
||||
XLS: { icon: FileSpreadsheet, class: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300' },
|
||||
XLSX: { icon: FileSpreadsheet, class: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300' },
|
||||
CSV: { icon: FileSpreadsheet, class: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300' },
|
||||
ODS: { icon: FileSpreadsheet, class: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300' },
|
||||
PPT: { icon: Presentation, class: 'bg-orange-50 text-orange-700 dark:bg-orange-950/50 dark:text-orange-300' },
|
||||
PPTX: { icon: Presentation, class: 'bg-orange-50 text-orange-700 dark:bg-orange-950/50 dark:text-orange-300' },
|
||||
JPG: { icon: FileImage, class: 'bg-violet-50 text-violet-700 dark:bg-violet-950/50 dark:text-violet-300' },
|
||||
JPEG: { icon: FileImage, class: 'bg-violet-50 text-violet-700 dark:bg-violet-950/50 dark:text-violet-300' },
|
||||
PNG: { icon: FileImage, class: 'bg-violet-50 text-violet-700 dark:bg-violet-950/50 dark:text-violet-300' },
|
||||
ZIP: { icon: FileArchive, class: 'bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300' },
|
||||
};
|
||||
|
||||
const kind = computed(() => kinds[props.extension?.toUpperCase()] ?? { icon: File, class: 'bg-muted text-muted-foreground' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="relative grid size-10 shrink-0 place-items-center rounded-md" :class="kind.class">
|
||||
<component :is="kind.icon" class="size-5" />
|
||||
<span v-if="extension" class="absolute -bottom-1 rounded bg-card px-1 text-[9px] leading-tight font-bold text-current ring-1 ring-border">{{ extension }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Folder, FolderOpen } from '@lucide/vue';
|
||||
|
||||
defineProps({
|
||||
items: { type: Array, required: true },
|
||||
currentId: { type: Number, default: null },
|
||||
openIds: { type: Array, default: () => [] },
|
||||
depth: { type: Number, default: 0 },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul class="grid gap-0.5" :class="depth ? 'ml-3 border-l pl-2' : ''">
|
||||
<li v-for="item in items" :key="item.id">
|
||||
<Link
|
||||
:href="`/dokumente/ordner/${item.id}`"
|
||||
class="flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm"
|
||||
:class="item.id === currentId ? 'bg-brand-soft font-medium text-brand-soft-foreground' : 'text-foreground/80 hover:bg-accent hover:text-foreground'"
|
||||
preserve-scroll
|
||||
>
|
||||
<FolderOpen v-if="item.id === currentId || openIds.includes(item.id)" class="size-4 shrink-0" />
|
||||
<Folder v-else class="size-4 shrink-0" />
|
||||
<span class="truncate">{{ item.name }}</span>
|
||||
</Link>
|
||||
<FolderTreeNav
|
||||
v-if="item.children.length && (item.id === currentId || openIds.includes(item.id))"
|
||||
:items="item.children"
|
||||
:current-id="currentId"
|
||||
:open-ids="openIds"
|
||||
:depth="depth + 1"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
327
plugins-core/documents/resources/js/pages/Index.vue
Normal file
327
plugins-core/documents/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
|
||||
import { ChevronRight, Download, EllipsisVertical, FilePlus2, Folder, FolderPlus, History, LoaderCircle, PencilLine, Search, Trash2, Upload, X } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { http } from '@/lib/http';
|
||||
import { formatRelative, formatShortDate } from '@/lib/format';
|
||||
import FileIcon from '../components/FileIcon.vue';
|
||||
import FolderTreeNav from '../components/FolderTreeNav.vue';
|
||||
|
||||
const props = defineProps({
|
||||
tree: { type: Array, required: true },
|
||||
folder: { type: Object, default: null },
|
||||
breadcrumbs: { type: Array, default: () => [] },
|
||||
children: { type: Array, default: () => [] },
|
||||
documents: { type: Array, default: () => [] },
|
||||
search: { type: String, default: '' },
|
||||
canCreateRoot: { type: Boolean, default: false },
|
||||
folderOptions: { type: Array, default: () => [] },
|
||||
maxUploadMb: { type: Number, default: 20 },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const openIds = computed(() => props.breadcrumbs.map((b) => b.id));
|
||||
const canEdit = computed(() => !!props.folder?.can_edit);
|
||||
const title = computed(() => (props.search ? `Suche: ${props.search}` : props.folder?.name ?? 'Dokumente'));
|
||||
|
||||
const formatSize = (bytes) => (bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
||||
|
||||
// Suche
|
||||
const query = ref(props.search);
|
||||
function submitSearch() {
|
||||
router.get(props.folder ? `/dokumente/ordner/${props.folder.id}` : '/dokumente', query.value.trim() ? { q: query.value.trim() } : {}, { preserveState: true });
|
||||
}
|
||||
|
||||
// Hochladen (auch per Ziehen und Ablegen)
|
||||
const upload = useForm({ files: [] });
|
||||
const dragging = ref(false);
|
||||
const fileInput = ref(null);
|
||||
|
||||
function sendFiles(files) {
|
||||
if (!canEdit.value || !files.length) return;
|
||||
|
||||
const tooLarge = files.find((f) => f.size > props.maxUploadMb * 1024 * 1024);
|
||||
if (tooLarge) {
|
||||
toast.error(`„${tooLarge.name}“ ist größer als ${props.maxUploadMb} MB.`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
upload.files = files;
|
||||
upload.post(`/dokumente/ordner/${props.folder.id}/dateien`, {
|
||||
forceFormData: true,
|
||||
preserveScroll: true,
|
||||
onError: (errors) => toast.error(Object.values(errors)[0]),
|
||||
onFinish: () => upload.reset(),
|
||||
});
|
||||
}
|
||||
|
||||
function onDrop(event) {
|
||||
dragging.value = false;
|
||||
sendFiles([...(event.dataTransfer?.files ?? [])]);
|
||||
}
|
||||
|
||||
// Neue Fassung
|
||||
const versionFor = ref(null);
|
||||
const versionForm = useForm({ file: null, note: '' });
|
||||
|
||||
function submitVersion() {
|
||||
versionForm.post(`/dokumente/${versionFor.value.id}/versionen`, {
|
||||
forceFormData: true,
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
versionFor.value = null;
|
||||
versionForm.reset();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Bearbeiten
|
||||
const editing = ref(null);
|
||||
const editForm = useForm({ title: '', description: '', folder_id: null });
|
||||
|
||||
function edit(doc) {
|
||||
editing.value = doc;
|
||||
editForm.defaults({ title: doc.title, description: doc.description ?? '', folder_id: doc.folder_id });
|
||||
editForm.reset();
|
||||
editForm.clearErrors();
|
||||
}
|
||||
|
||||
function submitEdit() {
|
||||
editForm.put(`/dokumente/${editing.value.id}`, { preserveScroll: true, onSuccess: () => (editing.value = null) });
|
||||
}
|
||||
|
||||
function remove(doc) {
|
||||
if (window.confirm(`„${doc.title}“ mit allen Fassungen löschen?`)) {
|
||||
router.delete(`/dokumente/${doc.id}`, { preserveScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
// Fassungen
|
||||
const history = ref(null);
|
||||
const versions = ref([]);
|
||||
|
||||
async function showVersions(doc) {
|
||||
history.value = doc;
|
||||
versions.value = [];
|
||||
versions.value = (await http.get(`/dokumente/${doc.id}/versionen`)).versions;
|
||||
}
|
||||
|
||||
// Ordner
|
||||
const folderDialog = ref(null); // 'new' | 'rename'
|
||||
const folderForm = useForm({ name: '', parent_id: null });
|
||||
|
||||
function openFolderDialog(mode) {
|
||||
folderDialog.value = mode;
|
||||
folderForm.clearErrors();
|
||||
folderForm.name = mode === 'rename' ? props.folder.name : '';
|
||||
folderForm.parent_id = mode === 'new' ? props.folder?.id ?? null : null;
|
||||
}
|
||||
|
||||
function submitFolder() {
|
||||
if (folderDialog.value === 'rename') {
|
||||
folderForm.transform((data) => ({ name: data.name, description: props.folder.description })).put(`/dokumente/ordner/${props.folder.id}`, { onSuccess: () => (folderDialog.value = null) });
|
||||
} else {
|
||||
folderForm.transform((data) => data).post('/dokumente/ordner', { onSuccess: () => (folderDialog.value = null) });
|
||||
}
|
||||
}
|
||||
|
||||
function deleteFolder() {
|
||||
if (window.confirm(`Ordner „${props.folder.name}“ löschen?`)) {
|
||||
router.delete(`/dokumente/ordner/${props.folder.id}`, { onError: (errors) => toast.error(Object.values(errors)[0]) });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="title">
|
||||
<div class="grid gap-6 lg:grid-cols-[260px_minmax(0,1fr)]">
|
||||
<aside class="hidden lg:block">
|
||||
<nav class="sticky top-24 rounded-lg border bg-card p-2" aria-label="Ordner">
|
||||
<Link href="/dokumente" class="mb-1 block rounded-md px-2.5 py-1.5 text-sm font-semibold hover:bg-accent" :class="!folder && !search ? 'bg-brand-soft text-brand-soft-foreground' : ''">Alle Ordner</Link>
|
||||
<FolderTreeNav :items="tree" :current-id="folder?.id ?? null" :open-ids="openIds" />
|
||||
<p v-if="!tree.length" class="px-2.5 py-2 text-[13px] text-muted-foreground">Noch keine Ordner.</p>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<section
|
||||
class="min-w-0"
|
||||
@dragover.prevent="canEdit && (dragging = true)"
|
||||
@dragleave.self="dragging = false"
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<nav class="mb-2 flex flex-wrap items-center gap-1 text-[13px] text-muted-foreground" aria-label="Brotkrumen">
|
||||
<Link href="/dokumente" class="hover:text-foreground hover:underline">Dokumente</Link>
|
||||
<template v-for="crumb in breadcrumbs" :key="crumb.id">
|
||||
<ChevronRight class="size-3.5" />
|
||||
<Link :href="`/dokumente/ordner/${crumb.id}`" class="hover:text-foreground hover:underline">{{ crumb.name }}</Link>
|
||||
</template>
|
||||
</nav>
|
||||
|
||||
<div class="mb-5 flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">{{ title }}</h1>
|
||||
<p v-if="folder?.description && !search" class="mt-1 text-sm text-muted-foreground">{{ folder.description }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<form class="relative" role="search" @submit.prevent="submitSearch">
|
||||
<Search class="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input v-model="query" type="search" class="w-56 pl-9" placeholder="Dokumente durchsuchen …" aria-label="Dokumente durchsuchen" />
|
||||
</form>
|
||||
<Button v-if="canEdit" :disabled="upload.processing" @click="fileInput?.click()">
|
||||
<LoaderCircle v-if="upload.processing" class="animate-spin" />
|
||||
<Upload v-else /> Hochladen
|
||||
</Button>
|
||||
<input ref="fileInput" type="file" multiple class="hidden" @change="sendFiles([...$event.target.files]); $event.target.value = ''" />
|
||||
<DropdownMenu v-if="canEdit || (!folder && canCreateRoot)">
|
||||
<DropdownMenuTrigger as-child><Button variant="outline" size="icon" aria-label="Ordner-Aktionen"><EllipsisVertical /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem @select="openFolderDialog('new')"><FolderPlus /> {{ folder ? 'Unterordner anlegen' : 'Ordner anlegen' }}</DropdownMenuItem>
|
||||
<template v-if="folder && canEdit">
|
||||
<DropdownMenuItem @select="openFolderDialog('rename')"><PencilLine /> Ordner umbenennen</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="folder.can_delete" />
|
||||
<DropdownMenuItem v-if="folder.can_delete" class="text-destructive" @select="deleteFolder"><Trash2 /> Ordner löschen</DropdownMenuItem>
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="upload.processing && upload.progress" class="mb-4 h-1.5 overflow-hidden rounded-full bg-muted" role="progressbar" :aria-valuenow="upload.progress.percentage">
|
||||
<div class="h-full bg-brand transition-all" :style="{ width: `${upload.progress.percentage}%` }" />
|
||||
</div>
|
||||
|
||||
<div v-if="dragging" class="mb-4 grid place-items-center rounded-lg border-2 border-dashed border-brand-400 bg-brand-soft/60 py-10 text-sm font-medium text-brand-soft-foreground">
|
||||
Dateien hier ablegen, um sie in „{{ folder.name }}“ hochzuladen
|
||||
</div>
|
||||
|
||||
<div v-if="children.length && !search" class="mb-5 grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
|
||||
<Link v-for="child in children" :key="child.id" :href="`/dokumente/ordner/${child.id}`" class="group flex items-center gap-3 rounded-lg border bg-card p-3.5 hover:border-brand-300">
|
||||
<span class="grid size-10 place-items-center rounded-md bg-brand-soft text-brand-text"><Folder class="size-5" /></span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-sm font-medium group-hover:underline">{{ child.name }}</span>
|
||||
<span class="text-xs text-muted-foreground">{{ child.count }} {{ child.count === 1 ? 'Eintrag' : 'Einträge' }}</span>
|
||||
</span>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div v-if="documents.length" class="divide-y rounded-lg border bg-card">
|
||||
<div v-for="doc in documents" :key="doc.id" class="flex items-center gap-3 px-4 py-3">
|
||||
<FileIcon :extension="doc.extension" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<a v-if="doc.download_url" :href="doc.download_url" class="block truncate text-sm font-medium hover:underline">{{ doc.title }}</a>
|
||||
<span v-else class="block truncate text-sm font-medium">{{ doc.title }}</span>
|
||||
<p v-if="doc.description" class="truncate text-[13px] text-muted-foreground">{{ doc.description }}</p>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ doc.extension }} · {{ formatSize(doc.size) }} · {{ formatShortDate(doc.updated_at) }}
|
||||
<template v-if="doc.version > 1"> · Fassung {{ doc.version }}</template>
|
||||
</p>
|
||||
</div>
|
||||
<Button v-if="doc.download_url" variant="ghost" size="icon" as-child :title="`${doc.title} herunterladen`"><a :href="doc.download_url"><Download /></a></Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child><Button variant="ghost" size="icon" :aria-label="`Aktionen für ${doc.title}`"><EllipsisVertical /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem @select="showVersions(doc)"><History /> Fassungen</DropdownMenuItem>
|
||||
<template v-if="canEdit || search">
|
||||
<DropdownMenuItem v-if="canEdit" @select="versionFor = doc; versionForm.reset()"><FilePlus2 /> Neue Fassung hochladen</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="canEdit" @select="edit(doc)"><PencilLine /> Bearbeiten oder verschieben</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="canEdit" />
|
||||
<DropdownMenuItem v-if="canEdit" class="text-destructive" @select="remove(doc)"><Trash2 /> Löschen</DropdownMenuItem>
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="search" class="rounded-lg border bg-card"><EmptyState :icon="Search" title="Keine Treffer" :text="`Nichts gefunden zu „${search}“.`" /></div>
|
||||
<div v-else-if="folder && !children.length" class="rounded-lg border border-dashed bg-card">
|
||||
<EmptyState :icon="Folder" title="Dieser Ordner ist leer" :text="canEdit ? 'Dateien hierher ziehen oder „Hochladen“ wählen.' : ''" />
|
||||
</div>
|
||||
<div v-else-if="!folder && !tree.length" class="rounded-lg border bg-card"><EmptyState :icon="Folder" title="Noch keine Dokumente" /></div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Neue Fassung -->
|
||||
<Dialog :open="!!versionFor" @update:open="(v) => !v && (versionFor = null)">
|
||||
<DialogContent class="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Neue Fassung</DialogTitle>
|
||||
<DialogDescription>„{{ versionFor?.title }}“ – die bisherige Fassung bleibt unter „Fassungen“ abrufbar.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form class="grid gap-4" @submit.prevent="submitVersion">
|
||||
<FormField id="version-file" label="Datei" :error="versionForm.errors.file">
|
||||
<input id="version-file" type="file" class="text-sm" @change="versionForm.file = $event.target.files[0]" />
|
||||
</FormField>
|
||||
<FormField id="version-note" label="Was hat sich geändert? (optional)" :error="versionForm.errors.note">
|
||||
<Input id="version-note" v-model="versionForm.note" maxlength="500" />
|
||||
</FormField>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" @click="versionFor = null">Abbrechen</Button>
|
||||
<Button type="submit" :disabled="!versionForm.file || versionForm.processing">Hochladen</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<!-- Bearbeiten -->
|
||||
<Dialog :open="!!editing" @update:open="(v) => !v && (editing = null)">
|
||||
<DialogContent class="sm:max-w-lg">
|
||||
<DialogHeader><DialogTitle>Dokument bearbeiten</DialogTitle></DialogHeader>
|
||||
<form class="grid gap-4" @submit.prevent="submitEdit">
|
||||
<FormField id="doc-title" label="Titel" :error="editForm.errors.title"><Input id="doc-title" v-model="editForm.title" maxlength="250" /></FormField>
|
||||
<FormField id="doc-description" label="Beschreibung" :error="editForm.errors.description"><Textarea id="doc-description" v-model="editForm.description" rows="3" maxlength="2000" /></FormField>
|
||||
<FormField id="doc-folder" label="Ordner" :error="editForm.errors.folder_id"><NativeSelect id="doc-folder" v-model="editForm.folder_id" :options="folderOptions" /></FormField>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" @click="editing = null">Abbrechen</Button>
|
||||
<Button type="submit" :disabled="editForm.processing">Speichern</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<!-- Fassungen -->
|
||||
<Dialog :open="!!history" @update:open="(v) => !v && (history = null)">
|
||||
<DialogContent class="sm:max-w-lg">
|
||||
<DialogHeader><DialogTitle>Fassungen</DialogTitle><DialogDescription>{{ history?.title }}</DialogDescription></DialogHeader>
|
||||
<div v-if="!versions.length" class="grid place-items-center py-6"><LoaderCircle class="size-5 animate-spin text-muted-foreground" /></div>
|
||||
<ul v-else class="-mx-2 divide-y">
|
||||
<li v-for="v in versions" :key="v.version" class="flex items-center gap-3 px-2 py-2.5">
|
||||
<span class="grid size-8 place-items-center rounded-md bg-muted text-xs font-semibold">{{ v.version }}</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate text-sm">{{ v.name }} <span v-if="v.current" class="ml-1 rounded bg-brand-soft px-1.5 py-0.5 text-[11px] text-brand-soft-foreground">aktuell</span></p>
|
||||
<p class="text-xs text-muted-foreground">{{ formatRelative(v.created_at) }}<template v-if="v.uploader"> · {{ v.uploader }}</template> · {{ formatSize(v.size) }}</p>
|
||||
<p v-if="v.note" class="text-xs">{{ v.note }}</p>
|
||||
</div>
|
||||
<Button variant="ghost" size="icon" as-child :title="`Fassung ${v.version} herunterladen`"><a :href="v.download_url"><Download /></a></Button>
|
||||
</li>
|
||||
</ul>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<!-- Ordner -->
|
||||
<Dialog :open="!!folderDialog" @update:open="(v) => !v && (folderDialog = null)">
|
||||
<DialogContent class="sm:max-w-md">
|
||||
<DialogHeader><DialogTitle>{{ folderDialog === 'rename' ? 'Ordner umbenennen' : folder ? `Unterordner in „${folder.name}“` : 'Neuer Ordner' }}</DialogTitle></DialogHeader>
|
||||
<form class="grid gap-4" @submit.prevent="submitFolder">
|
||||
<FormField id="folder-name" label="Name" :error="folderForm.errors.name"><Input id="folder-name" v-model="folderForm.name" maxlength="120" autofocus /></FormField>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" @click="folderDialog = null">Abbrechen</Button>
|
||||
<Button type="submit" :disabled="folderForm.processing || !folderForm.name.trim()">Speichern</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</AppLayout>
|
||||
</template>
|
||||
18
plugins-core/documents/routes/web.php
Normal file
18
plugins-core/documents/routes/web.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Documents\Http\Controllers\DocumentController;
|
||||
|
||||
Route::middleware('auth')->prefix('dokumente')->name('documents.')->controller(DocumentController::class)->where(['document' => '[0-9]+', 'folder' => '[0-9]+', 'version' => '[0-9]+'])->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/ordner/{folder}', 'folder')->name('folder');
|
||||
Route::post('/ordner', 'storeFolder')->name('folders.store');
|
||||
Route::put('/ordner/{folder}', 'updateFolder')->name('folders.update');
|
||||
Route::delete('/ordner/{folder}', 'destroyFolder')->name('folders.destroy');
|
||||
Route::post('/ordner/{folder}/dateien', 'upload')->name('upload');
|
||||
Route::put('/{document}', 'update')->name('update');
|
||||
Route::delete('/{document}', 'destroy')->name('destroy');
|
||||
Route::post('/{document}/versionen', 'newVersion')->name('versions.store');
|
||||
Route::get('/{document}/versionen', 'versions')->name('versions');
|
||||
Route::get('/{document}/herunterladen/{version}/{name}', 'download')->name('download');
|
||||
});
|
||||
29
plugins-core/documents/src/DocumentPresenter.php
Normal file
29
plugins-core/documents/src/DocumentPresenter.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents;
|
||||
|
||||
use Inhaus\Plugins\Documents\Models\Document;
|
||||
|
||||
final class DocumentPresenter
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function row(Document $document): array
|
||||
{
|
||||
$version = $document->currentVersion;
|
||||
|
||||
return [
|
||||
'id' => $document->id,
|
||||
'title' => $document->title,
|
||||
'description' => $document->description,
|
||||
'folder_id' => $document->folder_id,
|
||||
'version' => $version?->version,
|
||||
'name' => $version?->name,
|
||||
'extension' => $version?->extension(),
|
||||
'size' => (int) ($version?->size ?? 0),
|
||||
'updated_at' => ($version?->created_at ?? $document->updated_at)?->toIso8601String(),
|
||||
'download_url' => $version ? $document->downloadUrl($version) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
60
plugins-core/documents/src/DocumentsPlugin.php
Normal file
60
plugins-core/documents/src/DocumentsPlugin.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\BlockType;
|
||||
use App\Pagebuilder\Field;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Inhaus\Plugins\Documents\Models\Document;
|
||||
use Inhaus\Plugins\Documents\Models\DocumentFolder;
|
||||
use Inhaus\Plugins\Documents\Policies\DocumentFolderPolicy;
|
||||
|
||||
class DocumentsPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(FolderTree::class);
|
||||
|
||||
$this->app->make(Navigation::class)->add('documents', 'Dokumente', '/dokumente', active: 'documents.*', sort: 50);
|
||||
|
||||
$abilities = $this->app->make(Abilities::class);
|
||||
$abilities->define('documents.manage', 'Dokumente: gesamte Ablage verwalten', 'Dokumente');
|
||||
$abilities->define('documents.edit', 'Dokumente pflegen', 'Dokumente', resource: 'document_folder');
|
||||
$abilities->resourceType(
|
||||
'document_folder',
|
||||
'Dokumentenordner',
|
||||
fn () => $this->app->make(FolderTree::class)->options(),
|
||||
fn (array $ids) => $this->app->make(FolderTree::class)->descendantIds($ids),
|
||||
);
|
||||
|
||||
Gate::policy(DocumentFolder::class, DocumentFolderPolicy::class);
|
||||
|
||||
$this->app->make(Blocks::class)->add(BlockType::make('documents.folder', 'Dokumente', 'file-down', 'dynamic', 'documents::FolderBlock')
|
||||
->description('Die Dokumente eines Ordners – immer in der aktuellen Fassung.')
|
||||
->fields([
|
||||
Field::text('title', 'Überschrift', 150),
|
||||
Field::select('folder', 'Ordner', fn () => collect($this->app->make(FolderTree::class)->options())->mapWithKeys(fn ($name, $id) => [(string) $id => $name])->all()),
|
||||
Field::toggle('show_description', 'Beschreibungen anzeigen', true),
|
||||
])
|
||||
->resolveUsing(function (array $data, ?User $user) {
|
||||
$tree = $this->app->make(FolderTree::class);
|
||||
$folderId = (int) $data['folder'];
|
||||
|
||||
if (! $folderId || ! $tree->isVisible($folderId, $user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$documents = Document::query()->where('folder_id', $folderId)->with('currentVersion')->orderBy('title')->limit(100)->get();
|
||||
|
||||
return [
|
||||
'folder_url' => route('documents.folder', $folderId),
|
||||
'documents' => $documents->map(fn (Document $d) => DocumentPresenter::row($d))->all(),
|
||||
];
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Filament\Resources\DocumentFolders;
|
||||
|
||||
use App\Filament\Components\AudienceSection;
|
||||
use App\Filament\Components\RoleGrantSelect;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Inhaus\Plugins\Documents\Filament\Resources\DocumentFolders\Pages\ManageDocumentFolders;
|
||||
use Inhaus\Plugins\Documents\FolderTree;
|
||||
use Inhaus\Plugins\Documents\Models\DocumentFolder;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Ordnerstruktur der Dokumentenablage: Rechte je Ordner und Sichtbarkeit.
|
||||
* Hochladen und Pflegen der Dokumente geschieht im Portal unter „Dokumente“.
|
||||
*/
|
||||
class DocumentFolderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DocumentFolder::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedFolder;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static ?string $modelLabel = 'Dokumentenordner';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Dokumentenordner';
|
||||
|
||||
protected static ?string $slug = 'dokumentenordner';
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('documents.manage') ?? false;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->columns(2)->components([
|
||||
TextInput::make('name')->label('Name')->required()->maxLength(120),
|
||||
Select::make('parent_id')->label('Übergeordneter Ordner')->placeholder('– oberste Ebene –')->searchable()
|
||||
->options(fn (?DocumentFolder $record) => collect(app(FolderTree::class)->options())
|
||||
->except($record ? [$record->id, ...app(FolderTree::class)->descendantIds([$record->id])] : [])->all()),
|
||||
TextInput::make('description')->label('Beschreibung')->maxLength(500)->columnSpanFull(),
|
||||
TextInput::make('sort')->label('Reihenfolge')->numeric()->default(0),
|
||||
Section::make('Pflege')
|
||||
->description('Rollen, die in diesem Ordner und allen Unterordnern Dokumente hochladen, ändern und löschen dürfen.')
|
||||
->columnSpanFull()
|
||||
->schema([RoleGrantSelect::make('editors', 'Dürfen Dokumente pflegen', 'documents.edit', 'document_folder', includeChildren: true)]),
|
||||
AudienceSection::make('document_folder', 'Wer den Ordner sieht. Leer lassen = alle. Gilt auch für alle Unterordner.')->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->modifyQueryUsing(fn ($query) => $query->withCount('documents'))
|
||||
->defaultSort('name')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Name')->weight('medium')->searchable()
|
||||
->formatStateUsing(fn (string $state, DocumentFolder $record) => str_repeat('— ', count(app(FolderTree::class)->ancestors($record->id))).$state),
|
||||
TextColumn::make('documents_count')->label('Dokumente'),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('open')->label('Öffnen')->icon(Heroicon::OutlinedArrowTopRightOnSquare)->iconButton()
|
||||
->url(fn (DocumentFolder $record) => route('documents.folder', $record)),
|
||||
EditAction::make()->after(fn () => FolderTree::flush(true)),
|
||||
DeleteAction::make()->visible(fn (DocumentFolder $record) => $record->documents_count === 0 && ! $record->children()->exists()),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return ['index' => ManageDocumentFolders::route('/')];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Filament\Resources\DocumentFolders\Pages;
|
||||
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Inhaus\Plugins\Documents\Filament\Resources\DocumentFolders\DocumentFolderResource;
|
||||
use Inhaus\Plugins\Documents\FolderTree;
|
||||
|
||||
class ManageDocumentFolders extends ManageRecords
|
||||
{
|
||||
protected static string $resource = DocumentFolderResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()->label('Ordner anlegen')
|
||||
->mutateDataUsing(fn (array $data) => [...$data, 'created_by' => auth()->id()])
|
||||
->after(fn () => FolderTree::flush(true)),
|
||||
];
|
||||
}
|
||||
}
|
||||
177
plugins-core/documents/src/FolderTree.php
Normal file
177
plugins-core/documents/src/FolderTree.php
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use App\Support\Permissions\Permissions;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Ordnerbaum als gecachte Struktur (nur Arrays). Sichtbar ist ein Ordner, wenn
|
||||
* die Person seine Zielgruppe und die aller übergeordneten Ordner erfüllt.
|
||||
*/
|
||||
class FolderTree
|
||||
{
|
||||
private const CACHE_KEY = 'documents.tree';
|
||||
|
||||
/** @var array{folders: array<int, array<string, mixed>>, children: array<int, list<int>>}|null */
|
||||
private ?array $data = null;
|
||||
|
||||
/** @var array<int, array<int, bool>> */
|
||||
private array $visible = [];
|
||||
|
||||
public static function flush(bool $structureChanged = false): void
|
||||
{
|
||||
Cache::forget(self::CACHE_KEY);
|
||||
app(self::class)->data = null;
|
||||
app(self::class)->visible = [];
|
||||
|
||||
if ($structureChanged) {
|
||||
Permissions::flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function get(int $id): ?array
|
||||
{
|
||||
return $this->data()['folders'][$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function childIds(?int $id): array
|
||||
{
|
||||
return $this->data()['children'][$id ?? 0] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $ids
|
||||
* @return list<int>
|
||||
*/
|
||||
public function descendantIds(array $ids): array
|
||||
{
|
||||
$result = [];
|
||||
$queue = $ids;
|
||||
|
||||
while ($queue !== []) {
|
||||
foreach ($this->childIds(array_shift($queue)) as $child) {
|
||||
if (! in_array($child, $result, true)) {
|
||||
$result[] = $child;
|
||||
$queue[] = $child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function ancestors(int $id): array
|
||||
{
|
||||
$result = [];
|
||||
$parent = $this->get($id)['parent_id'] ?? null;
|
||||
|
||||
while ($parent !== null && ($folder = $this->get($parent)) && count($result) < 50) {
|
||||
array_unshift($result, $folder);
|
||||
$parent = $folder['parent_id'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isVisible(int $id, ?User $user): bool
|
||||
{
|
||||
if ($user?->can('documents.manage')) {
|
||||
return $this->get($id) !== null;
|
||||
}
|
||||
|
||||
$key = $user?->id ?? 0;
|
||||
|
||||
if (isset($this->visible[$key][$id])) {
|
||||
return $this->visible[$key][$id];
|
||||
}
|
||||
|
||||
$folder = $this->get($id);
|
||||
$visible = $folder !== null
|
||||
&& Audiences::matches($folder['audience'], $user)
|
||||
&& ($folder['parent_id'] === null || $this->isVisible($folder['parent_id'], $user));
|
||||
|
||||
return $this->visible[$key][$id] = $visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* IDs aller sichtbaren Ordner – für die Suche.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
public function visibleIds(?User $user): array
|
||||
{
|
||||
return array_values(array_filter(array_keys($this->data()['folders']), fn (int $id) => $this->isVisible($id, $user)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{id: int, name: string, children: list<mixed>}>
|
||||
*/
|
||||
public function visibleTree(?int $rootId, ?User $user, int $maxDepth = 8): array
|
||||
{
|
||||
if ($maxDepth <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($this->childIds($rootId) as $id) {
|
||||
if ($this->isVisible($id, $user)) {
|
||||
$result[] = ['id' => $id, 'name' => $this->get($id)['name'], 'children' => $this->visibleTree($id, $user, $maxDepth - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function options(?int $rootId = null, int $depth = 0): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach ($this->childIds($rootId) as $id) {
|
||||
$options[$id] = str_repeat('— ', $depth).$this->get($id)['name'];
|
||||
$options += $this->options($id, $depth + 1);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{folders: array<int, array<string, mixed>>, children: array<int, list<int>>}
|
||||
*/
|
||||
private function data(): array
|
||||
{
|
||||
return $this->data ??= Cache::rememberForever(self::CACHE_KEY, function () {
|
||||
$audiences = Audiences::allOfType('document_folder');
|
||||
$folders = [];
|
||||
$children = [];
|
||||
|
||||
foreach (DB::table('document_folders')->orderBy('sort')->orderBy('name')->get(['id', 'parent_id', 'name']) as $row) {
|
||||
$folders[$row->id] = [
|
||||
'id' => (int) $row->id,
|
||||
'parent_id' => $row->parent_id !== null ? (int) $row->parent_id : null,
|
||||
'name' => $row->name,
|
||||
'audience' => $audiences[$row->id] ?? null,
|
||||
];
|
||||
$children[(int) ($row->parent_id ?? 0)][] = (int) $row->id;
|
||||
}
|
||||
|
||||
return ['folders' => $folders, 'children' => $children];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Documents\DocumentPresenter;
|
||||
use Inhaus\Plugins\Documents\FolderTree;
|
||||
use Inhaus\Plugins\Documents\Models\Document;
|
||||
use Inhaus\Plugins\Documents\Models\DocumentFolder;
|
||||
use Inhaus\Plugins\Documents\Models\DocumentVersion;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
/** Nie als Datei annehmen: ausführbarer Code, Webseiten, Skripte. */
|
||||
private const BLOCKED = ['php', 'phtml', 'phar', 'php3', 'php4', 'php5', 'php7', 'php8', 'pht', 'shtml', 'htaccess', 'exe', 'bat', 'cmd', 'com', 'sh', 'js', 'mjs', 'html', 'htm', 'svg', 'xhtml', 'jsp', 'asp', 'aspx', 'cgi', 'pl', 'py', 'msi', 'ps1', 'vbs', 'scr'];
|
||||
|
||||
public const MAX_KB = 100 * 1024;
|
||||
|
||||
public function __construct(private readonly FolderTree $tree) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return $this->render($request, null);
|
||||
}
|
||||
|
||||
public function folder(Request $request, DocumentFolder $folder): Response
|
||||
{
|
||||
abort_unless($this->tree->isVisible($folder->id, $request->user()) || $request->user()->can('update', $folder), 404);
|
||||
|
||||
return $this->render($request, $folder);
|
||||
}
|
||||
|
||||
public function upload(Request $request, DocumentFolder $folder): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $folder);
|
||||
$request->validate([
|
||||
'files' => ['required', 'array', 'max:20'],
|
||||
'files.*' => ['file', 'max:'.self::MAX_KB],
|
||||
], [], ['files.*' => 'Datei']);
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($request->file('files') as $index => $file) {
|
||||
$this->assertAllowed($file, "files.{$index}");
|
||||
}
|
||||
|
||||
foreach ($request->file('files') as $file) {
|
||||
DB::transaction(function () use ($folder, $file, $request) {
|
||||
$document = $folder->documents()->create([
|
||||
'title' => Str::limit(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) ?: 'Dokument', 250, ''),
|
||||
'created_by' => $request->user()->id,
|
||||
'updated_by' => $request->user()->id,
|
||||
]);
|
||||
$this->storeVersion($document, $file, $request, null);
|
||||
});
|
||||
$count++;
|
||||
}
|
||||
|
||||
Audit::log('documents.uploaded', ['folder' => $folder->id, 'count' => $count]);
|
||||
|
||||
return back()->with('status', $count === 1 ? 'Dokument hochgeladen.' : "{$count} Dokumente hochgeladen.");
|
||||
}
|
||||
|
||||
public function newVersion(Request $request, Document $document): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $document->folder);
|
||||
$request->validate(['file' => ['required', 'file', 'max:'.self::MAX_KB], 'note' => ['nullable', 'string', 'max:500']], [], ['file' => 'Datei', 'note' => 'Hinweis']);
|
||||
$this->assertAllowed($request->file('file'), 'file');
|
||||
|
||||
DB::transaction(fn () => $this->storeVersion($document, $request->file('file'), $request, $request->input('note')));
|
||||
Audit::log('documents.version_added', ['document' => $document->id, 'title' => $document->title]);
|
||||
|
||||
return back()->with('status', 'Neue Fassung hochgeladen.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Document $document): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $document->folder);
|
||||
$data = $request->validate([
|
||||
'title' => ['required', 'string', 'max:250'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'folder_id' => ['required', 'integer', Rule::exists('document_folders', 'id')],
|
||||
], [], ['title' => 'Titel', 'folder_id' => 'Ordner']);
|
||||
|
||||
// Verschieben: im Zielordner muss man ebenfalls pflegen dürfen.
|
||||
if ((int) $data['folder_id'] !== $document->folder_id) {
|
||||
Gate::authorize('update', DocumentFolder::query()->findOrFail($data['folder_id']));
|
||||
}
|
||||
|
||||
$document->update([...$data, 'updated_by' => $request->user()->id]);
|
||||
|
||||
return back()->with('status', 'Gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Document $document): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $document->folder);
|
||||
$document->delete();
|
||||
Audit::log('documents.deleted', ['document' => $document->id, 'title' => $document->title]);
|
||||
|
||||
return back()->with('status', 'Dokument gelöscht.');
|
||||
}
|
||||
|
||||
public function versions(Request $request, Document $document): JsonResponse
|
||||
{
|
||||
abort_unless($this->tree->isVisible($document->folder_id, $request->user()) || $request->user()->can('update', $document->folder), 404);
|
||||
|
||||
return response()->json(['versions' => $document->versions()->with('uploader:id,name')->get()->map(fn (DocumentVersion $v) => [
|
||||
'version' => $v->version,
|
||||
'name' => $v->name,
|
||||
'size' => (int) $v->size,
|
||||
'note' => $v->note,
|
||||
'uploader' => $v->uploader?->name,
|
||||
'created_at' => $v->created_at?->toIso8601String(),
|
||||
'current' => $v->id === $document->current_version_id,
|
||||
'download_url' => $document->downloadUrl($v),
|
||||
])]);
|
||||
}
|
||||
|
||||
public function download(Request $request, Document $document, int $version): StreamedResponse
|
||||
{
|
||||
abort_unless($this->tree->isVisible($document->folder_id, $request->user()) || $request->user()->can('update', $document->folder), 404);
|
||||
|
||||
$file = $document->versions()->where('version', $version)->firstOrFail();
|
||||
|
||||
return Storage::disk(DocumentVersion::DISK)->download($file->path, $file->name, [
|
||||
'Content-Type' => $file->mime ?: 'application/octet-stream',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
'Cache-Control' => 'private, max-age=300',
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeFolder(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'parent_id' => ['nullable', 'integer', Rule::exists('document_folders', 'id')],
|
||||
], [], ['name' => 'Name']);
|
||||
|
||||
$parent = isset($data['parent_id']) ? DocumentFolder::query()->findOrFail($data['parent_id']) : null;
|
||||
Gate::authorize('create', [DocumentFolder::class, $parent]);
|
||||
|
||||
$folder = DocumentFolder::query()->create([
|
||||
'name' => trim($data['name']),
|
||||
'parent_id' => $parent?->id,
|
||||
'sort' => (int) DocumentFolder::query()->where('parent_id', $parent?->id)->max('sort') + 1,
|
||||
'created_by' => $request->user()->id,
|
||||
]);
|
||||
|
||||
return to_route('documents.folder', $folder)->with('status', 'Ordner angelegt.');
|
||||
}
|
||||
|
||||
public function updateFolder(Request $request, DocumentFolder $folder): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $folder);
|
||||
$folder->update($request->validate(['name' => ['required', 'string', 'max:120'], 'description' => ['nullable', 'string', 'max:500']], [], ['name' => 'Name']));
|
||||
|
||||
return back()->with('status', 'Ordner gespeichert.');
|
||||
}
|
||||
|
||||
public function destroyFolder(Request $request, DocumentFolder $folder): RedirectResponse
|
||||
{
|
||||
Gate::authorize('delete', $folder);
|
||||
|
||||
if ($folder->children()->exists() || $folder->documents()->exists()) {
|
||||
throw ValidationException::withMessages(['folder' => 'Der Ordner ist nicht leer. Bitte zuerst Dokumente und Unterordner entfernen oder verschieben.']);
|
||||
}
|
||||
|
||||
$parent = $folder->parent_id;
|
||||
$folder->delete();
|
||||
|
||||
return ($parent ? to_route('documents.folder', $parent) : to_route('documents.index'))->with('status', 'Ordner gelöscht.');
|
||||
}
|
||||
|
||||
private function render(Request $request, ?DocumentFolder $folder): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$search = trim((string) $request->query('q', ''));
|
||||
|
||||
if ($search !== '') {
|
||||
$like = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $search).'%';
|
||||
$documents = Document::query()
|
||||
->whereIn('folder_id', $this->tree->visibleIds($user) ?: [0])
|
||||
->where(fn ($q) => $q->where('title', 'like', $like)->orWhere('description', 'like', $like)
|
||||
->orWhereHas('versions', fn ($v) => $v->where('name', 'like', $like)))
|
||||
->with('currentVersion')->orderBy('title')->limit(100)->get();
|
||||
} else {
|
||||
$documents = $folder
|
||||
? $folder->documents()->with('currentVersion')->orderBy('title')->get()
|
||||
: collect();
|
||||
}
|
||||
|
||||
$childIds = array_values(array_filter($this->tree->childIds($folder?->id), fn ($id) => $this->tree->isVisible($id, $user)));
|
||||
$counts = Document::query()->whereIn('folder_id', $childIds ?: [0])->selectRaw('folder_id, count(*) as c')->groupBy('folder_id')->pluck('c', 'folder_id');
|
||||
$children = collect($childIds)->map(fn ($id) => [
|
||||
'id' => $id,
|
||||
'name' => $this->tree->get($id)['name'],
|
||||
'count' => (int) ($counts[$id] ?? 0) + count($this->tree->childIds($id)),
|
||||
]);
|
||||
|
||||
return Inertia::render('documents::Index', [
|
||||
'tree' => $this->tree->visibleTree(null, $user),
|
||||
'folder' => $folder ? [
|
||||
'id' => $folder->id,
|
||||
'name' => $folder->name,
|
||||
'description' => $folder->description,
|
||||
'parent_id' => $folder->parent_id,
|
||||
'can_edit' => $user->can('update', $folder),
|
||||
'can_delete' => $user->can('delete', $folder),
|
||||
] : null,
|
||||
'breadcrumbs' => $folder ? array_map(fn ($f) => ['id' => $f['id'], 'name' => $f['name']], $this->tree->ancestors($folder->id)) : [],
|
||||
'children' => $children,
|
||||
'documents' => $documents->map(fn (Document $d) => DocumentPresenter::row($d)),
|
||||
'search' => $search,
|
||||
'canCreateRoot' => $user->can('documents.manage'),
|
||||
// Zielordner zum Verschieben: nur solche, in denen die Person pflegen darf.
|
||||
'folderOptions' => collect($this->tree->options())->filter(fn ($name, $id) => $user->can('documents.edit', ['document_folder', $id]))
|
||||
->map(fn ($name, $id) => ['value' => $id, 'label' => $name])->values(),
|
||||
'maxUploadMb' => (int) floor(min(self::MAX_KB / 1024, self::phpUploadLimitMb())),
|
||||
]);
|
||||
}
|
||||
|
||||
private function storeVersion(Document $document, UploadedFile $file, Request $request, ?string $note): DocumentVersion
|
||||
{
|
||||
$name = Str::limit(preg_replace('/[^\pL\pN ._()\-]+/u', '_', $file->getClientOriginalName()) ?: 'datei', 200, '');
|
||||
$extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
|
||||
|
||||
$version = $document->versions()->create([
|
||||
'version' => (int) $document->versions()->max('version') + 1,
|
||||
'name' => $name,
|
||||
'path' => $file->storeAs('documents/'.$document->folder_id, Str::random(40).($extension ? '.'.$extension : ''), DocumentVersion::DISK),
|
||||
'mime' => $file->getMimeType(),
|
||||
'size' => $file->getSize(),
|
||||
'note' => $note,
|
||||
'uploaded_by' => $request->user()->id,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$document->forceFill(['current_version_id' => $version->id, 'updated_by' => $request->user()->id])->save();
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
private function assertAllowed(UploadedFile $file, string $field): void
|
||||
{
|
||||
$extensions = [strtolower(pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION)), strtolower((string) $file->getClientOriginalExtension())];
|
||||
|
||||
if (array_intersect($extensions, self::BLOCKED) !== []) {
|
||||
throw ValidationException::withMessages([$field => '„'.$file->getClientOriginalName().'“: Dieser Dateityp ist aus Sicherheitsgründen nicht erlaubt.']);
|
||||
}
|
||||
}
|
||||
|
||||
private static function phpUploadLimitMb(): float
|
||||
{
|
||||
$bytes = fn (string $v) => (int) $v * (['g' => 1024 ** 3, 'm' => 1024 ** 2, 'k' => 1024][strtolower(substr(trim($v), -1))] ?? 1);
|
||||
$limits = array_filter([$bytes((string) ini_get('upload_max_filesize')), $bytes((string) ini_get('post_max_size'))]);
|
||||
|
||||
return $limits === [] ? self::MAX_KB / 1024 : min($limits) / 1024 / 1024;
|
||||
}
|
||||
}
|
||||
58
plugins-core/documents/src/Models/Document.php
Normal file
58
plugins-core/documents/src/Models/Document.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['folder_id', 'title', 'description', 'created_by', 'updated_by'])]
|
||||
class Document extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
// Dateien aller Fassungen mit entfernen.
|
||||
static::deleting(fn (Document $document) => $document->versions()->get()->each->delete());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<DocumentFolder, $this>
|
||||
*/
|
||||
public function folder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DocumentFolder::class, 'folder_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<DocumentVersion, $this>
|
||||
*/
|
||||
public function currentVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DocumentVersion::class, 'current_version_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<DocumentVersion, $this>
|
||||
*/
|
||||
public function versions(): HasMany
|
||||
{
|
||||
return $this->hasMany(DocumentVersion::class)->orderByDesc('version');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
|
||||
public function downloadUrl(?DocumentVersion $version = null): string
|
||||
{
|
||||
$version ??= $this->currentVersion;
|
||||
|
||||
return route('documents.download', ['document' => $this->id, 'version' => $version?->version, 'name' => $version?->name ?? 'datei']);
|
||||
}
|
||||
}
|
||||
51
plugins-core/documents/src/Models/DocumentFolder.php
Normal file
51
plugins-core/documents/src/Models/DocumentFolder.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Inhaus\Plugins\Documents\FolderTree;
|
||||
|
||||
#[Fillable(['parent_id', 'name', 'description', 'sort', 'created_by'])]
|
||||
class DocumentFolder extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(fn (DocumentFolder $folder) => FolderTree::flush($folder->wasRecentlyCreated || $folder->wasChanged('parent_id')));
|
||||
static::deleted(fn () => FolderTree::flush(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: int}
|
||||
*/
|
||||
public function permissionResource(): array
|
||||
{
|
||||
return ['document_folder', $this->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<DocumentFolder, $this>
|
||||
*/
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DocumentFolder::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<DocumentFolder, $this>
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(DocumentFolder::class, 'parent_id')->orderBy('sort')->orderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Document, $this>
|
||||
*/
|
||||
public function documents(): HasMany
|
||||
{
|
||||
return $this->hasMany(Document::class, 'folder_id');
|
||||
}
|
||||
}
|
||||
47
plugins-core/documents/src/Models/DocumentVersion.php
Normal file
47
plugins-core/documents/src/Models/DocumentVersion.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Eine Fassung eines Dokuments. Die Datei liegt außerhalb von public/ und
|
||||
* wird nur an Personen ausgeliefert, die den Ordner sehen dürfen.
|
||||
*/
|
||||
#[Fillable(['document_id', 'version', 'name', 'path', 'mime', 'size', 'note', 'uploaded_by', 'created_at'])]
|
||||
class DocumentVersion extends Model
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleted(fn (DocumentVersion $version) => Storage::disk(self::DISK)->delete($version->path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Document, $this>
|
||||
*/
|
||||
public function document(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Document::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function uploader(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uploaded_by');
|
||||
}
|
||||
|
||||
public function extension(): string
|
||||
{
|
||||
return strtoupper(pathinfo($this->name, PATHINFO_EXTENSION));
|
||||
}
|
||||
}
|
||||
41
plugins-core/documents/src/Policies/DocumentFolderPolicy.php
Normal file
41
plugins-core/documents/src/Policies/DocumentFolderPolicy.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Documents\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use Inhaus\Plugins\Documents\FolderTree;
|
||||
use Inhaus\Plugins\Documents\Models\DocumentFolder;
|
||||
|
||||
/**
|
||||
* „Dokumente verwalten“ gilt für die ganze Ablage. „Dokumente pflegen“ wird je
|
||||
* Ordner vergeben (meist inkl. Unterordnern) – z. B. pflegt die Personalabteilung
|
||||
* den Ordner „Personal“.
|
||||
*/
|
||||
class DocumentFolderPolicy
|
||||
{
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('documents.manage') || $user->permissions()->ids('documents.edit', 'document_folder') !== [];
|
||||
}
|
||||
|
||||
public function view(User $user, DocumentFolder $folder): bool
|
||||
{
|
||||
return app(FolderTree::class)->isVisible($folder->id, $user) || $this->update($user, $folder);
|
||||
}
|
||||
|
||||
public function create(User $user, ?DocumentFolder $parent = null): bool
|
||||
{
|
||||
return $user->can('documents.manage') || ($parent !== null && $this->update($user, $parent));
|
||||
}
|
||||
|
||||
/** Dokumente hochladen, ändern, löschen; Unterordner anlegen. */
|
||||
public function update(User $user, DocumentFolder $folder): bool
|
||||
{
|
||||
return $user->can('documents.manage') || $user->can('documents.edit', ['document_folder', $folder->id]);
|
||||
}
|
||||
|
||||
public function delete(User $user, DocumentFolder $folder): bool
|
||||
{
|
||||
return $user->can('documents.manage') || ($folder->parent_id !== null && $user->can('documents.edit', ['document_folder', $folder->parent_id]));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue