Pflichtlektüre für Neuigkeiten (0.59.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 8m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 7m39s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 12m30s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 17m0s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m43s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 24m25s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 11m16s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 3m39s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 10m40s

Beiträge mit Lesebestätigung (namentlich), Frist, Aufgabe und Feed-Hinweis;
Auswertung für die Redaktion (bestätigt von / wer fehlt).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-10-01 15:16:16 +00:00
parent 799a075cd2
commit 443599b739
149 changed files with 716 additions and 376 deletions

View file

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Pflichtlektüre: Beiträge mit Lesebestätigung („Gelesen und verstanden“), namentlich festgehalten.
*/
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasColumn('news_posts', 'must_read')) {
Schema::table('news_posts', function (Blueprint $table) {
$table->boolean('must_read')->default(false)->after('comments_enabled');
$table->date('must_read_until')->nullable()->after('must_read');
});
}
if (! Schema::hasTable('news_acknowledgements')) {
Schema::create('news_acknowledgements', function (Blueprint $table) {
$table->id();
$table->foreignId('post_id')->constrained('news_posts')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamp('acknowledged_at');
$table->unique(['post_id', 'user_id']);
});
}
}
public function down(): void
{
Schema::dropIfExists('news_acknowledgements');
if (Schema::hasColumn('news_posts', 'must_read')) {
Schema::table('news_posts', fn (Blueprint $table) => $table->dropColumn(['must_read', 'must_read_until']));
}
}
};

View file

