add some permession

This commit is contained in:
2023-11-29 23:56:04 +05:00
parent f073020e86
commit c3ef45134c
8 changed files with 123 additions and 23 deletions

View File

@@ -32,6 +32,13 @@ class Permission extends Resource
'id', 'name', '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. * Get the fields displayed by the resource.
*/ */

View File

@@ -48,6 +48,19 @@ class Role extends Resource
return __('Role'); 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. * Get the fields displayed by the resource.
*/ */

View File

@@ -13,7 +13,11 @@ class PermissionPolicy
*/ */
public function viewAny(User $user): bool 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 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 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 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 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 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 public function forceDelete(User $user, Permission $permission): bool
{ {
// if ($user->isAdmin()) {
return true;
}
return false;
} }
} }

View File

@@ -13,7 +13,11 @@ class RolePolicy
*/ */
public function viewAny(User $user): bool 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 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 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 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 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 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 public function forceDelete(User $user, Role $role): bool
{ {
// if ($user->isAdmin()) {
return true;
}
return false;
} }
} }

View File

@@ -96,6 +96,10 @@ class UserPolicy
*/ */
public function forceDelete(User $user, User $model): bool public function forceDelete(User $user, User $model): bool
{ {
if ($model->email === 'nurmuhammet@mail.com') {
return false;
}
if ($user->isAdmin()) { if ($user->isAdmin()) {
return true; return true;
} }

View File

@@ -3,6 +3,10 @@
namespace App\Providers; namespace App\Providers;
// use Illuminate\Support\Facades\Gate; // 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 App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@@ -15,6 +19,8 @@ class AuthServiceProvider extends ServiceProvider
*/ */
protected $policies = [ protected $policies = [
User::class => UserPolicy::class, User::class => UserPolicy::class,
Role::class => RolePolicy::class,
Permission::class => PermissionPolicy::class,
]; ];
/** /**

View File

@@ -23,17 +23,13 @@ class UsersTableSeeder extends Seeder
return; return;
} }
$roles = [ collect([
'king', 'king',
'superadmin', 'superadmin',
'admin', 'admin',
'operator', 'operator',
'user', 'user',
]; ])->each(fn ($role) => Role::create(['name' => $role]));
foreach ($roles as $role) {
Role::create(['name' => $role]);
}
} }
public function createAdmins(): void public function createAdmins(): void

View File

@@ -16,8 +16,8 @@
"Balkan": "Balkan", "Balkan": "Balkan",
"Bandwidth Limit Exceeded": "Zolak giňligi çäklendirildi", "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ň.", "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 password": "Billing paroly",
"Billing username": "Hasap ulanyjy ady", "Billing username": "Billing ulanyjy ady",
"Born place (passport)": "Doglan ýeri (pasport)", "Born place (passport)": "Doglan ýeri (pasport)",
"Branch": "Şahamça", "Branch": "Şahamça",
"Branches": "Şahamçalar", "Branches": "Şahamçalar",
@@ -73,7 +73,7 @@
"Loan orders": "Karz sargytlary", "Loan orders": "Karz sargytlary",
"Loan type": "Karz görnüşi", "Loan type": "Karz görnüşi",
"Loan types": "Karz görnüşleri", "Loan types": "Karz görnüşleri",
"Location": "Ýerleşýän ýeri", "Location": "Lokasiýa",
"Locked": "Gulply", "Locked": "Gulply",
"Login": "Giriş", "Login": "Giriş",
"Logout": "Hasapdan çykmak", "Logout": "Hasapdan çykmak",