Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 15m6s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 15m58s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 15m42s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 15m21s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1h1m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1h2m13s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 23m20s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 23m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 1m17s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m57s
Feed-Registry mit Anbietern (Neu im Team, Neuigkeiten, Termine, Umfragen), Schnellaktionen je nach Rechten, Nachladen über /feed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
||
|
||
namespace App\Feed;
|
||
|
||
use App\Models\User;
|
||
use App\Plugins\Hooks;
|
||
use App\Plugins\PluginAccess;
|
||
use Illuminate\Support\Facades\Route;
|
||
|
||
/**
|
||
* Schnellaktionen über dem Feed – je nach Rechten: „Beitrag schreiben“ nur, wer Neuigkeiten
|
||
* verfassen darf; alle anderen z. B. „Problem melden“, „Formular finden“, „Idee einreichen“.
|
||
* Plugins ergänzen über Hooks::filter('feed.actions', fn (array $actions, User $user) => [...]).
|
||
*/
|
||
class FeedActions
|
||
{
|
||
/**
|
||
* @return list<array{label: string, url: string, icon: string}>
|
||
*/
|
||
public static function for(User $user): array
|
||
{
|
||
$access = app(PluginAccess::class);
|
||
$actions = [];
|
||
$add = function (string $plugin, string $route, string $label, string $icon) use (&$actions, $access, $user) {
|
||
if (Route::has($route) && $access->allows($plugin, $user)) {
|
||
$actions[] = ['label' => $label, 'url' => route($route), 'icon' => $icon];
|
||
}
|
||
};
|
||
|
||
if ($user->can('news.manage')) {
|
||
$add('news', 'news.editor.create', 'Beitrag schreiben', 'pen-line');
|
||
}
|
||
|
||
$add('it-service', 'it-service.tickets.create', 'Problem melden', 'circle-alert');
|
||
$add('forms', 'forms.index', 'Formular finden', 'file-text');
|
||
$add('ideen', 'ideas.index', 'Idee einreichen', 'lightbulb');
|
||
|
||
$actions = Hooks::apply('feed.actions', $actions, $user);
|
||
|
||
return array_values(array_filter((array) $actions, fn ($action) => is_array($action) && isset($action['label'], $action['url'])));
|
||
}
|
||
}
|