diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b465a0..78deef3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Neueste Version oben. Jeder Abschnitt beginnt mit `## MAJOR.MINOR.PATCH` und enthält kurze Stichpunkte für Anwenderinnen und Anwender – keine Commit-Texte. Der Self-Updater zeigt diese Abschnitte bei neuen Versionen an. +## 0.36.0 + +- Wochenüberblick per E-Mail: Wer möchte, schaltet ihn im Profil ein und bekommt einmal pro Woche Neuigkeiten, anstehende Termine, offene Umfragen, neue Ideen und neue Stellen – nur, was die Person im Portal sehen darf. In Wochen ohne Neues kommt keine E-Mail +- Abbestellen mit einem Klick aus der E-Mail (auch direkt im E-Mail-Programm), ohne Anmeldung +- Administration unter „Portal → Wochenüberblick“: Tag und Uhrzeit, ganz abschalten, Vorschau an sich selbst senden + +- Ideenbox: Ideen und Kommentare lassen sich melden (beleidigend, nennt Personen, vertraulich, Spam, Sonstiges). Das Gremium bekommt Bescheid und sieht Grund und Anmerkung – nicht, wer gemeldet hat +- Ab drei Meldungen verschiedener Personen wird der Inhalt vorläufig ausgeblendet, bis das Gremium entscheidet: „In Ordnung – behalten“ oder „Löschen“ +- Gemeldete Ideen stehen in der Redaktion oben unter „Gemeldet“ + ## 0.35.0 - KI-Assistent: Neben Anthropic jetzt auch OpenAI bzw. OpenAI-kompatible Dienste (z. B. Mistral, IONOS, OpenRouter) und Ollama auf einem eigenen Server – dann bleibt der Text im eigenen Netz diff --git a/app/Digest/Digest.php b/app/Digest/Digest.php new file mode 100644 index 00000000..3b8f8f21 --- /dev/null +++ b/app/Digest/Digest.php @@ -0,0 +1,120 @@ +add('news', 'Neuigkeiten', 10, fn (User $user, CarbonImmutable $since) => [ + * ['title' => '…', 'url' => '…', 'meta' => '…', 'text' => '…'], … + * ]); + * + * Es gilt, was die Person im Portal sieht. Leere Abschnitte fallen weg; ist alles leer, + * geht keine E-Mail raus. + */ +class Digest +{ + public const WEEKDAYS = [1 => 'Montag', 2 => 'Dienstag', 3 => 'Mittwoch', 4 => 'Donnerstag', 5 => 'Freitag', 6 => 'Samstag', 7 => 'Sonntag']; + + /** @var array */ + private array $sections = []; + + public function __construct(private readonly Settings $settings) {} + + public function add(string $key, string $label, int $sort, callable $items): void + { + $this->sections[$key] = ['label' => $label, 'sort' => $sort, 'items' => $items]; + } + + public function enabled(): bool + { + return (bool) $this->settings->get('digest.enabled', true); + } + + public function weekday(): int + { + return (int) $this->settings->get('digest.weekday', 1); + } + + public function hour(): int + { + return (int) $this->settings->get('digest.hour', 7); + } + + /** „montags ab 7 Uhr“ */ + public function scheduleLabel(): string + { + return mb_strtolower(self::WEEKDAYS[$this->weekday()]).'s ab '.$this->hour().' Uhr'; + } + + /** + * @return list>}> + */ + public function build(User $user, CarbonImmutable $since): array + { + $access = app(PluginAccess::class); + + return collect($this->sections) + ->filter(fn ($section, $key) => $access->allows($key.'.digest', $user)) + ->sortBy('sort') + ->map(function (array $section, string $key) use ($user, $since) { + try { + $items = array_values(($section['items'])($user, $since)); + } catch (Throwable $e) { + report($e); + $items = []; + } + + return ['key' => $key, 'label' => $section['label'], 'items' => $items]; + }) + ->filter(fn (array $section) => $section['items'] !== []) + ->values()->all(); + } + + /** + * Stündlich aufgerufen: am eingestellten Tag ab der eingestellten Stunde an alle, + * die ihn eingeschaltet haben – je Person höchstens einmal in sechs Tagen. + */ + public function sendDue(): int + { + $now = CarbonImmutable::now(config('app.timezone')); + + if (! $this->enabled() || $now->dayOfWeekIso !== $this->weekday() || $now->hour < $this->hour()) { + return 0; + } + + $sent = 0; + + User::query()->active()->where('weekly_digest', true)->whereNotNull('email') + ->where(fn ($q) => $q->whereNull('digest_sent_at')->orWhere('digest_sent_at', '<', $now->subDays(6))) + ->chunkById(100, function ($users) use ($now, &$sent) { + foreach ($users as $user) { + $user->forceFill(['digest_sent_at' => $now])->saveQuietly(); + $sent += $this->sendTo($user, $now->subDays(7)) ? 1 : 0; + } + }); + + return $sent; + } + + public function sendTo(User $user, CarbonImmutable $since): bool + { + $sections = $this->build($user, $since); + + if ($sections === []) { + return false; + } + + Mail::to($user)->queue(new WeeklyDigest($user, $sections, $since)); + + return true; + } +} diff --git a/app/Filament/Pages/DigestSettings.php b/app/Filament/Pages/DigestSettings.php new file mode 100644 index 00000000..6a9d4387 --- /dev/null +++ b/app/Filament/Pages/DigestSettings.php @@ -0,0 +1,98 @@ +|null */ + public ?array $data = []; + + public static function canAccess(): bool + { + return auth()->user()?->can('appearance.manage') ?? false; + } + + public function mount(Digest $digest): void + { + $this->form->fill(['enabled' => $digest->enabled(), 'weekday' => $digest->weekday(), 'hour' => $digest->hour()]); + } + + public function form(Schema $schema): Schema + { + $subscribers = User::query()->active()->where('weekly_digest', true)->count(); + + return $schema + ->components([ + Section::make('Versand') + ->columns(2) + ->schema([ + Text::make('Eine E-Mail mit Neuigkeiten, Terminen, offenen Umfragen, neuen Ideen und Stellen der letzten Woche – jeweils nur, was die Person im Portal sehen darf. Sie geht nur an Personen, die den Wochenüberblick in ihrem Profil einschalten (derzeit '.$subscribers.'). Ohne Neues in der Woche wird nichts verschickt.')->columnSpanFull(), + Toggle::make('enabled')->label('Wochenüberblick anbieten')->helperText('Ausgeschaltet verschwindet die Option im Profil, es wird nichts verschickt.')->columnSpanFull(), + Select::make('weekday')->label('Tag')->options(Digest::WEEKDAYS)->required()->native(false)->selectablePlaceholder(false), + Select::make('hour')->label('Ab Uhrzeit')->required()->native(false)->selectablePlaceholder(false) + ->options(collect(range(5, 20))->mapWithKeys(fn ($h) => [$h => sprintf('%02d:00 Uhr', $h)])->all()) + ->helperText('Mit Cronjob pünktlich, ohne Cron beim nächsten Seitenaufruf danach.'), + ]), + ]) + ->statePath('data'); + } + + public function save(Settings $settings): void + { + $state = $this->form->getState(); + $settings->setMany(['digest.enabled' => (bool) $state['enabled'], 'digest.weekday' => (int) $state['weekday'], 'digest.hour' => (int) $state['hour']]); + Audit::log('digest.settings_updated', $state); + + Notification::make()->success()->title('Gespeichert')->send(); + } + + protected function getHeaderActions(): array + { + return [ + Action::make('preview') + ->label('Vorschau an mich senden') + ->icon(Heroicon::OutlinedPaperAirplane) + ->color('gray') + ->action(function (Digest $digest) { + $user = auth()->user(); + $digest->sendTo($user, now()->toImmutable()->subDays(7)) + ? Notification::make()->success()->title('Vorschau an '.$user->email.' verschickt')->send() + : Notification::make()->warning()->title('In der letzten Woche gab es nichts Neues – es wurde nichts verschickt.')->send(); + }), + ]; + } +} diff --git a/app/Http/Controllers/DigestController.php b/app/Http/Controllers/DigestController.php new file mode 100644 index 00000000..ca8c92c0 --- /dev/null +++ b/app/Http/Controllers/DigestController.php @@ -0,0 +1,38 @@ +validate(['enabled' => ['required', 'boolean']]); + $request->user()->forceFill(['weekly_digest' => $data['enabled']])->save(); + + return back()->with('status', $data['enabled'] ? 'Wochenüberblick eingeschaltet.' : 'Wochenüberblick ausgeschaltet.'); + } + + /** Link aus der E-Mail: erst bestätigen, damit Link-Vorschauen nicht versehentlich abbestellen */ + public function confirm(Request $request, User $user): Response + { + return Inertia::render('DigestUnsubscribe', ['done' => ! $user->weekly_digest, 'action' => $request->fullUrl()]); + } + + /** Bestätigung auf der Seite oder Ein-Klick-Abmeldung des E-Mail-Programms (RFC 8058) */ + public function unsubscribe(Request $request, User $user): RedirectResponse|HttpResponse + { + $user->forceFill(['weekly_digest' => false])->save(); + + return $request->header('X-Inertia') ? back() : response('Der Wochenüberblick ist abbestellt.', 200); + } +} diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 58de219b..8097b50a 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Digest\Digest; use App\Http\Requests\UpdateProfileRequest; use App\Models\User; use App\Profile\ProfileSections; @@ -52,6 +53,7 @@ class ProfileController extends Controller 'locked' => $locked, 'customFields' => $profileFields->formFor($user, $managed), 'sections' => app(ProfileSections::class)->resolve($user), + 'digest' => app(Digest::class)->enabled() ? ['enabled' => (bool) $user->weekly_digest, 'schedule' => app(Digest::class)->scheduleLabel()] : null, // Apps & Geräte: persönliche Zugangs-Tokens für die REST-API 'tokens' => $user->tokens()->latest()->get()->map(fn ($token) => [ 'id' => $token->id, diff --git a/app/Mail/WeeklyDigest.php b/app/Mail/WeeklyDigest.php new file mode 100644 index 00000000..59c2a5b7 --- /dev/null +++ b/app/Mail/WeeklyDigest.php @@ -0,0 +1,60 @@ +>}> $sections + */ + public function __construct(public User $user, public array $sections, public CarbonImmutable $since) {} + + public function envelope(): Envelope + { + return new Envelope(subject: 'Ihr Wochenüberblick aus '.app(Branding::class)->portalName()); + } + + public function headers(): Headers + { + // Abmelden mit einem Klick direkt im E-Mail-Programm (RFC 8058) + return new Headers(text: [ + 'List-Unsubscribe' => '<'.$this->unsubscribeUrl().'>', + 'List-Unsubscribe-Post' => 'List-Unsubscribe=One-Click', + ]); + } + + public function content(): Content + { + return new Content(view: 'mail.weekly-digest', with: [ + 'portalName' => app(Branding::class)->portalName(), + 'color' => app(Branding::class)->primaryColor(), + 'portalUrl' => url('/'), + 'profileUrl' => route('profile.edit'), + 'unsubscribeUrl' => $this->unsubscribeUrl(), + 'period' => $this->since->timezone(config('app.timezone'))->format('d.m.').' – '.now(config('app.timezone'))->format('d.m.Y'), + ]); + } + + private function unsubscribeUrl(): string + { + return URL::signedRoute('digest.unsubscribe', ['user' => $this->user->id]); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index cd2cfaaf..7f6f27f4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -83,6 +83,8 @@ class User extends Authenticatable implements FilamentUser, HasAvatar 'custom_fields' => 'array', 'password' => 'hashed', 'is_active' => 'boolean', + 'weekly_digest' => 'boolean', + 'digest_sent_at' => 'datetime', ]; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6da27110..45e08fd1 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -6,6 +6,7 @@ use App\Accessibility\EasyLanguage; use App\Dashboard\CoreWidgets; use App\Dashboard\Homepage; use App\Dashboard\Widgets; +use App\Digest\Digest; use App\Editorial\Editorial; use App\Identity\Entra\EntraDriver; use App\Identity\IdentityDrivers; @@ -64,6 +65,7 @@ class AppServiceProvider extends ServiceProvider $this->app->singleton(Settings::class); $this->app->singleton(EasyLanguage::class); + $this->app->singleton(Digest::class); $this->app->singleton(MailSettings::class); $this->app->singleton(Branding::class); $this->app->singleton(Theme::class); diff --git a/app/Version.php b/app/Version.php index aa1ea230..c8a87829 100644 --- a/app/Version.php +++ b/app/Version.php @@ -9,5 +9,5 @@ namespace App; */ final class Version { - public const VERSION = '0.35.0'; + public const VERSION = '0.36.0'; } diff --git a/bootstrap/app.php b/bootstrap/app.php index bd798b25..5cef070d 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -32,7 +32,7 @@ return Application::configure(basePath: dirname(__DIR__)) $middleware->throttleApi(); // SAML-Antworten kommen per POST vom Anbieter (siehe routes/web.php). - $middleware->validateCsrfTokens(except: ['auth/*/callback']); + $middleware->validateCsrfTokens(except: ['auth/*/callback', 'wochenueberblick/abbestellen/*']); $middleware->web(prepend: [ SecurityHeaders::class, diff --git a/database/migrations/2026_10_20_000002_add_weekly_digest_to_users.php b/database/migrations/2026_10_20_000002_add_weekly_digest_to_users.php new file mode 100644 index 00000000..c18860d7 --- /dev/null +++ b/database/migrations/2026_10_20_000002_add_weekly_digest_to_users.php @@ -0,0 +1,24 @@ +boolean('weekly_digest')->default(false)->after('theme'); + $table->timestamp('digest_sent_at')->nullable()->after('weekly_digest'); + }); + } + + public function down(): void + { + Schema::table('users', fn (Blueprint $table) => $table->dropColumn(['weekly_digest', 'digest_sent_at'])); + } +}; diff --git a/docs/API.md b/docs/API.md index 329ed54f..d752c7f6 100644 --- a/docs/API.md +++ b/docs/API.md @@ -63,6 +63,7 @@ Tokens deaktivierter Konten gelten sofort nicht mehr. | GET | `/ideas/{id}` | Idee mit Beschreibung, Rückmeldung (`status_note`) und Kommentaren (`comment_list`) | | POST | `/ideas` | einreichen: `{ "title": "…", "body": "…", "anonymous": false }` | | POST/DELETE | `/ideas/{id}/support` | unterstützen bzw. zurücknehmen → `{ data: { supported, supports } }` | +| POST | `/ideas/{id}/report` | melden: `{ "reason": "offensive\|personal\|confidential\|spam\|other", "note": "…", "comment_id": null }` | | POST | `/ideas/{id}/comments` | kommentieren: `{ "body": "…" }` | | POST | `/polls/{id}/vote` | abstimmen: `{ "answers": { "": "" \| ["…"] \| 3 \| "Text" } }` | diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md index bfcb9aac..a452cb6c 100644 --- a/docs/PLUGINS.md +++ b/docs/PLUGINS.md @@ -136,6 +136,8 @@ $this->app->make(Blocks::class)->add(BlockType::make('mein-plugin.liste', 'Meine - Dynamische Menüpunkte: `app(Navigation::class)->provider('mein-plugin', fn (Request $request, ?User $user) => [...])`; feste Menüpunkte können mit `visible: fn (User $user) => …` je Person ausgeblendet werden. - Benachrichtigungen (Glocke im Portal): `$user->notify(new App\Notifications\PortalNotification($titel, $text, $url))`. +- Wochenüberblick per E-Mail: `app(App\Digest\Digest::class)->add('mein-plugin', 'Überschrift', $sort, fn (User $user, CarbonImmutable $seit) => [['title' => …, 'url' => …, 'meta' => …, 'text' => …]])` + – Schlüssel = Plugin-Kürzel (Rollen-Ausschluss gilt), nur Sichtbares liefern, leere Liste = Abschnitt entfällt. - Barrierefreiheit: `` liest Text mit der Sprachausgabe des Geräts vor. Leichte Sprache als zweite Fassung eigener Inhalte: `app(App\Accessibility\EasyLanguage::class)->register('typ', fn (int $id, User $user) => ['can_view' => …, 'can_edit' => …, 'title' => …, 'text' => fn () => '…'])` (Kürzel nur aus Buchstaben), in der Ansicht `easy` aus diff --git a/phpunit.xml b/phpunit.xml index a05fc308..2ebfd70d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,8 @@ + + diff --git a/plugins-core/events/src/EventsPlugin.php b/plugins-core/events/src/EventsPlugin.php index 94110b92..61082f2f 100644 --- a/plugins-core/events/src/EventsPlugin.php +++ b/plugins-core/events/src/EventsPlugin.php @@ -3,6 +3,7 @@ namespace Inhaus\Plugins\Events; use App\Dashboard\Widgets; +use App\Digest\Digest; use App\Editorial\Editorial; use App\Media\ImagePaths; use App\Media\MediaUsages; @@ -23,6 +24,19 @@ class EventsPlugin extends Plugin { public function register(): void { + // Wochenüberblick: Termine der nächsten zwei Wochen + $this->app->make(Digest::class)->add('events', 'Termine', 20, fn (User $user) => Event::query() + ->upcoming()->visibleTo($user)->where('starts_at', '<=', now()->addDays(14))->limit(8)->get() + ->map(fn (Event $event) => [ + 'title' => $event->title, + 'url' => route('events.show', $event), + 'meta' => collect([ + $event->starts_at->timezone(config('app.timezone'))->translatedFormat($event->all_day ? 'D, d.m.' : 'D, d.m., H:i \\U\\h\\r'), + $event->location, + $event->registration_enabled ? 'mit Anmeldung' : null, + ])->filter()->implode(' · '), + ])->all()); + $this->app->make(GlobalSearch::class)->add('events', 'Termine', 'calendar-days', fn (...$args) => app(EventSearch::class)(...$args), sort: 20); $this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30); diff --git a/plugins-core/ideen/database/migrations/2026_10_20_000001_add_idea_moderation.php b/plugins-core/ideen/database/migrations/2026_10_20_000001_add_idea_moderation.php new file mode 100644 index 00000000..720a4bdd --- /dev/null +++ b/plugins-core/ideen/database/migrations/2026_10_20_000001_add_idea_moderation.php @@ -0,0 +1,43 @@ +timestamp('hidden_at')->nullable()->after('comments_count'); + }); + + Schema::table('idea_comments', function (Blueprint $table) { + $table->timestamp('hidden_at')->nullable()->after('official'); + }); + + Schema::create('idea_reports', function (Blueprint $table) { + $table->id(); + $table->foreignId('idea_id')->constrained('ideas')->cascadeOnDelete(); + $table->foreignId('comment_id')->nullable()->constrained('idea_comments')->cascadeOnDelete(); + $table->foreignId('user_id')->constrained()->cascadeOnDelete(); + $table->string('reason', 30); + $table->string('note', 500)->nullable(); + $table->timestamp('resolved_at')->nullable(); + $table->timestamps(); + + $table->unique(['user_id', 'idea_id', 'comment_id']); + $table->index(['resolved_at', 'idea_id']); + }); + } + + public function down(): void + { + Schema::dropIfExists('idea_reports'); + Schema::table('idea_comments', fn (Blueprint $table) => $table->dropColumn('hidden_at')); + Schema::table('ideas', fn (Blueprint $table) => $table->dropColumn('hidden_at')); + } +}; diff --git a/plugins-core/ideen/resources/js/components/ModerationNotice.vue b/plugins-core/ideen/resources/js/components/ModerationNotice.vue new file mode 100644 index 00000000..0179602e --- /dev/null +++ b/plugins-core/ideen/resources/js/components/ModerationNotice.vue @@ -0,0 +1,37 @@ + + + diff --git a/plugins-core/ideen/resources/js/components/ReportDialog.vue b/plugins-core/ideen/resources/js/components/ReportDialog.vue new file mode 100644 index 00000000..b63f2047 --- /dev/null +++ b/plugins-core/ideen/resources/js/components/ReportDialog.vue @@ -0,0 +1,63 @@ + + +