Feed in der Mitarbeiter-App (0.54.0)
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
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>
This commit is contained in:
parent
ab76b65aff
commit
8acc0cfd8b
152 changed files with 950 additions and 361 deletions
35
app/Feed/CoreFeed.php
Normal file
35
app/Feed/CoreFeed.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Feed;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Einträge des Kerns im Feed: neue Kolleginnen und Kollegen.
|
||||
*/
|
||||
class CoreFeed
|
||||
{
|
||||
public static function register(Feed $feed): void
|
||||
{
|
||||
$feed->add('people', fn (User $user, ?CarbonImmutable $before, int $limit) => User::query()
|
||||
->active()
|
||||
->whereKeyNot($user->getKey())
|
||||
->where('created_at', '>=', now()->subDays(120))
|
||||
->when($before, fn ($query) => $query->where('created_at', '<', $before))
|
||||
->latest()
|
||||
->limit($limit)
|
||||
->get()
|
||||
->map(fn (User $person) => [
|
||||
'id' => 'person-'.$person->id,
|
||||
'kind' => 'welcome',
|
||||
'time' => $person->created_at,
|
||||
'actor' => Feed::person($person),
|
||||
'badge' => 'Neu im Team',
|
||||
'title' => $person->name.' ist neu im Team',
|
||||
'text' => implode(' · ', array_filter([$person->job_title, $person->department, $person->location])),
|
||||
'url' => route('people.show', $person),
|
||||
'cta' => ['label' => 'Profil ansehen', 'url' => route('people.show', $person)],
|
||||
]));
|
||||
}
|
||||
}
|
||||
130
app/Feed/Feed.php
Normal file
130
app/Feed/Feed.php
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace App\Feed;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\PluginAccess;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Der Feed der Mitarbeiter-App: was im Haus passiert, als Beiträge in zeitlicher Folge.
|
||||
* Kern und Plugins steuern Einträge bei:
|
||||
*
|
||||
* app(Feed::class)->add('news', function (User $user, ?CarbonImmutable $before, int $limit) {
|
||||
* return NewsPost::query()->published()->visibleTo($user)
|
||||
* ->when($before, fn ($q) => $q->where('published_at', '<', $before))
|
||||
* ->latest('published_at')->limit($limit)->get()
|
||||
* ->map(fn ($post) => [
|
||||
* 'id' => 'news-'.$post->id, 'time' => $post->published_at,
|
||||
* 'actor' => Feed::person($post->author), 'action' => 'hat eine Neuigkeit veröffentlicht',
|
||||
* 'badge' => $post->category?->name, 'title' => $post->title, 'text' => $post->teaser,
|
||||
* 'image_url' => …, 'url' => …, 'stats' => ['likes' => 3, 'comments' => 1],
|
||||
* ]);
|
||||
* });
|
||||
*
|
||||
* Jeder Anbieter liefert höchstens $limit Einträge, die älter als $before sind (neueste zuerst);
|
||||
* der Feed mischt sie nach Zeit. Nur, was die Person sehen darf. Gesperrte Plugins liefern nichts.
|
||||
*/
|
||||
class Feed
|
||||
{
|
||||
/** @var array<string, Closure> */
|
||||
private array $providers = [];
|
||||
|
||||
public function add(string $key, Closure $items): void
|
||||
{
|
||||
$this->providers[$key] = $items;
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
{
|
||||
unset($this->providers[$key]);
|
||||
}
|
||||
|
||||
public function has(): bool
|
||||
{
|
||||
return $this->providers !== [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: list<array<string, mixed>>, next: string|null}
|
||||
*/
|
||||
public function page(User $user, ?CarbonImmutable $before = null, int $limit = 10): array
|
||||
{
|
||||
$access = app(PluginAccess::class);
|
||||
$items = [];
|
||||
|
||||
foreach ($this->providers as $key => $provider) {
|
||||
if ($key !== 'people' && ! $access->allows($key, $user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($provider($user, $before, $limit) as $item) {
|
||||
$normalized = $this->normalize($key, $item);
|
||||
|
||||
if ($normalized && (! $before || CarbonImmutable::parse($normalized['time'])->lt($before))) {
|
||||
$items[] = $normalized;
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
Log::error("Feed {$key}: ".$e->getMessage(), ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
usort($items, fn (array $a, array $b) => strcmp($b['time'], $a['time']));
|
||||
$page = array_slice($items, 0, $limit);
|
||||
|
||||
return [
|
||||
'items' => $page,
|
||||
'next' => count($items) > $limit ? end($page)['time'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Person für die Kopfzeile eines Beitrags.
|
||||
*
|
||||
* @return array{id: int, name: string, initials: string, avatar_url: string|null, subtitle: string}|null
|
||||
*/
|
||||
public static function person(?User $user): ?array
|
||||
{
|
||||
return $user ? [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'initials' => $user->initials,
|
||||
'avatar_url' => $user->avatarUrl(96),
|
||||
'subtitle' => implode(' · ', array_filter([$user->job_title, $user->department])),
|
||||
] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|mixed $item
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function normalize(string $key, mixed $item): ?array
|
||||
{
|
||||
if (! is_array($item) || blank($item['id'] ?? null) || blank($item['time'] ?? null) || blank($item['url'] ?? null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'key' => $key,
|
||||
'id' => (string) $item['id'],
|
||||
'kind' => (string) ($item['kind'] ?? $key),
|
||||
'time' => CarbonImmutable::parse($item['time'])->toIso8601String(),
|
||||
'actor' => is_array($item['actor'] ?? null) ? $item['actor'] : null,
|
||||
'action' => (string) ($item['action'] ?? ''),
|
||||
'context' => is_array($item['context'] ?? null) && filled($item['context']['label'] ?? null) ? $item['context'] : null,
|
||||
'badge' => filled($item['badge'] ?? null) ? (string) $item['badge'] : null,
|
||||
'title' => (string) ($item['title'] ?? ''),
|
||||
'text' => (string) ($item['text'] ?? ''),
|
||||
'image_url' => filled($item['image_url'] ?? null) ? (string) $item['image_url'] : null,
|
||||
'images' => array_values(array_filter((array) ($item['images'] ?? []), 'is_string')),
|
||||
'url' => (string) $item['url'],
|
||||
'stats' => is_array($item['stats'] ?? null) ? $item['stats'] : null,
|
||||
'cta' => is_array($item['cta'] ?? null) && filled($item['cta']['label'] ?? null) ? $item['cta'] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Feed/FeedActions.php
Normal file
42
app/Feed/FeedActions.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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'])));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Dashboard\Homepage;
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Feed\Feed;
|
||||
use App\Feed\FeedActions;
|
||||
use App\Support\Branding;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
|
@ -11,7 +13,7 @@ use Inertia\Response;
|
|||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, Widgets $widgets, Homepage $homepage, Branding $branding): Response
|
||||
public function __invoke(Request $request, Widgets $widgets, Homepage $homepage, Branding $branding, Feed $feed): Response
|
||||
{
|
||||
// Vorschau des Entwurfs für alle, die die Startseite gestalten
|
||||
$preview = $request->boolean('entwurf') && $request->user()->can('appearance.manage');
|
||||
|
|
@ -25,8 +27,13 @@ class DashboardController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
$isApp = $branding->interface() === 'app';
|
||||
|
||||
return Inertia::render('Dashboard', [
|
||||
'widgets' => $widgets->resolve($request->user(), $request),
|
||||
// Mitarbeiter-App: Feed in der Mitte, darüber Schnellaktionen je nach Rechten
|
||||
'feed' => $isApp ? fn () => $feed->page($request->user()) : null,
|
||||
'feedActions' => $isApp ? fn () => FeedActions::for($request->user()) : [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
app/Http/Controllers/FeedController.php
Normal file
24
app/Http/Controllers/FeedController.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Feed\Feed;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
|
||||
class FeedController extends Controller
|
||||
{
|
||||
/** Weitere Einträge für „Mehr laden“: /feed?vor=<Zeitpunkt> */
|
||||
public function __invoke(Request $request, Feed $feed): JsonResponse
|
||||
{
|
||||
try {
|
||||
$before = $request->filled('vor') ? CarbonImmutable::parse((string) $request->query('vor')) : null;
|
||||
} catch (Throwable) {
|
||||
$before = null;
|
||||
}
|
||||
|
||||
return response()->json($feed->page($request->user(), $before));
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ 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;
|
||||
|
|
@ -76,6 +78,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Avatars::class);
|
||||
$this->app->singleton(QuickLinks::class);
|
||||
$this->app->singleton(Tasks::class);
|
||||
$this->app->singleton(Feed::class);
|
||||
$this->app->singleton(PluginAccess::class);
|
||||
$this->app->singleton(GlobalSearch::class);
|
||||
$this->app->singleton(LicenseStore::class);
|
||||
|
|
@ -105,6 +108,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
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')
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.53.0';
|
||||
public const VERSION = '0.54.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue