From e06c332367e938113d0498d9ba9d58342204507c Mon Sep 17 00:00:00 2001 From: TCHOUKOUAHA Boris Gautier Date: Fri, 10 Nov 2023 18:13:29 +0100 Subject: [PATCH] Add 'Tanzanie' to list of countries and restrict access for role 2 users --- app/Filament/Resources/OscResource.php | 7 +++++++ app/Filament/Resources/UserResource.php | 1 + app/Models/User.php | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/OscResource.php b/app/Filament/Resources/OscResource.php index 03f082b..bbef838 100644 --- a/app/Filament/Resources/OscResource.php +++ b/app/Filament/Resources/OscResource.php @@ -46,6 +46,7 @@ public static function form(Form $form): Form 'Cameroun' => 'Cameroun', 'Senegal' => 'Senegal', 'Cote d\'ivoire' => 'Cote d\'ivoire', + 'Tanzanie' => 'Tanzanie', ]), Forms\Components\DatePicker::make('date_fondation'), Forms\Components\Textarea::make('description'), @@ -216,6 +217,12 @@ public static function getEloquentQuery(): Builder SoftDeletingScope::class, ]); } + if( auth()->user()->role == 8) { + return parent::getEloquentQuery()->where('pays', 'Tanzanie') + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 5b97534..9700463 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -51,6 +51,7 @@ public static function form(Form $form): Form '5' => 'User Cameroun', '6' => 'User Senegal', '7' => 'User Cote d\'ivoire', + '8' => 'User Tanzanie', ]) ->required(), ]); diff --git a/app/Models/User.php b/app/Models/User.php index dfc3d87..caa0e75 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -87,7 +87,7 @@ class User extends Authenticatable implements MustVerifyEmail, FilamentUser public function canAccessPanel(\Filament\Panel $panel): bool { - return str_ends_with($this->email, '@francophonie.org') || str_ends_with($this->email, '@ifdd.cm'); + return $this->role != 2 ; } public function oscs()