Loheide-eu-mitarbeiterplatt.../app/Providers/AppServiceProvider.php
Friederich Loheide 3addc09c38
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 8m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m8s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 17m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 9m50s
Frag das Portal durchsucht alles, neue Demo-Inhalte (0.66.0)
- Wissensquellen: Termine, Downloads, Formulare, Stellen, Ideen, Umfragen,
  Personen, eigene IT-Tickets/Geräte (OpenNIT, je Anfrage zwischengespeichert)
- Ranking mit IDF, Abfrage je Begriff, Abkürzungen als ganze Wörter,
  LIKE unabhängig von Groß-/Kleinschreibung (JSON-Spalten), Datum im Prompt
- Demo-Inhalte für einen Träger der Eingliederungshilfe (DemoData),
  mehrseitige PDFs, vorhandene Inhalte je Bereich entfernen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 20:01:00 +00:00

194 lines
8.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Providers;
use App\Accessibility\EasyLanguage;
use App\Ask\Knowledge;
use App\Ask\PeopleKnowledge;
use App\Dashboard\CoreWidgets;
use App\Dashboard\Homepage;
use App\Dashboard\Widgets;
use App\Digest\Digest;
use App\Editorial\Editorial;
use App\Feed\CoreFeed;
use App\Feed\Feed;
use App\Identity\Entra\EntraDriver;
use App\Identity\IdentityDrivers;
use App\Layout\HeaderItems;
use App\Media\EditorialMedia;
use App\Media\ImagePaths;
use App\Media\MediaLibrary;
use App\Media\MediaUsages;
use App\Models\DashboardTile;
use App\Models\IdentityProvider;
use App\Models\User;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\BlockType;
use App\Pagebuilder\Field;
use App\Plugins\PluginAccess;
use App\Search\GlobalSearch;
use App\Support\Abilities;
use App\Support\Avatars;
use App\Support\BackgroundTasks;
use App\Support\Branding;
use App\Support\Hubs;
use App\Support\Installation;
use App\Support\License\LicenseStore;
use App\Support\MailSettings;
use App\Support\Navigation;
use App\Support\Permissions\PermissionResource;
use App\Support\Permissions\Permissions;
use App\Support\ProfileFields;
use App\Support\QuickLinks;
use App\Support\Settings;
use App\Support\Theme\Theme;
use App\Support\Theme\ThemeCompiler;
use App\Support\Update\InstalledVersion;
use App\Support\Update\MaintenanceFlag;
use App\Support\Update\UpdateProgress;
use App\Tasks\Tasks;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rules\Password;
use Laravel\Sanctum\Sanctum;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
// Frisch hochgeladen: .env und Schlüssel anlegen; bis zur Einrichtung ohne Datenbank
// für Sitzungen, Cache und Queue auskommen (der Web-Installer braucht das).
if (! $this->app->runningUnitTests()) {
Installation::prepareEnvironment();
}
if (! Installation::isInstalled()) {
config(['session.driver' => 'file', 'cache.default' => 'file', 'queue.default' => 'sync']);
}
$this->app->singleton(Settings::class);
$this->app->singleton(EasyLanguage::class);
$this->app->singleton(Digest::class);
$this->app->singleton(HeaderItems::class);
$this->app->singleton(MailSettings::class);
$this->app->singleton(Branding::class);
$this->app->singleton(Theme::class);
$this->app->singleton(ThemeCompiler::class);
$this->app->singleton(Avatars::class);
$this->app->singleton(QuickLinks::class);
$this->app->singleton(Tasks::class);
$this->app->singleton(Feed::class);
$this->app->singleton(Hubs::class);
$this->app->singleton(PluginAccess::class);
$this->app->singleton(GlobalSearch::class);
$this->app->singleton(Knowledge::class);
$this->app->singleton(LicenseStore::class);
$this->app->singleton(Permissions::class);
$this->app->singleton(ProfileFields::class);
$this->app->singleton(Blocks::class);
$this->app->singleton(IdentityDrivers::class, function ($app) {
$drivers = new IdentityDrivers($app);
$drivers->add(IdentityProvider::ENTRA, EntraDriver::class);
return $drivers;
});
$this->app->singleton(Editorial::class);
$this->app->singleton(MediaUsages::class);
$this->app->singleton(MediaLibrary::class);
$this->app->singleton(BackgroundTasks::class);
$this->app->singleton(InstalledVersion::class);
$this->app->singleton(UpdateProgress::class);
$this->app->singleton(MaintenanceFlag::class);
}
public function boot(): void
{
// „Frag das Portal“: Personenverzeichnis als Wissensquelle (Fachbereiche melden ihre selbst an)
$this->app->make(Knowledge::class)->add('people', 'Personen', fn (...$args) => app(PeopleKnowledge::class)(...$args));
RateLimiter::for('api', fn (Request $request) => Limit::perMinute(180)->by($request->user()?->id ?: $request->ip()));
// API-Tokens deaktivierter Konten gelten nicht mehr
Sanctum::authenticateAccessTokensUsing(fn ($token, bool $isValid) => $isValid && $token->tokenable instanceof User && $token->tokenable->is_active);
CoreWidgets::register($this->app->make(Widgets::class));
CoreFeed::register($this->app->make(Feed::class));
// Frei gestaltete Startseite: jede Kachel als Block
$this->app->make(Blocks::class)->add(BlockType::make(Homepage::WIDGET_BLOCK, 'Kachel', 'layout-dashboard', 'homepage', 'WidgetBlock')
->description('Eine Kachel der Startseite – Begrüßung, Termine, Geburtstage, eigene Kacheln …')
->fields([Field::select('widget', 'Kachel', fn () => $this->app->make(Widgets::class)->options())])
->resolveUsing(fn (array $data, ?User $user) => $user && $data['widget']
? $this->app->make(Widgets::class)->resolveOne($data['widget'], $user, request())
: null));
$this->app->make(Navigation::class)->add('editorial', 'Redaktion', '/redaktion', active: ['editorial', 'pages.editor', 'news.editor.*', 'forms.builder', 'media.*'], sort: 85, icon: 'pen-line',
visible: fn (User $user) => $this->app->make(Editorial::class)->visibleFor($user));
$this->registerMedia();
// N+1-Abfragen in Entwicklung und Tests sofort sichtbar machen (docs/PLAN.md, Performance).
Model::preventLazyLoading(! $this->app->isProduction());
// Rechte aus Rollen (App\Support\Abilities) entscheidet das Rechtesystem – Administration
// hat sie alle. Alles andere (z. B. „delete“ auf einem Modell) entscheiden die Policies,
// damit Regeln wie „Systemrollen nie löschen“ auch für Administratoren gelten.
Gate::before(function (User $user, string $ability, array $arguments) {
if (! $user->is_active) {
return false;
}
if (! $this->app->make(Abilities::class)->exists($ability)) {
return null;
}
[$type, $id] = PermissionResource::from($arguments);
return $user->permissions()->can($ability, $type, $id);
});
Password::defaults(fn () => Password::min(10)->letters()->numbers());
if (Installation::isInstalled()) {
$this->app->make(MailSettings::class)->apply();
// Whitelabel: Laravel nutzt app.name z. B. in Benachrichtigungs-Mails („Viele Grüße …“).
try {
config(['app.name' => $this->app->make(Branding::class)->portalName()]);
} catch (\Throwable) {
// Datenbank noch nicht bereit
}
}
}
/**
* Mediathek: Zugang für alle, die in der Redaktion arbeiten, Abschnitt in der
* Redaktion und die Startseiten-Kacheln als Quelle für „Eingebunden in“.
*/
private function registerMedia(): void
{
$editorial = $this->app->make(Editorial::class);
// Bildauswahl und Hochladen: wer irgendwo in der Redaktion arbeitet (Seiten, Beiträge …) oder die Mediathek verwaltet.
Gate::define('media.use', fn (User $user) => $user->can('media.manage') || $editorial->visibleFor($user, except: 'media'));
// Abschnitt nur neben anderen Redaktionsbereichen – sonst erschiene „Redaktion“ ohne Inhalte.
$editorial->add('media', 'Mediathek', 'core::EditorialMedia', 90,
fn (User $user) => $editorial->visibleFor($user, except: 'media'),
fn (User $user) => EditorialMedia::props($user));
$editorial->meta('media', icon: 'images');
$usages = $this->app->make(MediaUsages::class);
$usages->add('dashboard_tiles', 'Startseiten-Kacheln',
fn (DashboardTile $tile) => [
['context' => 'Kachelbild', 'label' => $tile->name ?: (string) $tile->title, 'url' => '/admin/startseite-menue/kacheln', 'draft' => $tile->is_active === false, 'paths' => [$tile->image_path]],
['context' => ImagePaths::HTML_CONTEXT, 'label' => $tile->name ?: (string) $tile->title, 'url' => '/admin/startseite-menue/kacheln', 'draft' => $tile->is_active === false, 'paths' => ImagePaths::fromHtml($tile->body_html)],
],
fn (callable $each) => DashboardTile::query()->chunkById(100, fn ($tiles) => $tiles->each($each)));
$usages->watch('dashboard_tiles', DashboardTile::class, ['image_path', 'body_html', 'name', 'title', 'is_active']);
}
}