Optimierung Phase 1: Aufraeumen / toter Code

1.1 Prototyp admin/users/table entfernt: Route (war durch admin/users/{id}
    ohnehin unerreichbar) + Volt-Komponente table.blade.php geloescht,
    ADMIN_ROUTES.md aktualisiert; Regressions-Test in PanelConsolidationTest.
1.2 16 tote Legacy-Wrapper-Views unter resources/views/admin/* geloescht
    (nutzten alte Route-Parameter, nirgends via view/@include/@livewire
    gerendert); admin.dashboard + .md-Doku behalten.
1.3 Tote Helfer entfernt: EnsureUserIsAdmin redundantes loadMissing('roles'),
    ungenutzter statusColor-Key aus with() in admin PR edit/show,
    LegacyInvoicePdfController Laufzeit-Schema::hasColumn (Spalte existiert
    seit Migration) inkl. Schema-Import.

Volle Suite gruen (794 passed, 1 skipped).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 08:27:12 +00:00
parent a82964df2b
commit a5f3ddd0f3
25 changed files with 9 additions and 329 deletions

View file

@ -5,7 +5,6 @@ namespace App\Http\Controllers;
use App\Models\LegacyInvoice;
use App\Services\Billing\LegacyInvoicePdfRenderer;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\Response;
@ -23,9 +22,7 @@ class LegacyInvoicePdfController extends Controller
]);
}
if (Schema::hasColumn('legacy_invoices', 'pdf_generated_at')) {
$legacyInvoice->forceFill(['pdf_generated_at' => now()])->save();
}
$legacyInvoice->forceFill(['pdf_generated_at' => now()])->save();
return $renderer->inlineResponse($legacyInvoice);
}

View file

@ -13,10 +13,6 @@ class EnsureUserIsAdmin
{
$user = $request->user();
if ($user !== null && $user->is_active && ! $user->is_super_admin) {
$user->loadMissing('roles');
}
if (app(UserImpersonation::class)->isActive()) {
if ($request->isMethod('GET') || $request->isMethod('HEAD')) {
return redirect()->route('me.dashboard');

View file

@ -30,9 +30,9 @@ Latente Fehlerquellen und Sicherheitslücken. Klein, aber wichtig.
Keine Fachlogik-Änderung. Reduziert erreichbare Demo-Komponenten und Altlasten.
- [ ] **1.1 Prototyp `admin/users/table` entfernen** — Route in `routes/admin.php` + `resources/views/livewire/admin/users/table.blade.php`. Filtert auf nicht existentes `users.status`, liest `$user->role` (statt Spatie), englische Demo-Menüs → kann SQL-Fehler/falsche UI erzeugen. Test für entfernte Route anpassen/ergänzen.
- [ ] **1.2 Tote Admin-Wrapper-Views prüfen & entfernen** — `resources/views/admin/*` werden außer `admin.dashboard` (via `DashboardController`) nicht produktiv gerendert. Wrapper mit alten Parametern (`request()->route('pressRelease')` vs. aktuelle `{id}`-Route) entfernen oder klar als Legacy markieren. `admin.dashboard` behalten.
- [ ] **1.3 Tote Helfer entfernen** — `EnsureUserIsAdmin:16-18` totes `loadMissing('roles')`; `statusColor` aus `with()` (admin/edit:558-564, admin/show:111-117) prüfen/entfernen; `LegacyInvoicePdfController:26` Laufzeit-`Schema::hasColumn` nach Migration entfernen.
- [x] **1.1 Prototyp `admin/users/table` entfernt** — Route aus `routes/admin.php` (war ohnehin durch `admin/users/{id}` unerreichbar) + `resources/views/livewire/admin/users/table.blade.php` gelöscht; Eintrag aus `routes/ADMIN_ROUTES.md` entfernt. Regressions-Test in `PanelConsolidationTest` (`Route::has('admin.users.table')` ist false).
- [x] **1.2 Tote Admin-Wrapper-Views entfernt** — verifiziert: kein `view()`/`@include`/`@extends`/`@livewire` rendert `resources/views/admin/*` außer `admin.dashboard` (via `DashboardController`); Wrapper nutzten alte Route-Parameter (`request()->route('company')`). 16 tote Wrapper-Blades gelöscht; `dashboard.blade.php` + die `.md`-Doku behalten.
- [x] **1.3 Tote Helfer entfernt** — `EnsureUserIsAdmin` redundantes `loadMissing('roles')` (Spatie `hasAnyRole()` lädt ohnehin); `statusColor`-Key aus `with()` in admin `edit`/`show` (Blade nutzt nur lokales `$statusClass`); `LegacyInvoicePdfController` Laufzeit-`Schema::hasColumn` (Spalte existiert seit Migration 2026_05_04) + unbenutzter `Schema`-Import.
---

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Kategorien') }}</flux:heading>
@livewire('admin.categories.index')
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.companies.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Neue Firma') }}</flux:heading>
@livewire('admin.companies.create')
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.companies.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Firma bearbeiten') }}</flux:heading>
@livewire('admin.companies.edit', ['companyId' => request()->route('company')])
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Firmen') }}</flux:heading>
@livewire('admin.companies.index')
</flux:main>
</x-layouts.app>

View file

@ -1,11 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.companies.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
@livewire('admin.companies.show', ['companyId' => request()->route('company')])
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Kontakte') }}</flux:heading>
@livewire('admin.contacts.index')
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Gutscheine') }}</flux:heading>
@livewire('admin.coupons.index')
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Rechnungen') }}</flux:heading>
@livewire('admin.invoices.index')
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Zahlungen') }}</flux:heading>
@livewire('admin.payments.index')
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.press-releases.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Neue Pressemitteilung') }}</flux:heading>
@livewire('admin.press-releases.create')
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.press-releases.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Pressemitteilung bearbeiten') }}</flux:heading>
@livewire('admin.press-releases.edit', ['pressReleaseId' => request()->route('pressRelease')])
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Pressemitteilungen') }}</flux:heading>
@livewire('admin.press-releases.index')
</flux:main>
</x-layouts.app>

View file

@ -1,11 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.press-releases.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
@livewire('admin.press-releases.show', ['pressReleaseId' => request()->route('pressRelease')])
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.roles.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Neue Rolle erstellen') }}</flux:heading>
@livewire('admin.roles.create')
</flux:main>
</x-layouts.app>

View file

@ -1,13 +0,0 @@
<x-layouts.app>
<flux:main>
<div class="mb-6">
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.roles.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</div>
<flux:heading size="xl" class="mb-6">{{ __('Rolle bearbeiten') }}</flux:heading>
@livewire('admin.roles.edit', ['roleId' => request()->route('role')])
</flux:main>
</x-layouts.app>

View file

@ -1,7 +0,0 @@
<x-layouts.app>
<flux:main>
<flux:heading size="xl" class="mb-6">{{ __('Rollen & Rechte') }}</flux:heading>
@livewire('admin.roles.index')
</flux:main>
</x-layouts.app>

View file

@ -555,13 +555,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
'selectedCompany' => $selectedCompany,
'selectedCompanyContacts' => $selectedCompany ? $this->companyContacts((int) $selectedCompany->id) : Contact::query()->whereRaw('0 = 1')->get(),
'tagSuggestions' => $this->tagSuggestionsFor($selectedCompany),
'statusColor' => match ($this->currentStatus) {
'published' => 'green',
'review' => 'yellow',
'rejected' => 'red',
'archived' => 'blue',
default => 'zinc',
},
];
}

View file

@ -108,13 +108,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends
'categoryName' => $pr->category?->translations->firstWhere('locale', 'de')?->name
?? $pr->category?->translations->first()?->name
?? '–',
'statusColor' => match ($pr->status->value) {
'published' => 'green',
'review' => 'yellow',
'rejected' => 'red',
'archived' => 'blue',
default => 'zinc',
},
];
}
}; ?>

View file

@ -1,146 +0,0 @@
<?php
use App\Models\User;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Volt\Component;
use Livewire\WithPagination; // Wichtig für Paginierung
new #[Layout('components.layouts.app'), Title('Benutzertabelle')] class extends Component {
use WithPagination;
// Optional: Such- und Filter-Properties
public string $search = '';
public string $statusFilter = '';
public string $roleFilter = '';
// Optional: Sortierung
public $sortBy = 'name';
public $sortDirection = 'asc';
/**
* Mount the component.
*/
public function mount(): void
{
// Standardwerte für Sortierung setzen
$this->sortBy = 'name';
$this->sortDirection = 'asc';
}
public function sort($column) {
if ($this->sortBy === $column) {
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
} else {
$this->sortBy = $column;
$this->sortDirection = 'asc';
}
}
/*public function orders()
{
return \App\Models\Order::query()
->tap(fn ($query) => $this->sortBy ? $query->orderBy($this->sortBy, $this->sortDirection) : $query)
->paginate(5);
}*/
// Die Hauptmethode, um Daten zu laden
#[\Livewire\Attributes\Computed]
public function users()
{
return User::query()
->when($this->search, fn($query, $search) =>
$query->where('name', 'like', '%' . $search . '%')
->orWhere('email', 'like', '%' . $search . '%')
)
->when($this->statusFilter, fn($query, $status) =>
$query->where('status', $status)
)
->when($this->roleFilter, fn($query, $role) =>
$query->where('role', $role) // oder 'role_id' wenn du IDs verwendest
)
->orderBy($this->sortBy, $this->sortDirection)
->paginate(10); // 10 Einträge pro Seite
}
// Optional: Lifecycle hook für das Zurücksetzen der Paginierung bei Suche/Filterung
public function updatedSearch() { $this->resetPage(); }
public function updatedStatusFilter() { $this->resetPage(); }
public function updatedRoleFilter() { $this->resetPage(); }
// Wird für die Paginierung mit Tailwind benötigt (Standard in Livewire 3)
// Wenn FluxUI Bootstrap-basierte Paginierung braucht, musst du das anpassen
// public function paginationView()
// {
// return 'vendor.livewire.tailwind'; // oder 'livewire::bootstrap'
// }
// Wenn du mit Relationen arbeitest (z.B. user->role->name)
// public function with(): array
// {
// return [
// 'users' => User::with(['role', 'group']) // Eager loading
// // ... deine Query-Logik von oben ...
// ->paginate(10),
// ];
// }
}; ?>
<flux:table :paginate="$this->users">
<flux:table.columns>
<flux:table.column>Customer</flux:table.column>
<flux:table.column sortable :sorted="$sortBy === 'date'" :direction="$sortDirection" wire:click="sort('date')">Date</flux:table.column>
<flux:table.column sortable :sorted="$sortBy === 'status'" :direction="$sortDirection" wire:click="sort('status')">Status</flux:table.column>
<flux:table.column sortable :sorted="$sortBy === 'amount'" :direction="$sortDirection" wire:click="sort('amount')">Amount</flux:table.column>
</flux:table.columns>
<flux:table.rows>
@foreach ($this->users as $user)
<flux:table.row :key="$user->id">
<flux:table.cell class="flex items-center gap-3">
<flux:avatar size="xs" src="{{ $user->avatar }}" />
{{ $user->name }}
</flux:table.cell>
<flux:table.cell class="whitespace-nowrap">{{ $user->email }}</flux:table.cell>
<flux:table.cell>
<flux:badge size="sm" color="lime" inset="top bottom">RTest</flux:badge>
</flux:table.cell>
<flux:table.cell variant="strong">{{ $user->role }}</flux:table.cell>
<flux:table.cell>
<flux:dropdown>
<flux:button variant="filled" size="sm" icon="ellipsis-horizontal" inset="top bottom"></flux:button>
<flux:menu>
<flux:menu.item icon="plus">New post</flux:menu.item>
<flux:menu.separator />
<flux:menu.submenu heading="Sort by">
<flux:menu.radio.group>
<flux:menu.radio checked>Name</flux:menu.radio>
<flux:menu.radio>Date</flux:menu.radio>
<flux:menu.radio>Popularity</flux:menu.radio>
</flux:menu.radio.group>
</flux:menu.submenu>
<flux:menu.submenu heading="Filter">
<flux:menu.checkbox checked>Draft</flux:menu.checkbox>
<flux:menu.checkbox checked>Published</flux:menu.checkbox>
<flux:menu.checkbox>Archived</flux:menu.checkbox>
</flux:menu.submenu>
<flux:menu.separator />
<flux:menu.item variant="danger" icon="trash">Delete</flux:menu.item>
</flux:menu>
</flux:dropdown>
</flux:table.cell>
</flux:table.row>
@endforeach
</flux:table.rows>
</flux:table>

View file

@ -53,7 +53,6 @@
- `GET /admin/users/create` → `admin.users.create`
- `GET /admin/users/{id}` → `admin.users.show`
- `GET /admin/users/{id}/edit` → `admin.users.edit`
- `GET /admin/users/table` → `admin.users.table`
- `GET /admin/roles` → `admin.roles.index`
- `GET /admin/roles/create` → `admin.roles.create`
- `GET /admin/roles/{id}/edit` → `admin.roles.edit`

View file

@ -81,7 +81,6 @@ Route::middleware(['auth', 'verified', EnsureUserIsAdmin::class, LogSlowAdminReq
Volt::route('admin/users/create', 'admin.users.create')->name('admin.users.create');
Volt::route('admin/users/{id}', 'admin.users.show')->name('admin.users.show');
Volt::route('admin/users/{id}/edit', 'admin.users.edit')->name('admin.users.edit');
Volt::route('admin/users/table', 'admin.users.table')->name('admin.users.table');
Volt::route('admin/roles', 'admin.roles.index')->name('admin.roles.index');
Volt::route('admin/roles/create', 'admin.roles.create')->name('admin.roles.create');

View file

@ -3,6 +3,7 @@
use App\Models\Plan;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Support\Facades\Route;
use Tests\TestCase;
beforeEach(function (): void {
@ -10,6 +11,10 @@ beforeEach(function (): void {
$this->seed(RolesAndPermissionsSeeder::class);
});
test('the removed admin users table prototype route no longer exists', function () {
expect(Route::has('admin.users.table'))->toBeFalse();
});
test('legacy customer dashboard URL redirects to me dashboard', function () {
/** @var TestCase $this */
$this->get('/customer')