Add user role management: introduce UserRole enum for role definitions, implement role-based access control in various resources and pages, and enhance authorization logic in the PanelProvider for improved security and user experience.

This commit is contained in:
nurmuhammet committed 2025-07-29 15:33:36 +05:00
1 parent c7e01f404d
commit a1826ae53c
18 files changed
+226

No files matched your search

+6
View File
@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Settings\AboutSettings;
use App\Models\UserRole;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Repeater;
@@ -245,4 +246,9 @@ public function getSubheading(): string|Htmlable|null
{
return 'Manage the content sections of the About Us page.';
}
public static function canView(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Settings\ContactSettings;
use App\Models\UserRole;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
@@ -84,4 +85,9 @@ public function getSubheading(): string|Htmlable|null
{
return 'Manage the contact form details, contact information, and map embed.';
}
public static function canView(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
+6
View File
@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Settings\HomeSettings;
use App\Models\UserRole;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Repeater;
@@ -292,4 +293,9 @@ public function getSubheading(): string|Htmlable|null
{
return 'Manage the homepage hero section, background video, and call-to-action content.';
}
public static function canView(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
+6
View File
@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Settings\SiteSettings;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\SettingsPage;
@@ -168,4 +169,9 @@ public function getSubheading(): string|Htmlable|null
{
return 'Manage your website\'s general configuration';
}
public static function canView(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Settings\SiteSocialSettings;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\SettingsPage;
@@ -77,4 +78,9 @@ public function getSubheading(): string|Htmlable|null
{
return 'Manage your social media profiles and sharing options';
}
public static function canView(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -5,6 +5,7 @@
use App\Filament\Resources\ApplicationResource\Pages;
use App\Models\Application;
use App\Models\Career;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
@@ -104,4 +105,9 @@ public static function getPages(): array
'edit' => Pages\EditApplication::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
+31
View File
@@ -13,6 +13,7 @@
use Filament\Tables;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class AuthorResource extends Resource
{
@@ -91,4 +92,34 @@ public static function getPages(): array
'edit' => Pages\EditAuthor::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->can('view-authors');
}
public static function canCreate(): bool
{
return auth()->user()->can('view-authors');
}
public static function canEdit(mixed $record): bool
{
return auth()->user()->can('view-authors');
}
public static function canDelete(mixed $record): bool
{
return auth()->user()->can('view-authors');
}
public static function canDeleteAny(): bool
{
return auth()->user()->can('view-authors');
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withoutGlobalScopes();
}
}
+6
View File
@@ -4,6 +4,7 @@
use App\Filament\Resources\BrandResource\Pages;
use App\Models\Brand;
use App\Models\UserRole;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
@@ -79,4 +80,9 @@ public static function getPages(): array
'index' => Pages\ManageBrands::route('/'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -5,6 +5,7 @@
use App\Filament\Resources\CareerResource\Pages;
use App\Filament\Resources\CareerResource\RelationManagers;
use App\Models\Career;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Textarea;
@@ -117,4 +118,9 @@ public static function getPages(): array
'edit' => Pages\EditCareer::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -4,6 +4,7 @@
use App\Filament\Resources\CommentResource\Pages;
use App\Models\Comment;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
@@ -93,4 +94,9 @@ public static function getPages(): array
'edit' => Pages\EditComment::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -5,6 +5,7 @@
use App\Filament\Resources\InternshipResource\Pages;
use App\Filament\Resources\InternshipResource\RelationManagers;
use App\Models\Internship;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Textarea;
@@ -120,4 +121,9 @@ public static function getPages(): array
'edit' => Pages\EditInternship::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
+32
View File
@@ -17,6 +17,8 @@
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
class NewsResource extends Resource
{
@@ -123,4 +125,34 @@ public static function getPages(): array
'edit' => Pages\EditNews::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canCreate(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canEdit(mixed $record): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canDelete(mixed $record): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canDeleteAny(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withoutGlobalScopes();
}
}
@@ -4,6 +4,7 @@
use App\Filament\Resources\SolutionResource\Pages;
use App\Models\Solution;
use App\Models\UserRole;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
@@ -129,4 +130,9 @@ public static function getPages(): array
'edit' => Pages\EditSolution::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}
@@ -15,6 +15,7 @@
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Builder;
class SuccessResource extends Resource
{
@@ -112,4 +113,34 @@ public static function getPages(): array
'edit' => Pages\EditSuccess::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canCreate(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canEdit(mixed $record): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canDelete(mixed $record): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function canDeleteAny(): bool
{
return auth()->user()->can('manage-news-and-success');
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withoutGlobalScopes();
}
}
@@ -5,6 +5,7 @@
use App\Filament\Resources\TeamMemberResource\Pages;
use App\Filament\Resources\TeamMemberResource\RelationManagers;
use App\Models\TeamMember;
use App\Models\UserRole;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
@@ -91,4 +92,9 @@ public static function getPages(): array
'edit' => Pages\EditTeamMember::route('/{record}/edit'),
];
}
public static function canViewAny(): bool
{
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
}
}