Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6269d3302c
commit
f3987e8386
328 changed files with 10618 additions and 389 deletions
|
|
@ -30,6 +30,7 @@ class NewsController extends Controller
|
|||
'posts' => NewsPostResource::collection($posts),
|
||||
'categories' => $categories->map(fn (NewsCategory $c) => ['name' => $c->name, 'slug' => $c->slug]),
|
||||
'activeCategory' => $category?->slug,
|
||||
'canWrite' => $request->user()->can('create', NewsPost::class),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ class NewsController extends Controller
|
|||
'avatar_url' => $post->author->avatarUrl(96),
|
||||
] : null,
|
||||
],
|
||||
'editUrl' => request()->user()->can('update', $post) ? route('news.editor.edit', $post) : null,
|
||||
'related' => NewsPostResource::collection(
|
||||
NewsPost::query()
|
||||
->published()
|
||||
|
|
|
|||
223
plugins-core/news/src/Http/Controllers/NewsEditorController.php
Normal file
223
plugins-core/news/src/Http/Controllers/NewsEditorController.php
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Images;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\File;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Inhaus\Plugins\News\NewsWorkflow;
|
||||
use Inhaus\Plugins\News\Policies\NewsPostPolicy;
|
||||
|
||||
/**
|
||||
* Beiträge im Portal schreiben: speichern als Entwurf, zur Freigabe einreichen
|
||||
* oder – mit Veröffentlichungsrecht – direkt veröffentlichen bzw. planen.
|
||||
*/
|
||||
class NewsEditorController extends Controller
|
||||
{
|
||||
public function __construct(private readonly NewsWorkflow $workflow, private readonly NewsPostPolicy $policy) {}
|
||||
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
Gate::authorize('create', NewsPost::class);
|
||||
|
||||
return $this->form($request, null);
|
||||
}
|
||||
|
||||
public function edit(Request $request, NewsPost $post): Response
|
||||
{
|
||||
Gate::authorize('update', $post);
|
||||
|
||||
return $this->form($request, $post);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
Gate::authorize('create', NewsPost::class);
|
||||
|
||||
$post = new NewsPost(['author_id' => $request->user()->id]);
|
||||
|
||||
return $this->save($request, $post);
|
||||
}
|
||||
|
||||
public function update(Request $request, NewsPost $post): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $post);
|
||||
|
||||
// Veröffentlichte Beiträge ändert nur, wer veröffentlichen darf – sonst gingen Änderungen ohne Freigabe online.
|
||||
if ($post->status === NewsPost::PUBLISHED && ! $this->policy->publish($request->user(), $post->category_id)) {
|
||||
abort(403, 'Veröffentlichte Beiträge kann nur die Redaktion ändern.');
|
||||
}
|
||||
|
||||
return $this->save($request, $post);
|
||||
}
|
||||
|
||||
public function approve(Request $request, NewsPost $post): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $post);
|
||||
abort_unless($this->policy->publish($request->user(), $post->category_id), 403);
|
||||
|
||||
$data = $request->validate(['published_at' => ['nullable', 'date']]);
|
||||
$this->workflow->approve($post, $request->user(), isset($data['published_at']) ? Carbon::parse($data['published_at']) : null);
|
||||
|
||||
return to_route('editorial')->with('status', $post->isScheduled() ? 'Beitrag freigegeben und geplant.' : 'Beitrag veröffentlicht.');
|
||||
}
|
||||
|
||||
public function reject(Request $request, NewsPost $post): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $post);
|
||||
abort_unless($this->policy->publish($request->user(), $post->category_id), 403);
|
||||
abort_unless($post->status === NewsPost::PENDING, 422);
|
||||
|
||||
$data = $request->validate(['note' => ['required', 'string', 'max:1000']], [], ['note' => 'Begründung']);
|
||||
$this->workflow->reject($post, $request->user(), $data['note']);
|
||||
|
||||
return to_route('editorial')->with('status', 'Beitrag zurückgegeben.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, NewsPost $post): RedirectResponse
|
||||
{
|
||||
Gate::authorize('delete', $post);
|
||||
|
||||
if ($post->status === NewsPost::PUBLISHED && ! $this->policy->publish($request->user(), $post->category_id)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$post->delete();
|
||||
Audit::log('news.deleted', ['post' => $post->id, 'title' => $post->title]);
|
||||
|
||||
return to_route('editorial')->with('status', 'Beitrag gelöscht.');
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request, Images $images): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', NewsPost::class);
|
||||
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp', 'gif'])->max(15 * 1024)]]);
|
||||
|
||||
$path = $images->storeContentImage($request->file('image'), 'news/inline');
|
||||
|
||||
return response()->json(['path' => $path, 'url' => Storage::disk('uploads')->url($path)]);
|
||||
}
|
||||
|
||||
private function save(Request $request, NewsPost $post): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$writable = $this->writableCategoryIds($request);
|
||||
|
||||
$data = $request->validate([
|
||||
'title' => ['required', 'string', 'max:160'],
|
||||
'teaser' => ['nullable', 'string', 'max:300'],
|
||||
'body' => ['nullable', 'string', 'max:500000'],
|
||||
'category_id' => [$user->can('news.manage') ? 'nullable' : 'required', 'integer', Rule::in($writable === true ? NewsCategory::query()->pluck('id')->all() : $writable)],
|
||||
'cover' => ['nullable', File::image()->types(['jpg', 'jpeg', 'png', 'webp'])->max(10 * 1024)],
|
||||
'remove_cover' => ['boolean'],
|
||||
'is_featured' => ['boolean'],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
'action' => ['required', Rule::in(['draft', 'submit', 'publish'])],
|
||||
], ['category_id.in' => 'In dieser Kategorie dürfen Sie keine Beiträge schreiben.'], ['category_id' => 'Kategorie', 'title' => 'Titel']);
|
||||
|
||||
$canPublish = $this->policy->publish($user, $data['category_id'] ?? null);
|
||||
|
||||
if ($data['action'] === 'publish' && ! $canPublish) {
|
||||
throw ValidationException::withMessages(['action' => 'In dieser Kategorie dürfen Sie nicht veröffentlichen. Bitte reichen Sie den Beitrag zur Freigabe ein.']);
|
||||
}
|
||||
|
||||
$post->fill([
|
||||
'title' => $data['title'],
|
||||
'teaser' => $data['teaser'] ?? null,
|
||||
'body' => $data['body'] ?? null,
|
||||
'category_id' => $data['category_id'] ?? null,
|
||||
]);
|
||||
|
||||
if ($canPublish) {
|
||||
$post->is_featured = (bool) ($data['is_featured'] ?? false);
|
||||
}
|
||||
|
||||
if ($request->boolean('remove_cover')) {
|
||||
$post->cover_path = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('cover')) {
|
||||
$post->cover_path = $request->file('cover')->store('news', 'uploads');
|
||||
}
|
||||
|
||||
if ($data['action'] === 'draft') {
|
||||
// Ein Entwurf ist nicht (mehr) veröffentlicht; eine laufende Freigabe bleibt bestehen.
|
||||
if ($post->status !== NewsPost::PENDING) {
|
||||
$post->published_at = null;
|
||||
$post->status = NewsPost::DRAFT;
|
||||
}
|
||||
}
|
||||
|
||||
$post->save();
|
||||
|
||||
if ($data['action'] === 'submit') {
|
||||
$count = $this->workflow->submit($post, $user);
|
||||
$message = $count > 0
|
||||
? "Zur Freigabe eingereicht – {$count} ".($count === 1 ? 'Person wurde' : 'Personen wurden').' benachrichtigt.'
|
||||
: 'Zur Freigabe eingereicht.';
|
||||
} elseif ($data['action'] === 'publish') {
|
||||
$this->workflow->approve($post, $user, isset($data['published_at']) ? Carbon::parse($data['published_at']) : null);
|
||||
$message = $post->isScheduled() ? 'Beitrag geplant.' : 'Beitrag veröffentlicht.';
|
||||
} else {
|
||||
$message = 'Entwurf gespeichert.';
|
||||
}
|
||||
|
||||
return to_route('news.editor.edit', $post)->with('status', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>|true
|
||||
*/
|
||||
private function writableCategoryIds(Request $request): array|true
|
||||
{
|
||||
return $request->user()->can('news.manage') ? true : $request->user()->permissions()->ids('news.post.create', 'news_category');
|
||||
}
|
||||
|
||||
private function form(Request $request, ?NewsPost $post): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$writable = $this->writableCategoryIds($request);
|
||||
$categories = NewsCategory::query()->orderBy('sort')->orderBy('name')
|
||||
->when($writable !== true, fn ($q) => $q->whereIn('id', $writable))
|
||||
->get(['id', 'name']);
|
||||
|
||||
return Inertia::render('news::Editor', [
|
||||
'post' => $post ? [
|
||||
'id' => $post->id,
|
||||
'title' => $post->title,
|
||||
'teaser' => $post->teaser,
|
||||
'body' => $post->body,
|
||||
'category_id' => $post->category_id,
|
||||
'cover_url' => $post->coverUrl('large'),
|
||||
'is_featured' => $post->is_featured,
|
||||
'published_at' => $post->published_at?->toIso8601String(),
|
||||
'status' => $post->status,
|
||||
'status_label' => $post->statusLabel(),
|
||||
'is_published' => $post->isPublished(),
|
||||
'url' => $post->isPublished() ? route('news.show', $post) : null,
|
||||
'review_note' => $post->review_note,
|
||||
'author' => $post->author?->name,
|
||||
] : null,
|
||||
'categories' => $categories->map(fn (NewsCategory $c) => [
|
||||
'id' => $c->id,
|
||||
'name' => $c->name,
|
||||
'can_publish' => $this->policy->publish($user, $c->id),
|
||||
]),
|
||||
'canPublishWithoutCategory' => $user->can('news.manage'),
|
||||
'canDelete' => $post && $user->can('delete', $post) && ($post->status !== NewsPost::PUBLISHED || $this->policy->publish($user, $post->category_id)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue