From 1494273efd996d1834fb74fae16c7dd1809946fc Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sun, 13 Sep 2026 02:44:00 +0200 Subject: [PATCH] Add viewer access to records and restrict activity log - canView() + canViewAny() in EnforcesRoles: all SMS roles can view - View pages for all 7 resources so viewers can open records read-only - Custom ActivityResource restricts activity log to admin + manager only Co-Authored-By: Claude Sonnet 4.6 --- app/Filament/User/Resources/ActivityResource.php | 11 +++++++++++ app/Filament/User/Resources/PackingResource.php | 1 + .../Resources/PackingResource/Pages/ViewPacking.php | 11 +++++++++++ .../User/Resources/ProductInventoryResource.php | 1 + .../Pages/ViewProductInventory.php | 11 +++++++++++ app/Filament/User/Resources/ProductResource.php | 1 + .../Resources/ProductResource/Pages/ViewProduct.php | 11 +++++++++++ app/Filament/User/Resources/ProductSaleResource.php | 1 + .../ProductSaleResource/Pages/ViewProductSale.php | 11 +++++++++++ app/Filament/User/Resources/SpiceResource.php | 1 + .../User/Resources/SpiceResource/Pages/ViewSpice.php | 11 +++++++++++ app/Filament/User/Resources/SpiceSupplierResource.php | 1 + .../SpiceSupplierResource/Pages/ViewSpiceSupplier.php | 11 +++++++++++ app/Filament/User/Resources/SupplierResource.php | 1 + .../Resources/SupplierResource/Pages/ViewSupplier.php | 11 +++++++++++ app/Traits/EnforcesRoles.php | 10 ++++++++++ config/filament-logger.php | 2 +- 17 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 app/Filament/User/Resources/ActivityResource.php create mode 100644 app/Filament/User/Resources/PackingResource/Pages/ViewPacking.php create mode 100644 app/Filament/User/Resources/ProductInventoryResource/Pages/ViewProductInventory.php create mode 100644 app/Filament/User/Resources/ProductResource/Pages/ViewProduct.php create mode 100644 app/Filament/User/Resources/ProductSaleResource/Pages/ViewProductSale.php create mode 100644 app/Filament/User/Resources/SpiceResource/Pages/ViewSpice.php create mode 100644 app/Filament/User/Resources/SpiceSupplierResource/Pages/ViewSpiceSupplier.php create mode 100644 app/Filament/User/Resources/SupplierResource/Pages/ViewSupplier.php diff --git a/app/Filament/User/Resources/ActivityResource.php b/app/Filament/User/Resources/ActivityResource.php new file mode 100644 index 0000000..d0c32a5 --- /dev/null +++ b/app/Filament/User/Resources/ActivityResource.php @@ -0,0 +1,11 @@ +user()?->hasAnyRole(['sms-admin', 'sms-manager']) ?? false; + } +} diff --git a/app/Filament/User/Resources/PackingResource.php b/app/Filament/User/Resources/PackingResource.php index 3982757..23cb5ac 100644 --- a/app/Filament/User/Resources/PackingResource.php +++ b/app/Filament/User/Resources/PackingResource.php @@ -82,6 +82,7 @@ class PackingResource extends Resource return [ 'index' => Pages\ListPackings::route('/'), 'create' => Pages\CreatePacking::route('/create'), + 'view' => Pages\ViewPacking::route('/{record}'), 'edit' => Pages\EditPacking::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/PackingResource/Pages/ViewPacking.php b/app/Filament/User/Resources/PackingResource/Pages/ViewPacking.php new file mode 100644 index 0000000..dca6769 --- /dev/null +++ b/app/Filament/User/Resources/PackingResource/Pages/ViewPacking.php @@ -0,0 +1,11 @@ + Pages\ListProductInventory::route('/'), 'create' => Pages\CreateProductInventory::route('/create'), + 'view' => Pages\ViewProductInventory::route('/{record}'), 'edit' => Pages\EditProductInventory::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/ProductInventoryResource/Pages/ViewProductInventory.php b/app/Filament/User/Resources/ProductInventoryResource/Pages/ViewProductInventory.php new file mode 100644 index 0000000..99e8112 --- /dev/null +++ b/app/Filament/User/Resources/ProductInventoryResource/Pages/ViewProductInventory.php @@ -0,0 +1,11 @@ + Pages\ListProducts::route('/'), 'create' => Pages\CreateProduct::route('/create'), + 'view' => Pages\ViewProduct::route('/{record}'), 'edit' => Pages\EditProduct::route('/{record}/edit'), 'recipe-history' => Pages\RecipeHistory::route('/{record}/rezept-versionen'), ]; diff --git a/app/Filament/User/Resources/ProductResource/Pages/ViewProduct.php b/app/Filament/User/Resources/ProductResource/Pages/ViewProduct.php new file mode 100644 index 0000000..b83f445 --- /dev/null +++ b/app/Filament/User/Resources/ProductResource/Pages/ViewProduct.php @@ -0,0 +1,11 @@ + Pages\ListProductSales::route('/'), 'create' => Pages\CreateProductSale::route('/create'), + 'view' => Pages\ViewProductSale::route('/{record}'), 'edit' => Pages\EditProductSale::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/ProductSaleResource/Pages/ViewProductSale.php b/app/Filament/User/Resources/ProductSaleResource/Pages/ViewProductSale.php new file mode 100644 index 0000000..d923f95 --- /dev/null +++ b/app/Filament/User/Resources/ProductSaleResource/Pages/ViewProductSale.php @@ -0,0 +1,11 @@ + Pages\ListSpices::route('/'), 'create' => Pages\CreateSpice::route('/create'), + 'view' => Pages\ViewSpice::route('/{record}'), 'edit' => Pages\EditSpice::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/SpiceResource/Pages/ViewSpice.php b/app/Filament/User/Resources/SpiceResource/Pages/ViewSpice.php new file mode 100644 index 0000000..ef60cc8 --- /dev/null +++ b/app/Filament/User/Resources/SpiceResource/Pages/ViewSpice.php @@ -0,0 +1,11 @@ + Pages\ListSpiceSuppliers::route('/'), 'create' => Pages\CreateSpiceSupplier::route('/create'), + 'view' => Pages\ViewSpiceSupplier::route('/{record}'), 'edit' => Pages\EditSpiceSupplier::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/SpiceSupplierResource/Pages/ViewSpiceSupplier.php b/app/Filament/User/Resources/SpiceSupplierResource/Pages/ViewSpiceSupplier.php new file mode 100644 index 0000000..e214bcc --- /dev/null +++ b/app/Filament/User/Resources/SpiceSupplierResource/Pages/ViewSpiceSupplier.php @@ -0,0 +1,11 @@ + Pages\ListSuppliers::route('/'), 'create' => Pages\CreateSupplier::route('/create'), + 'view' => Pages\ViewSupplier::route('/{record}'), 'edit' => Pages\EditSupplier::route('/{record}/edit'), ]; } diff --git a/app/Filament/User/Resources/SupplierResource/Pages/ViewSupplier.php b/app/Filament/User/Resources/SupplierResource/Pages/ViewSupplier.php new file mode 100644 index 0000000..b22ca5d --- /dev/null +++ b/app/Filament/User/Resources/SupplierResource/Pages/ViewSupplier.php @@ -0,0 +1,11 @@ +user()?->hasAnyRole(['sms-admin', 'sms-manager', 'sms-viewer']) ?? false; + } + + public static function canView(Model $record): bool + { + return auth()->user()?->hasAnyRole(['sms-admin', 'sms-manager', 'sms-viewer']) ?? false; + } + public static function canCreate(): bool { return auth()->user()?->hasAnyRole(['sms-admin', 'sms-manager']) ?? false; diff --git a/config/filament-logger.php b/config/filament-logger.php index 8618b83..3ab43b4 100644 --- a/config/filament-logger.php +++ b/config/filament-logger.php @@ -3,7 +3,7 @@ return [ 'datetime_format' => 'd.m.Y H:i:s', 'date_format' => 'd.m.Y', - 'activity_resource' => \Z3d0X\FilamentLogger\Resources\ActivityResource::class, + 'activity_resource' => \App\Filament\User\Resources\ActivityResource::class, 'resources' => [ 'enabled' => true,