add some permession
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user