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
56
plugins-core/news/src/EditorialNews.php
Normal file
56
plugins-core/news/src/EditorialNews.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News;
|
||||
|
||||
use App\Models\User;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
||||
/**
|
||||
* „Redaktion → Neuigkeiten“: eigene Entwürfe, Beiträge zur Freigabe und Geplantes.
|
||||
*/
|
||||
final class EditorialNews
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function props(User $user): array
|
||||
{
|
||||
$publishable = $user->can('news.manage') ? true : $user->permissions()->ids('news.post.publish', 'news_category');
|
||||
$writable = $user->can('news.manage') ? true : $user->permissions()->ids('news.post.create', 'news_category');
|
||||
|
||||
$map = fn (NewsPost $post) => [
|
||||
'id' => $post->id,
|
||||
'title' => $post->title,
|
||||
'category' => $post->category?->name,
|
||||
'author' => $post->author?->name,
|
||||
'status' => $post->status,
|
||||
'status_label' => $post->statusLabel(),
|
||||
'review_note' => $post->review_note,
|
||||
'date' => ($post->published_at ?? $post->submitted_at ?? $post->updated_at)?->toIso8601String(),
|
||||
'edit_url' => route('news.editor.edit', $post),
|
||||
];
|
||||
|
||||
$review = $publishable === [] ? collect() : NewsPost::query()->with(['category', 'author'])
|
||||
->where('status', NewsPost::PENDING)
|
||||
->when($publishable !== true, fn ($q) => $q->whereIn('category_id', $publishable))
|
||||
->oldest('submitted_at')->limit(20)->get();
|
||||
|
||||
$mine = NewsPost::query()->with(['category', 'author'])
|
||||
->where('author_id', $user->id)
|
||||
->where(fn ($q) => $q->whereIn('status', [NewsPost::DRAFT, NewsPost::PENDING])->orWhere('published_at', '>', now()))
|
||||
->latest('updated_at')->limit(20)->get();
|
||||
|
||||
$scheduled = NewsPost::query()->with(['category', 'author'])
|
||||
->where('status', NewsPost::PUBLISHED)->where('published_at', '>', now())
|
||||
->when($writable !== true, fn ($q) => $q->whereIn('category_id', $writable ?: [0]))
|
||||
->whereKeyNot($mine->modelKeys())
|
||||
->oldest('published_at')->limit(20)->get();
|
||||
|
||||
return [
|
||||
'review' => $review->map($map)->all(),
|
||||
'mine' => $mine->map($map)->all(),
|
||||
'scheduled' => $scheduled->map($map)->all(),
|
||||
'canCreate' => app(Policies\NewsPostPolicy::class)->create($user),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -158,14 +158,10 @@ class NewsPostResource extends Resource
|
|||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->state(fn (NewsPost $record) => match (true) {
|
||||
$record->published_at === null => 'Entwurf',
|
||||
$record->published_at->isFuture() => 'Geplant',
|
||||
default => 'Veröffentlicht',
|
||||
})
|
||||
->state(fn (NewsPost $record) => $record->statusLabel())
|
||||
->color(fn (string $state) => match ($state) {
|
||||
'Veröffentlicht' => 'success',
|
||||
'Geplant' => 'warning',
|
||||
'Geplant', 'Zur Freigabe' => 'warning',
|
||||
default => 'gray',
|
||||
}),
|
||||
IconColumn::make('is_featured')->label('Hervorgehoben')->boolean()->trueIcon(Heroicon::Star)->falseIcon(false)->trueColor('warning'),
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,12 @@ class NewsPost extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
public const DRAFT = 'draft';
|
||||
|
||||
public const PENDING = 'pending';
|
||||
|
||||
public const PUBLISHED = 'published';
|
||||
|
||||
protected static function newFactory(): NewsPostFactory
|
||||
{
|
||||
return NewsPostFactory::new();
|
||||
|
|
@ -34,6 +40,13 @@ class NewsPost extends Model
|
|||
$post->slug = static::uniqueSlug($post->title, $post->getKey());
|
||||
}
|
||||
|
||||
// Ein Veröffentlichungsdatum bedeutet „veröffentlicht“ (bzw. geplant) – auch aus dem Admin-Formular.
|
||||
if ($post->published_at !== null) {
|
||||
$post->status = self::PUBLISHED;
|
||||
} elseif ($post->status === self::PUBLISHED || $post->status === null) {
|
||||
$post->status = self::DRAFT;
|
||||
}
|
||||
|
||||
if ($post->isDirty('body') || $post->body_html === null) {
|
||||
$richText = app(RichText::class);
|
||||
$post->body_html = $richText->toSafeHtml($post->body);
|
||||
|
|
@ -66,6 +79,7 @@ class NewsPost extends Model
|
|||
return [
|
||||
'is_featured' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'submitted_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +91,14 @@ class NewsPost extends Model
|
|||
return $this->belongsTo(NewsCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function reviewer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'reviewed_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
|
|
@ -92,12 +114,27 @@ class NewsPost extends Model
|
|||
*/
|
||||
public function scopePublished(Builder $query): void
|
||||
{
|
||||
$query->whereNotNull('published_at')->where('published_at', '<=', now());
|
||||
$query->where('news_posts.status', self::PUBLISHED)->whereNotNull('published_at')->where('published_at', '<=', now());
|
||||
}
|
||||
|
||||
public function isPublished(): bool
|
||||
{
|
||||
return $this->published_at !== null && $this->published_at->isPast();
|
||||
return $this->status === self::PUBLISHED && $this->published_at !== null && $this->published_at->isPast();
|
||||
}
|
||||
|
||||
public function isScheduled(): bool
|
||||
{
|
||||
return $this->status === self::PUBLISHED && $this->published_at?->isFuture();
|
||||
}
|
||||
|
||||
public function statusLabel(): string
|
||||
{
|
||||
return match (true) {
|
||||
$this->status === self::PENDING => 'Zur Freigabe',
|
||||
$this->isScheduled() => 'Geplant',
|
||||
$this->isPublished() => 'Veröffentlicht',
|
||||
default => 'Entwurf',
|
||||
};
|
||||
}
|
||||
|
||||
public function coverUrl(string $variant = 'large'): ?string
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@
|
|||
namespace Inhaus\Plugins\News;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Editorial\Editorial;
|
||||
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;
|
||||
|
|
@ -20,7 +24,7 @@ class NewsPlugin extends Plugin
|
|||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20);
|
||||
$this->app->make(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: ['news.index', 'news.show'], sort: 20);
|
||||
|
||||
$abilities = $this->app->make(Abilities::class);
|
||||
$abilities->define('news.manage', 'Neuigkeiten: alle Kategorien verwalten', 'Neuigkeiten');
|
||||
|
|
@ -32,6 +36,34 @@ class NewsPlugin extends Plugin
|
|||
Gate::policy(NewsPost::class, NewsPostPolicy::class);
|
||||
|
||||
$this->registerWidgets($this->app->make(Widgets::class));
|
||||
|
||||
$this->app->make(Editorial::class)->add(
|
||||
'news',
|
||||
'Neuigkeiten',
|
||||
'news::EditorialNews',
|
||||
10,
|
||||
fn (User $user) => app(NewsPostPolicy::class)->viewAny($user),
|
||||
fn (User $user) => EditorialNews::props($user),
|
||||
);
|
||||
|
||||
$this->app->make(Blocks::class)->add(BlockType::make('news.latest', 'Neuigkeiten', 'newspaper', 'dynamic', 'news::LatestNews')
|
||||
->description('Die neuesten Beiträge – optional nur aus einer Kategorie.')
|
||||
->fields([
|
||||
Field::text('title', 'Überschrift', 150, 'Neuigkeiten'),
|
||||
Field::select('category', 'Kategorie', fn () => ['' => 'Alle Kategorien'] + NewsCategory::query()->orderBy('sort')->pluck('name', 'slug')->all(), ''),
|
||||
Field::number('count', 'Anzahl', 1, 12, 3),
|
||||
Field::select('layout', 'Darstellung', ['cards' => 'Kacheln', 'list' => 'Liste'], 'cards'),
|
||||
])
|
||||
->resolveUsing(function (array $data, ?User $user) {
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
->when($data['category'], fn ($q, $slug) => $q->whereHas('category', fn ($c) => $c->where('slug', $slug)))
|
||||
->latest('published_at')->limit($data['count'])->get();
|
||||
|
||||
return [
|
||||
'posts' => NewsPostResource::collection($posts)->resolve(),
|
||||
'more_url' => '/neuigkeiten'.($data['category'] ? '?kategorie='.$data['category'] : ''),
|
||||
];
|
||||
}));
|
||||
}
|
||||
|
||||
private function registerWidgets(Widgets $widgets): void
|
||||
|
|
|
|||
95
plugins-core/news/src/NewsWorkflow.php
Normal file
95
plugins-core/news/src/NewsWorkflow.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
||||
/**
|
||||
* Freigabe-Workflow für Beiträge: Einreichen, Freigeben, Zurückgeben –
|
||||
* mit Benachrichtigungen an Redaktion bzw. Autorin/Autor.
|
||||
*/
|
||||
class NewsWorkflow
|
||||
{
|
||||
public function submit(NewsPost $post, User $user): int
|
||||
{
|
||||
$post->forceFill(['status' => NewsPost::PENDING, 'submitted_at' => now(), 'published_at' => null, 'review_note' => null])->save();
|
||||
|
||||
$recipients = $this->publishers($post->category_id, $user);
|
||||
|
||||
Notification::send($recipients, new PortalNotification(
|
||||
'Beitrag zur Freigabe: '.$post->title,
|
||||
$user->name.' hat einen Beitrag eingereicht.',
|
||||
route('news.editor.edit', $post),
|
||||
'file-check',
|
||||
));
|
||||
|
||||
Audit::log('news.submitted', ['post' => $post->id, 'title' => $post->title]);
|
||||
|
||||
return $recipients->count();
|
||||
}
|
||||
|
||||
public function approve(NewsPost $post, User $reviewer, ?\DateTimeInterface $at = null): void
|
||||
{
|
||||
$wasPending = $post->status === NewsPost::PENDING;
|
||||
|
||||
$post->forceFill([
|
||||
'status' => NewsPost::PUBLISHED,
|
||||
'published_at' => $at ?? now(),
|
||||
'reviewed_by' => $reviewer->id,
|
||||
'review_note' => null,
|
||||
])->save();
|
||||
|
||||
if ($wasPending && $post->author && ! $post->author->is($reviewer)) {
|
||||
$post->author->notify(new PortalNotification(
|
||||
($post->isScheduled() ? 'Beitrag freigegeben und geplant: ' : 'Beitrag veröffentlicht: ').$post->title,
|
||||
'Freigegeben von '.$reviewer->name.'.',
|
||||
$post->isScheduled() ? route('news.editor.edit', $post) : route('news.show', $post),
|
||||
'newspaper',
|
||||
));
|
||||
}
|
||||
|
||||
Audit::log('news.published', ['post' => $post->id, 'title' => $post->title, 'at' => $post->published_at?->toIso8601String()]);
|
||||
}
|
||||
|
||||
public function reject(NewsPost $post, User $reviewer, string $note): void
|
||||
{
|
||||
$post->forceFill(['status' => NewsPost::DRAFT, 'published_at' => null, 'reviewed_by' => $reviewer->id, 'review_note' => $note])->save();
|
||||
|
||||
$post->author?->notify(new PortalNotification(
|
||||
'Beitrag zurückgegeben: '.$post->title,
|
||||
$reviewer->name.': '.$note,
|
||||
route('news.editor.edit', $post),
|
||||
'undo',
|
||||
));
|
||||
|
||||
Audit::log('news.returned', ['post' => $post->id, 'title' => $post->title]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wer in der Kategorie veröffentlichen darf.
|
||||
*
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function publishers(?int $categoryId, ?User $except = null): Collection
|
||||
{
|
||||
$roleIds = DB::table('grants')
|
||||
->where(function ($q) use ($categoryId) {
|
||||
$q->whereIn('ability', ['*', 'news.manage'])->whereNull('resource_type');
|
||||
$q->orWhere(fn ($q) => $q->where('ability', 'news.post.publish')->where('resource_type', 'news_category')
|
||||
->where(fn ($q) => $q->whereNull('resource_id')->when($categoryId, fn ($q) => $q->orWhere('resource_id', $categoryId))));
|
||||
})
|
||||
->pluck('role_id');
|
||||
|
||||
return User::query()->active()
|
||||
->whereIn('id', DB::table('role_user')->whereIn('role_id', $roleIds)->select('user_id'))
|
||||
->when($except, fn ($q) => $q->whereKeyNot($except->id))
|
||||
->limit(50)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue