Ideenbox-Moderation und Wochenüberblick per E-Mail (0.36.0)
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
11c5ef5baf
commit
f9922f7308
172 changed files with 1524 additions and 363 deletions
120
app/Digest/Digest.php
Normal file
120
app/Digest/Digest.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Digest;
|
||||
|
||||
use App\Mail\WeeklyDigest;
|
||||
use App\Models\User;
|
||||
use App\Plugins\PluginAccess;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Wochenüberblick per E-Mail. Plugins steuern Abschnitte bei:
|
||||
*
|
||||
* app(Digest::class)->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<string, array{label: string, sort: int, items: callable}> */
|
||||
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<array{key: string, label: string, items: list<array<string, mixed>>}>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
98
app/Filament/Pages/DigestSettings.php
Normal file
98
app/Filament/Pages/DigestSettings.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Digest\Digest;
|
||||
use App\Models\User;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Settings;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Wochenüberblick per E-Mail: Versandtag und -uhrzeit. Bekommen nur Personen, die ihn
|
||||
* im Profil einschalten.
|
||||
*/
|
||||
class DigestSettings extends Page
|
||||
{
|
||||
protected string $view = 'filament.pages.settings-form';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedNewspaper;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 30;
|
||||
|
||||
protected static ?string $navigationLabel = 'Wochenüberblick';
|
||||
|
||||
protected static ?string $title = 'Wochenüberblick per E-Mail';
|
||||
|
||||
protected static ?string $slug = 'wochenueberblick';
|
||||
|
||||
/** @var array<string, mixed>|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();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/DigestController.php
Normal file
38
app/Http/Controllers/DigestController.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response as HttpResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
/**
|
||||
* Wochenüberblick ein- und ausschalten – im Profil oder per Link aus der E-Mail.
|
||||
*/
|
||||
class DigestController extends Controller
|
||||
{
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
60
app/Mail/WeeklyDigest.php
Normal file
60
app/Mail/WeeklyDigest.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Branding;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Mail\Mailables\Headers;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
/**
|
||||
* Wochenüberblick: Neuigkeiten, Termine, Umfragen … der letzten sieben Tage.
|
||||
*/
|
||||
class WeeklyDigest extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @param list<array{key: string, label: string, items: list<array<string, mixed>>}> $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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.35.0';
|
||||
public const VERSION = '0.36.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue