Rollen, Rechte und Zielgruppen
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s
- Rollen mit globalen Rechten und Rechten für einzelne Objekte (z. B. „Beiträge schreiben in Kategorie MAV-Info“); Rollen sind additiv, Zuweisungen merken sich ihre Herkunft (manuell oder später Identity-Provider-Gruppe) - Systemrolle „Administration“ ersetzt users.is_admin (Migration übernimmt bestehende Administratoren); nicht löschbar, man kann sie sich nicht selbst entziehen - Rechte je Person vorberechnet und gecacht, Versionszähler invalidiert bei Änderungen - Gate-Anbindung: registrierte Rechte entscheidet das Rechtesystem, Objektregeln die Policies; Admin-Seiten und Plugin-Ressourcen hinter passenden Rechten - Redaktion nach Kategorie: Schreiben und Veröffentlichen getrennt, Liste im Admin auf eigene Kategorien beschränkt, ohne Veröffentlichungsrecht bleibt ein Beitrag Entwurf - Zielgruppen (Rolle/Abteilung/Standort) für Kategorien und Termine als indizierte SQL-Bedingung in Listen, Detailseiten, Kacheln und .ics-Export - Admin: Rollen-Verwaltung, „Rechte prüfen“, Redaktion und Sichtbarkeit direkt an Kategorie bzw. Termin - Kern-Ressourcen explizit registriert, damit nach Updates liegengebliebene alte Dateien nicht doppelt geladen werden - docs/PLUGINS.md für Plugin-Entwicklung; Demo-Rolle „MAV“ Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
28ef1e4a20
commit
9ddc35a62c
112 changed files with 2408 additions and 267 deletions
|
|
@ -7,8 +7,10 @@ use App\Models\User;
|
|||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Inhaus\Plugins\Events\Http\Resources\EventResource;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
use Inhaus\Plugins\Events\Policies\EventPolicy;
|
||||
|
||||
class EventsPlugin extends Plugin
|
||||
{
|
||||
|
|
@ -16,6 +18,7 @@ class EventsPlugin extends Plugin
|
|||
{
|
||||
$this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30);
|
||||
$this->app->make(Abilities::class)->define('events.manage', 'Termine verwalten', 'Termine');
|
||||
Gate::policy(Event::class, EventPolicy::class);
|
||||
|
||||
$this->app->make(Widgets::class)->add('events.upcoming', 'events::Upcoming', 'aside', sort: 20, props: fn (User $user) => [
|
||||
'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit(4)->get())->resolve(),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Inhaus\Plugins\Events\Filament\Resources\Events;
|
||||
|
||||
use App\Filament\Components\AudienceSection;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
|
|
@ -83,6 +84,7 @@ class EventResource extends Resource
|
|||
Section::make('Anzeige')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
AudienceSection::make('event', 'Wer den Termin sieht. Leer lassen = alle.'),
|
||||
Toggle::make('is_published')->label('Veröffentlicht')->default(true),
|
||||
FileUpload::make('image_path')
|
||||
->label('Bild')
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ class EventController extends Controller
|
|||
{
|
||||
return Inertia::render('events::Index', [
|
||||
'events' => EventResource::collection(
|
||||
Event::query()->upcoming()->limit(200)->get()
|
||||
Event::query()->upcoming()->visibleTo(request()->user())->limit(200)->get()
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Event $event): Response
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
abort_unless($event->is_published && $event->isVisibleTo(request()->user()), 404);
|
||||
|
||||
return Inertia::render('events::Show', [
|
||||
'event' => [
|
||||
|
|
@ -36,7 +36,7 @@ class EventController extends Controller
|
|||
|
||||
public function ics(Event $event, Calendar $calendar, Branding $branding): HttpResponse
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
abort_unless($event->is_published && $event->isVisibleTo(request()->user()), 404);
|
||||
|
||||
return response($calendar->toIcs($event, $branding->portalName()), 200, [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Inhaus\Plugins\Events\Models;
|
|||
|
||||
use App\Models\User;
|
||||
use App\Support\Images;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
|
@ -91,9 +92,21 @@ class Event extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Nur Einträge, die diese Person sehen darf (Zielgruppen). Platzhalter bis Phase 2c.
|
||||
* Nur Termine, die diese Person sehen darf (Zielgruppe des Termins).
|
||||
*
|
||||
* @param Builder<Event> $query
|
||||
*/
|
||||
public function scopeVisibleTo(Builder $query, ?User $user): void {}
|
||||
public function scopeVisibleTo(Builder $query, ?User $user): void
|
||||
{
|
||||
if ($user?->can('events.manage')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Audiences::constrain($query, 'event', 'events.id', $user);
|
||||
}
|
||||
|
||||
public function isVisibleTo(?User $user): bool
|
||||
{
|
||||
return (bool) $user?->can('events.manage') || Audiences::allows('event', $this->id, $user);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
plugins-core/events/src/Policies/EventPolicy.php
Normal file
29
plugins-core/events/src/Policies/EventPolicy.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
class EventPolicy
|
||||
{
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('events.manage');
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('events.manage');
|
||||
}
|
||||
|
||||
public function update(User $user, Event $event): bool
|
||||
{
|
||||
return $user->can('events.manage');
|
||||
}
|
||||
|
||||
public function delete(User $user, Event $event): bool
|
||||
{
|
||||
return $user->can('events.manage');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue