Neues Modul: Qualitätsmanagement
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m55s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 4m15s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m46s
CI / Build-Artefakte aktuell (pull_request) Successful in 52s
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m55s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 4m15s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m46s
CI / Build-Artefakte aktuell (pull_request) Successful in 52s
- Kategorien mit farbigen Ordnerkacheln; Farbe und Symbol je Ordner (Auswahl oder eigener Upload, SVG bereinigt), an Unterordner vererbt - Ordnerseite: Einführungstext, Ansprechpartner (Profilfelder wählbar), Unterordner, Liste mit Dokument, Version, Stand, Größe, Aktion - Einträge: Datei (Lesefassung + bearbeitbare Vorlage), Link, Online-Formular; neue Fassungen archivieren die bisherigen - PDF-Betrachter im Portal (pdf.js) - Eigene Volltextsuche (PDF, Word, Excel, PowerPoint, OpenDocument) mit Textausschnitt; optionale Texterkennung per Tesseract - Rollen-Ausschluss für das ganze Modul, Pflegerecht qm.manage, Zielgruppen je Kategorie - Vorbereitet: Wiedervorlage, Verantwortliche, Lesebestätigungen - Abhängigkeit smalot/pdfparser Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f78cc96be7
commit
b3a057e27c
218 changed files with 13478 additions and 358 deletions
253
plugins-core/qm/src/Http/Controllers/QmController.php
Normal file
253
plugins-core/qm/src/Http/Controllers/QmController.php
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Qm\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Audit;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Qm\Library;
|
||||
use Inhaus\Plugins\Qm\Models\QmEntry;
|
||||
use Inhaus\Plugins\Qm\Models\QmFile;
|
||||
use Inhaus\Plugins\Qm\Models\QmFolder;
|
||||
use Inhaus\Plugins\Qm\Presenter;
|
||||
use Inhaus\Plugins\Qm\QmAccess;
|
||||
use Inhaus\Plugins\Qm\QmTree;
|
||||
use Inhaus\Plugins\Qm\Search;
|
||||
use Symfony\Component\HttpFoundation\Response as HttpResponse;
|
||||
|
||||
class QmController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly QmTree $tree,
|
||||
private readonly Presenter $presenter,
|
||||
private readonly QmAccess $access,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$counts = $this->entryCounts();
|
||||
|
||||
return Inertia::render('qm::Index', [
|
||||
'categories' => collect($this->tree->categories($request->user()))->map(fn (array $category) => [
|
||||
'id' => $category['id'],
|
||||
'name' => $category['name'],
|
||||
'folders' => array_map(fn (int $id) => $this->presenter->tile($id, $counts), $category['folders']),
|
||||
])->values(),
|
||||
'canManage' => $this->access->canManage($request->user()),
|
||||
'adminUrl' => $this->access->canManage($request->user()) ? url('/admin/qm-ordner') : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function folder(Request $request, QmFolder $folder): Response
|
||||
{
|
||||
abort_unless($this->tree->isVisible($folder->id, $request->user()), 404);
|
||||
|
||||
$counts = $this->entryCounts();
|
||||
$canManage = $this->access->canManage($request->user());
|
||||
$entries = $folder->entries()->with(['readingFile', 'editableFile'])->orderBy('sort')->orderBy('title')->get();
|
||||
$node = $this->tree->folder($folder->id);
|
||||
|
||||
return Inertia::render('qm::Folder', [
|
||||
'folder' => [
|
||||
'id' => $folder->id,
|
||||
'name' => $folder->name,
|
||||
'color' => $node['color'],
|
||||
'icon' => $node['icon'],
|
||||
'intro' => app(RichText::class)->sanitize($folder->intro),
|
||||
'contacts' => $this->presenter->contacts($folder->contacts()->get(), $request->user()),
|
||||
],
|
||||
'breadcrumbs' => array_map(fn (array $f) => ['id' => $f['id'], 'name' => $f['name'], 'color' => $f['color']], array_slice($this->tree->path($folder->id), 0, -1)),
|
||||
'children' => array_map(fn (int $id) => $this->presenter->tile($id, $counts), $this->tree->childIds($folder->id)),
|
||||
'entries' => $entries->map(fn (QmEntry $entry) => $this->presenter->entry($entry)),
|
||||
'canManage' => $canManage,
|
||||
'forms' => $canManage ? $this->formOptions() : [],
|
||||
'maxUploadMb' => (int) floor(min(Library::MAX_KB / 1024, self::phpUploadLimitMb())),
|
||||
'adminUrl' => $canManage ? url('/admin/qm-ordner/'.$folder->id.'/edit') : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request, Search $search): Response
|
||||
{
|
||||
$query = trim((string) $request->query('q', ''));
|
||||
|
||||
return Inertia::render('qm::Search', [
|
||||
'query' => $query,
|
||||
'results' => $query === '' ? [] : $search->run($query, $request->user())->map(fn (array $hit) => [
|
||||
...$this->presenter->entry($hit['entry'], withFolder: true),
|
||||
'snippet' => $hit['snippet'],
|
||||
'in_content' => $hit['in_content'],
|
||||
])->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Datei zum Lesen im Portal (PDF-Betrachter bzw. Bild).
|
||||
*/
|
||||
public function view(Request $request, QmEntry $entry): Response|RedirectResponse
|
||||
{
|
||||
abort_unless($this->tree->isVisible($entry->folder_id, $request->user()), 404);
|
||||
|
||||
$entry->load(['readingFile', 'editableFile']);
|
||||
$file = $entry->readingFile ?? $entry->editableFile;
|
||||
abort_unless($file, 404);
|
||||
|
||||
if (! $file->isViewable()) {
|
||||
return redirect($file->url());
|
||||
}
|
||||
|
||||
return Inertia::render('qm::Viewer', [
|
||||
'entry' => $this->presenter->entry($entry, withFolder: true),
|
||||
'file' => ['url' => $file->url(inline: true), 'kind' => $file->mime === 'application/pdf' ? 'pdf' : 'image', 'name' => $file->name],
|
||||
'query' => (string) $request->query('suche', ''),
|
||||
]);
|
||||
}
|
||||
|
||||
public function file(Request $request, QmFile $file): HttpResponse
|
||||
{
|
||||
$entry = $file->entry;
|
||||
abort_unless($entry && $this->tree->isVisible($entry->folder_id, $request->user()), 404);
|
||||
// Archivierte Fassungen sieht nur das QM-Team.
|
||||
abort_if($file->archived_at && ! $this->access->canManage($request->user()), 404);
|
||||
|
||||
$headers = ['X-Content-Type-Options' => 'nosniff', 'Cache-Control' => 'private, max-age=300'];
|
||||
|
||||
if ($request->boolean('lesen') && $file->isViewable()) {
|
||||
// Bilder abgeschottet; PDFs ohne sandbox, sonst blockiert Chrome seinen PDF-Betrachter.
|
||||
return Storage::disk(QmFile::DISK)->response($file->path, $file->name, [
|
||||
...$headers,
|
||||
'Content-Type' => $file->mime,
|
||||
...($file->mime === 'application/pdf' ? [] : ['Content-Security-Policy' => "default-src 'none'; sandbox"]),
|
||||
]);
|
||||
}
|
||||
|
||||
return Storage::disk(QmFile::DISK)->download($file->path, $file->name, [...$headers, 'Content-Type' => $file->mime ?: 'application/octet-stream']);
|
||||
}
|
||||
|
||||
public function store(Request $request, QmFolder $folder, Library $library): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$data = $this->validated($request, null);
|
||||
|
||||
$entry = $library->create($folder, $data, $request->file('reading'), $request->file('editable'), $request->user());
|
||||
Audit::log('qm.entry_created', ['entry' => $entry->id, 'title' => $entry->title, 'folder' => $folder->id]);
|
||||
|
||||
return back()->with('status', 'Eintrag „'.$entry->title.'“ angelegt.');
|
||||
}
|
||||
|
||||
public function update(Request $request, QmEntry $entry, Library $library): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$data = $this->validated($request, $entry);
|
||||
|
||||
$library->update($entry, $data, $request->file('reading'), $request->file('editable'), $request->boolean('remove_editable'), $request->user());
|
||||
Audit::log('qm.entry_updated', ['entry' => $entry->id, 'title' => $entry->title, 'new_version' => $request->hasFile('reading') || $request->hasFile('editable')]);
|
||||
|
||||
return back()->with('status', $request->hasFile('reading') || $request->hasFile('editable') ? 'Neue Fassung gespeichert – die bisherige liegt im Archiv.' : 'Gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, QmEntry $entry): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$title = $entry->title;
|
||||
$entry->delete();
|
||||
Audit::log('qm.entry_deleted', ['entry' => $entry->id, 'title' => $title]);
|
||||
|
||||
return back()->with('status', '„'.$title.'“ gelöscht.');
|
||||
}
|
||||
|
||||
public function archive(Request $request, QmEntry $entry): JsonResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
|
||||
return response()->json(['files' => $entry->files()->with('uploader:id,first_name,last_name,name')->orderByDesc('created_at')->orderByDesc('id')->get()
|
||||
->map(fn (QmFile $file) => [
|
||||
'id' => $file->id,
|
||||
'kind' => $file->kind,
|
||||
'name' => $file->name,
|
||||
'version' => $file->version,
|
||||
'valid_from' => $file->valid_from?->toDateString(),
|
||||
'size' => $file->size,
|
||||
'uploaded_at' => $file->created_at?->toIso8601String(),
|
||||
'uploader' => $file->uploader?->name,
|
||||
'archived' => $file->archived_at !== null,
|
||||
'url' => $file->url(),
|
||||
])]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request, ?QmEntry $entry): array
|
||||
{
|
||||
$type = $entry?->type ?? $request->input('type');
|
||||
$fileRule = ['nullable', 'file', 'max:'.Library::MAX_KB, 'extensions:'.implode(',', Library::EXTENSIONS)];
|
||||
|
||||
return $request->validate([
|
||||
'type' => [$entry ? 'nullable' : 'required', Rule::in([QmEntry::FILE, QmEntry::LINK, QmEntry::FORM])],
|
||||
'title' => ['required', 'string', 'max:250'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'version' => ['nullable', 'string', 'max:30'],
|
||||
'valid_from' => ['nullable', 'date'],
|
||||
'url' => [Rule::requiredIf($type === QmEntry::LINK), 'nullable', 'string', 'max:1000', 'regex:#^(https?://|/)#i'],
|
||||
'form_id' => [Rule::requiredIf($type === QmEntry::FORM), 'nullable', 'integer', Rule::exists('forms', 'id')],
|
||||
'reading' => [...$fileRule, Rule::requiredIf($type === QmEntry::FILE && ! $entry && ! $request->hasFile('editable'))],
|
||||
'editable' => $fileRule,
|
||||
], ['url.regex' => 'Bitte eine Adresse angeben, die mit https:// oder / beginnt.', 'reading.required' => 'Bitte eine Datei auswählen.'], [
|
||||
'title' => 'Titel', 'version' => 'Version', 'valid_from' => 'Stand', 'url' => 'Adresse', 'form_id' => 'Formular',
|
||||
'reading' => 'Datei', 'editable' => 'Bearbeitbare Vorlage',
|
||||
]) + ['type' => $type];
|
||||
}
|
||||
|
||||
private function authorizeManage(Request $request): void
|
||||
{
|
||||
abort_unless($this->access->canManage($request->user()), 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int> Ordner => Anzahl Einträge
|
||||
*/
|
||||
private function entryCounts(): array
|
||||
{
|
||||
return DB::table('qm_entries')->selectRaw('folder_id, count(*) as c')->groupBy('folder_id')->pluck('c', 'folder_id')->map(fn ($c) => (int) $c)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{value: int, label: string}>
|
||||
*/
|
||||
private function formOptions(): array
|
||||
{
|
||||
if (! DB::getSchemaBuilder()->hasTable('forms')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return DB::table('forms')->orderBy('title')->get(['id', 'title'])->map(fn ($f) => ['value' => (int) $f->id, 'label' => $f->title])->all();
|
||||
}
|
||||
|
||||
private static function phpUploadLimitMb(): float
|
||||
{
|
||||
$bytes = function (string $value): float {
|
||||
$value = trim($value);
|
||||
$unit = strtolower(substr($value, -1));
|
||||
$number = (float) $value;
|
||||
|
||||
return match ($unit) {
|
||||
'g' => $number * 1024 ** 3,
|
||||
'm' => $number * 1024 ** 2,
|
||||
'k' => $number * 1024,
|
||||
default => $number,
|
||||
};
|
||||
};
|
||||
|
||||
$limits = array_filter([$bytes((string) ini_get('upload_max_filesize')), $bytes((string) ini_get('post_max_size'))]);
|
||||
|
||||
return $limits === [] ? 100 : min($limits) / 1024 / 1024;
|
||||
}
|
||||
}
|
||||
21
plugins-core/qm/src/Http/EnsureQmAccess.php
Normal file
21
plugins-core/qm/src/Http/EnsureQmAccess.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Qm\Http;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Inhaus\Plugins\Qm\QmAccess;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Ausgeschlossene Rollen (z. B. Klient*innen) sehen das QM-Modul nicht – auch nicht über Links.
|
||||
*/
|
||||
class EnsureQmAccess
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
abort_unless(app(QmAccess::class)->allows($request->user()), 404);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue