Rework the dashboard, environment topology view, header navigation, and status rendering, and standardise selects on a shadcn-vue component. Replace the thin database seeder with a SimulatedEnvironmentSeeder that builds a fully wired, mostly-running organisation (ACTIVE server fleet, managed + GHCR registries, Gitea source provider, ClipBin app with production/staging environments, services, slices, endpoints, managed variables, build artifacts, and a completed/in-progress/failed operations history) so the new UI renders against realistic data.
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Application;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Middleware;
|
|
use Tighten\Ziggy\Ziggy;
|
|
|
|
class HandleInertiaRequests extends Middleware
|
|
{
|
|
protected $rootView = 'app';
|
|
|
|
public function version(Request $request): ?string
|
|
{
|
|
return parent::version($request);
|
|
}
|
|
|
|
/**
|
|
* Define the props that are shared by default.
|
|
*
|
|
* @see https://inertiajs.com/shared-data
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function share(Request $request): array
|
|
{
|
|
return [
|
|
...parent::share($request),
|
|
'name' => config('app.name'),
|
|
'organisation' => $this->resolveOrganisation($request),
|
|
'application' => $request->route('application')
|
|
? Application::with('environments')->findOrFail($this->routeKey($request->route('application')))
|
|
: null,
|
|
'flash' => [
|
|
'server_credentials' => $request->session()->has('sudo_password') ? [
|
|
'sudo_password' => $request->session()->get('sudo_password'),
|
|
] : null,
|
|
],
|
|
'auth' => [
|
|
'user' => $request->user()?->load('organisations'),
|
|
],
|
|
'ziggy' => [
|
|
...(new Ziggy)->toArray(),
|
|
'location' => $request->url(),
|
|
],
|
|
];
|
|
}
|
|
|
|
private function resolveOrganisation(Request $request): ?Organisation
|
|
{
|
|
$query = Organisation::with('applications.environments')
|
|
->withCount(['providers', 'sourceProviders', 'registries', 'servers', 'applications']);
|
|
|
|
if ($request->route('organisation')) {
|
|
return $query->findOrFail($this->routeKey($request->route('organisation')));
|
|
}
|
|
|
|
$organisationId = $request->user()?->organisations()->value('organisations.id');
|
|
|
|
return $organisationId ? $query->find($organisationId) : null;
|
|
}
|
|
|
|
private function routeKey(mixed $routeValue): mixed
|
|
{
|
|
return $routeValue instanceof Model ? $routeValue->getKey() : $routeValue;
|
|
}
|
|
}
|