From c3ef45134c0509fb2616d3f4e125a6107be7ac9b Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Wed, 29 Nov 2023 23:56:04 +0500 Subject: [PATCH] add some permession --- .../Resources/System/Roles/Permission.php | 7 +++ app/Nova/Resources/System/Roles/Role.php | 13 ++++ .../System/Roles/PermissionPolicy.php | 42 ++++++++++--- app/Policies/System/Roles/RolePolicy.php | 60 ++++++++++++++++--- app/Policies/UserPolicy.php | 4 ++ app/Providers/AuthServiceProvider.php | 6 ++ database/seeders/UsersTableSeeder.php | 8 +-- lang/tk.json | 6 +- 8 files changed, 123 insertions(+), 23 deletions(-) diff --git a/app/Nova/Resources/System/Roles/Permission.php b/app/Nova/Resources/System/Roles/Permission.php index b265b10..3ea30cc 100644 --- a/app/Nova/Resources/System/Roles/Permission.php +++ b/app/Nova/Resources/System/Roles/Permission.php @@ -32,6 +32,13 @@ class Permission extends Resource 'id', 'name', ]; + /** + * Indicates if the resource should be displayed in the sidebar. + * + * @var bool + */ + public static $displayInNavigation = false; + /** * Get the fields displayed by the resource. */ diff --git a/app/Nova/Resources/System/Roles/Role.php b/app/Nova/Resources/System/Roles/Role.php index df44fe7..5a234a1 100644 --- a/app/Nova/Resources/System/Roles/Role.php +++ b/app/Nova/Resources/System/Roles/Role.php @@ -48,6 +48,19 @@ class Role extends Resource return __('Role'); } + /** + * Build an "index" query for the given resource. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function indexQuery(NovaRequest $request, $query) + { + $query->where('name', '!=', 'king'); + + return $query; + } + /** * Get the fields displayed by the resource. */ diff --git a/app/Policies/System/Roles/PermissionPolicy.php b/app/Policies/System/Roles/PermissionPolicy.php index 73c2cf8..5ce49d0 100644 --- a/app/Policies/System/Roles/PermissionPolicy.php +++ b/app/Policies/System/Roles/PermissionPolicy.php @@ -13,7 +13,11 @@ class PermissionPolicy */ public function viewAny(User $user): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -21,7 +25,11 @@ class PermissionPolicy */ public function view(User $user, Permission $permission): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -29,7 +37,11 @@ class PermissionPolicy */ public function create(User $user): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -37,7 +49,11 @@ class PermissionPolicy */ public function update(User $user, Permission $permission): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -45,7 +61,11 @@ class PermissionPolicy */ public function delete(User $user, Permission $permission): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -53,7 +73,11 @@ class PermissionPolicy */ public function restore(User $user, Permission $permission): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -61,6 +85,10 @@ class PermissionPolicy */ public function forceDelete(User $user, Permission $permission): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } } diff --git a/app/Policies/System/Roles/RolePolicy.php b/app/Policies/System/Roles/RolePolicy.php index eedfc4f..07ffb25 100644 --- a/app/Policies/System/Roles/RolePolicy.php +++ b/app/Policies/System/Roles/RolePolicy.php @@ -13,7 +13,11 @@ class RolePolicy */ public function viewAny(User $user): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -21,7 +25,11 @@ class RolePolicy */ public function view(User $user, Role $role): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -29,7 +37,11 @@ class RolePolicy */ public function create(User $user): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -37,7 +49,20 @@ class RolePolicy */ public function update(User $user, Role $role): bool { - // + if (in_array($role->name, [ + 'king', + 'superadmin', + 'admin', + 'operator', + ])) { + return false; + } + + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -45,7 +70,20 @@ class RolePolicy */ public function delete(User $user, Role $role): bool { - // + if (in_array($role->name, [ + 'king', + 'superadmin', + 'admin', + 'operator', + ])) { + return false; + } + + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -53,7 +91,11 @@ class RolePolicy */ public function restore(User $user, Role $role): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } /** @@ -61,6 +103,10 @@ class RolePolicy */ public function forceDelete(User $user, Role $role): bool { - // + if ($user->isAdmin()) { + return true; + } + + return false; } } diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 9f44c16..7219f26 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -96,6 +96,10 @@ class UserPolicy */ public function forceDelete(User $user, User $model): bool { + if ($model->email === 'nurmuhammet@mail.com') { + return false; + } + if ($user->isAdmin()) { return true; } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 87ea079..7b9bc1d 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,6 +3,10 @@ namespace App\Providers; // use Illuminate\Support\Facades\Gate; +use App\Models\System\Roles\Permission; +use App\Models\System\Roles\Role; +use App\Policies\System\Roles\PermissionPolicy; +use App\Policies\System\Roles\RolePolicy; use App\Policies\UserPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; @@ -15,6 +19,8 @@ class AuthServiceProvider extends ServiceProvider */ protected $policies = [ User::class => UserPolicy::class, + Role::class => RolePolicy::class, + Permission::class => PermissionPolicy::class, ]; /** diff --git a/database/seeders/UsersTableSeeder.php b/database/seeders/UsersTableSeeder.php index c019053..dfbc582 100644 --- a/database/seeders/UsersTableSeeder.php +++ b/database/seeders/UsersTableSeeder.php @@ -23,17 +23,13 @@ class UsersTableSeeder extends Seeder return; } - $roles = [ + collect([ 'king', 'superadmin', 'admin', 'operator', 'user', - ]; - - foreach ($roles as $role) { - Role::create(['name' => $role]); - } + ])->each(fn ($role) => Role::create(['name' => $role])); } public function createAdmins(): void diff --git a/lang/tk.json b/lang/tk.json index eabe34f..c2c2c9b 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -16,8 +16,8 @@ "Balkan": "Balkan", "Bandwidth Limit Exceeded": "Zolak giňligi çäklendirildi", "Before proceeding, please check your email for a verification link.": "Dowam etmezden ozal tassyklama baglanyşygy üçin e-poçtaňyzy barlaň.", - "Billing password": "Hasap paroly", - "Billing username": "Hasap ulanyjy ady", + "Billing password": "Billing paroly", + "Billing username": "Billing ulanyjy ady", "Born place (passport)": "Doglan ýeri (pasport)", "Branch": "Şahamça", "Branches": "Şahamçalar", @@ -73,7 +73,7 @@ "Loan orders": "Karz sargytlary", "Loan type": "Karz görnüşi", "Loan types": "Karz görnüşleri", - "Location": "Ýerleşýän ýeri", + "Location": "Lokasiýa", "Locked": "Gulply", "Login": "Giriş", "Logout": "Hasapdan çykmak",