@ -84,6 +84,8 @@ const form = useForm({
published_at: localValue(props.post?.published_at),
form_id: props.post?.form_id ?? null,
comments_enabled: props.post?.comments_enabled ?? true,
must_read: props.post?.must_read ?? false,
must_read_until: props.post?.must_read_until ?? '',
action: 'draft',
});
@ -644,6 +646,17 @@ function autoGrow(event) {
<Switch v-model="form.comments_enabled" />
</label>
<div class="grid gap-2">
<label class="flex items-center justify-between gap-3 text-[13px] font-medium">
Pflichtlektüre mit Lesebestätigung
<Switch v-model="form.must_read" />
</label>
<p class="-mt-1 text-xs text-muted-foreground">Alle, die den Beitrag sehen, bestätigen „Gelesen und verstanden“. Er steht dann unter „Meine Aufgaben“; Sie sehen, wer noch fehlt.</p>
<FormField v-if="form.must_read" id="must_read_until" label="Bestätigen bis (optional)" :error="form.errors.must_read_until">
<Input id="must_read_until" v-model="form.must_read_until" type="date" />
</FormField>
</div>
<FormField v-if="forms.length" id="form_id" label="Formular unter dem Beitrag" :error="form.errors.form_id" hint="Z. B. Anmeldung oder Rückmeldung zum Beitrag.">
<NativeSelect id="form_id" v-model="form.form_id" :options="forms" placeholder="– kein Formular –" />
</FormField>

View file

@ -2,7 +2,7 @@
import { computed, ref, watch } from 'vue';
import { Link, router } from '@inertiajs/vue3';
import { useWindowScroll } from '@vueuse/core';
import { CalendarDays, ChartNoAxesColumn, Check, Clock, Heart, Link2, Mail, MessageCircle, PenLine } from '@lucide/vue';
import { CalendarDays, ChartNoAxesColumn, Check, CircleCheck, Clock, FileCheck2, Heart, Link2, LoaderCircle, Mail, MessageCircle, PenLine } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import EasyLanguageBar from '@/components/EasyLanguageBar.vue';
import PageHeader from '@/components/PageHeader.vue';
@ -22,8 +22,21 @@ const props = defineProps({
comments: { type: Object, default: null },
reach: { type: Object, default: null },
easy: { type: Object, default: null },
// Pflichtlektüre: { until, acknowledged_at } bzw. für die Redaktion { confirmed, audience, missing }
mustRead: { type: Object, default: null },
mustReadReport: { type: Object, default: null },
});
const acknowledging = ref(false);
const showMissing = ref(false);
function acknowledge() {
router.post(`/neuigkeiten/${props.post.slug}/gelesen`, {}, {
preserveScroll: true,
onStart: () => (acknowledging.value = true),
onFinish: () => (acknowledging.value = false),
});
}
const showEasy = ref(false);
const body = ref(null);
@ -123,6 +136,12 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
</div>
</div>
<!-- Pflichtlektüre: Hinweis oben -->
<div v-if="mustRead && !mustRead.acknowledged_at" class="mb-6 flex items-start gap-3 rounded-lg border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100">
<FileCheck2 class="mt-0.5 size-5 shrink-0" />
<p><strong>Pflichtlektüre:</strong> Bitte lesen Sie den Beitrag und bestätigen Sie am Ende „Gelesen und verstanden“<template v-if="mustRead.until"> – bis {{ formatDate(mustRead.until) }}</template>.</p>
</div>
<EasyLanguageBar v-model="showEasy" :easy="easy" :read-source="() => `${post.title}.\n${post.teaser ?? ''}\n${body?.innerText ?? ''}`" class="-mt-2 mb-6" />
<div ref="body">
@ -137,6 +156,18 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
/>
</div>
<!-- Pflichtlektüre: Bestätigung am Ende -->
<div v-if="mustRead" class="mt-10 flex flex-wrap items-center gap-4 rounded-lg border p-5" :class="mustRead.acknowledged_at ? 'border-emerald-300 bg-emerald-50 dark:border-emerald-800 dark:bg-emerald-950/40' : 'bg-muted/50'">
<template v-if="mustRead.acknowledged_at">
<CircleCheck class="size-6 shrink-0 text-emerald-700 dark:text-emerald-400" />
<p class="flex-1 text-sm">Sie haben diesen Beitrag am {{ formatDate(mustRead.acknowledged_at) }} gelesen und bestätigt.</p>
</template>
<template v-else>
<p class="min-w-0 flex-1 text-sm"><strong>Gelesen?</strong> Bitte bestätigen Sie, dass Sie den Inhalt gelesen und verstanden haben.</p>
<Button :disabled="acknowledging" @click="acknowledge"><LoaderCircle v-if="acknowledging" class="animate-spin" /><Check v-else /> Gelesen und verstanden</Button>
</template>
</div>
<!-- Eingebundenes Formular (Pagebuilder-Block des Formular-Plugins) -->
<PageContent v-if="form" :content="form" class="mt-10" />
@ -174,6 +205,21 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
</Link>
</section>
<!-- Pflichtlektüre: wer hat bestätigt (Redaktion) -->
<section v-if="mustReadReport" class="rounded-xl border bg-card p-5 shadow-xs">
<h2 class="mb-3 flex items-center gap-1.5 text-xs font-semibold tracking-wider text-muted-foreground uppercase"><FileCheck2 class="size-3.5" /> Lesebestätigungen</h2>
<p class="text-2xl font-semibold tabular-nums">{{ mustReadReport.confirmed }} <span class="text-base font-normal text-muted-foreground">von {{ mustReadReport.audience }}</span></p>
<div class="mt-2 h-2 overflow-hidden rounded-full bg-muted"><div class="h-full rounded-full bg-brand" :style="{ width: `${mustReadReport.audience ? Math.round((mustReadReport.confirmed / mustReadReport.audience) * 100) : 0}%` }" /></div>
<div v-if="mustReadReport.missing.length" class="mt-4 border-t pt-3">
<button type="button" class="text-[13px] font-medium text-brand-text hover:underline" @click="showMissing = !showMissing">
{{ showMissing ? 'Ausblenden' : `Wer fehlt noch? (${mustReadReport.audience - mustReadReport.confirmed})` }}
</button>
<ul v-if="showMissing" class="mt-2 grid max-h-64 gap-1 overflow-y-auto text-[13px]">
<li v-for="name in mustReadReport.missing" :key="name">{{ name }}</li>
</ul>
</div>
</section>
<!-- Reichweite: nur für die Redaktion der Kategorie -->
<section v-if="reach" class="rounded-xl border bg-card p-5 shadow-xs">
<h2 class="mb-3 flex items-center gap-1.5 text-xs font-semibold tracking-wider text-muted-foreground uppercase"><ChartNoAxesColumn class="size-3.5" /> Reichweite</h2>

View file

@ -1,6 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
use Inhaus\Plugins\News\Http\Controllers\NewsAcknowledgementController;
use Inhaus\Plugins\News\Http\Controllers\NewsCommentController;
use Inhaus\Plugins\News\Http\Controllers\NewsController;
use Inhaus\Plugins\News\Http\Controllers\NewsEditorController;
@ -12,6 +13,7 @@ Route::middleware('auth')->group(function () {
Route::post('/neuigkeiten/{post:slug}/kommentare', [NewsCommentController::class, 'store'])->middleware('throttle:20,1')->name('news.comments.store');
Route::post('/neuigkeiten/{post:slug}/herz', [NewsLikeController::class, 'store'])->middleware('throttle:60,1')->name('news.like');
Route::delete('/neuigkeiten/{post:slug}/herz', [NewsLikeController::class, 'destroy'])->middleware('throttle:60,1')->name('news.unlike');
Route::post('/neuigkeiten/{post:slug}/gelesen', [NewsAcknowledgementController::class, 'store'])->middleware('throttle:30,1')->name('news.acknowledge');
Route::put('/kommentare/{comment}', [NewsCommentController::class, 'update'])->name('news.comments.update');
Route::delete('/kommentare/{comment}', [NewsCommentController::class, 'destroy'])->name('news.comments.destroy');

View file

@ -0,0 +1,22 @@
<?php
namespace Inhaus\Plugins\News\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inhaus\Plugins\News\Models\NewsPost;
use Inhaus\Plugins\News\MustRead;
class NewsAcknowledgementController extends Controller
{
/** „Gelesen und verstanden“ bei einer Pflichtlektüre */
public function store(Request $request, NewsPost $post, MustRead $mustRead): RedirectResponse
{
abort_unless($post->isPublished() && $post->isVisibleTo($request->user()) && $post->must_read, 404);
$mustRead->acknowledge($post, $request->user());
return back()->with('status', 'Danke – Ihre Lesebestätigung ist gespeichert.');
}
}

View file

@ -14,6 +14,7 @@ use Inhaus\Plugins\News\Http\Resources\NewsPostResource;
use Inhaus\Plugins\News\Models\NewsCategory;
use Inhaus\Plugins\News\Models\NewsComment;
use Inhaus\Plugins\News\Models\NewsPost;
use Inhaus\Plugins\News\MustRead;
use Inhaus\Plugins\News\Reach;
class NewsController extends Controller
@ -80,6 +81,9 @@ class NewsController extends Controller
] : null,
],
'editUrl' => $canEdit ? route('news.editor.edit', $post) : null,
// Pflichtlektüre: Frist und eigene Bestätigung; für die Redaktion, wer noch fehlt
'mustRead' => app(MustRead::class)->status($post, $user),
'mustReadReport' => $canEdit && $post->must_read ? app(MustRead::class)->report($post) : null,
'easy' => app(EasyLanguage::class)->props('news', $post->id, $user, $canEdit),
// Reichweite und wer ein Herz gegeben hat: nur für die Redaktion der Kategorie
'reach' => $canEdit ? [

View file

@ -153,6 +153,8 @@ class NewsEditorController extends Controller
'cover_media' => ['nullable', 'string', 'max:500', Rule::exists('media', 'path')],
'is_featured' => ['boolean'],
'comments_enabled' => ['boolean'],
'must_read' => ['boolean'],
'must_read_until' => ['nullable', 'date'],
'published_at' => ['nullable', 'date'],
'form_id' => ['nullable', 'integer', Rule::in(array_map('intval', array_keys(FormEmbed::options())))],
'action' => ['required', Rule::in(['draft', 'submit', 'publish'])],
@ -177,6 +179,8 @@ class NewsEditorController extends Controller
'category_id' => $data['category_id'] ?? null,
'form_id' => FormEmbed::available() ? ($data['form_id'] ?? null) : $post->form_id,
'comments_enabled' => $request->boolean('comments_enabled', $post->comments_enabled ?? true),
'must_read' => $request->boolean('must_read', $post->must_read ?? false),
'must_read_until' => $request->boolean('must_read', $post->must_read ?? false) ? ($data['must_read_until'] ?? null) : null,
]);
if ($canPublish) {
@ -254,6 +258,8 @@ class NewsEditorController extends Controller
'review_note' => $post->review_note,
'form_id' => $post->form_id,
'comments_enabled' => $post->comments_enabled,
'must_read' => (bool) $post->must_read,
'must_read_until' => $post->must_read_until?->toDateString(),
'author' => $post->author?->name,
] : null,
'categories' => $categories->map(fn (NewsCategory $c) => [

View file

@ -0,0 +1,34 @@
<?php
namespace Inhaus\Plugins\News\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Lesebestätigung einer Pflichtlektüre („Gelesen und verstanden“).
*/
#[Fillable(['post_id', 'user_id', 'acknowledged_at'])]
class NewsAcknowledgement extends Model
{
public $timestamps = false;
protected $table = 'news_acknowledgements';
protected function casts(): array
{
return ['acknowledged_at' => 'datetime'];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function post(): BelongsTo
{
return $this->belongsTo(NewsPost::class, 'post_id');
}
}

View file

@ -18,6 +18,7 @@ use Inhaus\Plugins\News\Database\Factories\NewsPostFactory;
#[Fillable([
'category_id', 'author_id', 'title', 'slug', 'teaser', 'body',
'cover_path', 'is_featured', 'published_at', 'form_id', 'content', 'comments_enabled',
'must_read', 'must_read_until',
])]
class NewsPost extends Model
{
@ -74,6 +75,8 @@ class NewsPost extends Model
'is_featured' => 'boolean',
'content' => 'array',
'comments_enabled' => 'boolean',
'must_read' => 'boolean',
'must_read_until' => 'date',
'published_at' => 'datetime',
'submitted_at' => 'datetime',
'form_id' => 'integer',
@ -214,6 +217,12 @@ class NewsPost extends Model
});
}
/** Pflichtlektüre: wer „Gelesen und verstanden“ bestätigt hat */
public function acknowledgements(): HasMany
{
return $this->hasMany(NewsAcknowledgement::class, 'post_id');
}
public function isVisibleTo(?User $user): bool
{
return $this->category_id === null || $user?->can('news.manage') || Audiences::allows('news_category', $this->category_id, $user);

View file

@ -0,0 +1,79 @@
<?php
namespace Inhaus\Plugins\News;
use App\Models\User;
use Illuminate\Support\Collection;
use Inhaus\Plugins\News\Models\NewsAcknowledgement;
use Inhaus\Plugins\News\Models\NewsPost;
/**
* Pflichtlektüre: Beiträge, die alle Lesenden mit „Gelesen und verstanden“ bestätigen sollen.
* Anders als die (anonyme) Reichweite wird hier namentlich festgehalten, wer bestätigt hat.
*/
class MustRead
{
/** @return Collection<int, NewsPost> offene Pflichtlektüren einer Person */
public function open(User $user): Collection
{
return NewsPost::query()->published()->visibleTo($user)
->where('must_read', true)
->whereDoesntHave('acknowledgements', fn ($query) => $query->where('user_id', $user->id))
->orderByRaw('must_read_until is null')->orderBy('must_read_until')->latest('published_at')
->get();
}
public function acknowledge(NewsPost $post, User $user): void
{
NewsAcknowledgement::query()->insertOrIgnore([
'post_id' => $post->id,
'user_id' => $user->id,
'acknowledged_at' => now(),
]);
}
/**
* Für die Lesenden: Frist und ob bestätigt – null, wenn keine Pflichtlektüre.
*
* @return array{until: string|null, acknowledged_at: string|null}|null
*/
public function status(NewsPost $post, User $user): ?array
{
if (! $post->must_read) {
return null;
}
$acknowledgement = $post->acknowledgements()->where('user_id', $user->id)->first();
return [
'until' => $post->must_read_until?->toDateString(),
'acknowledged_at' => $acknowledgement?->acknowledged_at?->toIso8601String(),
];
}
/**
* Für die Redaktion: wie viele von wie vielen bestätigt haben, und wer noch fehlt.
*
* @return array{confirmed: int, audience: int, missing: list<string>}
*/
public function report(NewsPost $post): array
{
$confirmed = $post->acknowledgements()->pluck('user_id')->flip();
$audience = 0;
$missing = [];
User::query()->active()->orderBy('last_name')->orderBy('first_name')->limit(5000)->get()
->each(function (User $user) use ($post, $confirmed, &$audience, &$missing) {
if (! $post->isVisibleTo($user)) {
return;
}
$audience++;
if (! $confirmed->has($user->id) && count($missing) < 300) {
$missing[] = $user->name;
}
});
return ['confirmed' => $confirmed->count(), 'audience' => $audience, 'missing' => $missing];
}
}

View file

@ -19,6 +19,7 @@ use App\Profile\ProfilePanels;
use App\Search\GlobalSearch;
use App\Support\Abilities;
use App\Support\Navigation;
use App\Tasks\Tasks;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
@ -197,10 +198,23 @@ class NewsPlugin extends Plugin
private function registerWidgets(Widgets $widgets): void
{
// Meine Aufgaben: offene Pflichtlektüren
if (class_exists(Tasks::class)) {
$this->app->make(Tasks::class)->add('news', fn (User $user) => $this->app->make(MustRead::class)->open($user)
->map(fn (NewsPost $post) => [
'title' => '„'.$post->title.'“ lesen und bestätigen',
'meta' => 'Pflichtlektüre',
'url' => '/neuigkeiten/'.$post->slug,
'icon' => 'newspaper',
'due' => $post->must_read_until?->toDateString(),
])->all(), sort: 20);
}
// Feed der Mitarbeiter-App: jede Neuigkeit als Beitrag ihrer Autorin bzw. ihres Autors
if (class_exists(Feed::class)) {
$this->app->make(Feed::class)->add('news', fn (User $user, ?CarbonImmutable $before, int $limit) => NewsPost::query()
->published()->visibleTo($user)->with(['category', 'author'])->withStats($user)
->withExists(['acknowledgements as acknowledged' => fn ($query) => $query->where('user_id', $user->id)])
->when($before, fn ($query) => $query->where('published_at', '<', $before))
->latest('published_at')->limit($limit)->get()
->map(fn (NewsPost $post) => [
@ -208,9 +222,10 @@ class NewsPlugin extends Plugin
'time' => $post->published_at,
'actor' => Feed::person($post->author),
'action' => 'hat eine Neuigkeit veröffentlicht',
'badge' => $post->category?->name,
'badge' => $post->must_read && ! $post->acknowledged ? 'Pflichtlektüre' : $post->category?->name,
'title' => $post->title,
'text' => (string) $post->teaser,
'cta' => $post->must_read && ! $post->acknowledged ? ['label' => 'Lesen und bestätigen', 'url' => '/neuigkeiten/'.$post->slug] : null,
'image_url' => $post->coverUrl('large'),
'url' => '/neuigkeiten/'.$post->slug,
'stats' => ['likes' => (int) ($post->likes_count ?? 0), 'comments' => $post->comments_enabled ? (int) ($post->comments_count ?? 0) : null],