permessions added to user
This commit is contained in:
@@ -3,7 +3,16 @@
|
||||
namespace App\Models\System\Roles;
|
||||
|
||||
use Spatie\Permission\Models\Permission as SpatiePermission;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class Permission extends SpatiePermission
|
||||
{
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* Translatable fields
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
public $translatable = ['display_name'];
|
||||
}
|
||||
|
||||
@@ -48,15 +48,15 @@ class CardOrderFieldsForIndex
|
||||
|
||||
Text::make(__('Phone'), 'phone'),
|
||||
|
||||
// Badge::make(__('Status'), 'status')
|
||||
// ->map(OrderRepo::statusClasses())
|
||||
// ->addTypes([
|
||||
// 'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
|
||||
// ])
|
||||
// ->labels(OrderRepo::statusValues())
|
||||
// ->withIcons()
|
||||
// ->icons(OrderRepo::statusIcons())
|
||||
// ->sortable(),
|
||||
Badge::make(__('Status'), 'status')
|
||||
->map(OrderRepo::statusClasses())
|
||||
->addTypes([
|
||||
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
|
||||
])
|
||||
->labels(OrderRepo::statusValues())
|
||||
->withIcons()
|
||||
->icons(OrderRepo::statusIcons())
|
||||
->sortable(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Nova\Resources\System\Roles;
|
||||
|
||||
use App\Models\System\Roles\Permission as PermissionModel;
|
||||
use App\Nova\Resource;
|
||||
use App\Repos\System\Nova\NovaRepo;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
@@ -22,7 +23,7 @@ class Permission extends Resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'name';
|
||||
public static $title = 'display_name';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
@@ -57,8 +58,13 @@ class Permission extends Resource
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
|
||||
Text::make(__('Name'), 'name')
|
||||
->rules('required', 'string', 'max:255', 'unique:permissions,name'),
|
||||
Text::make(__('Code'), 'name')
|
||||
->rules('required', 'string', 'max:255', 'unique:permissions,name')
|
||||
->readonly(NovaRepo::readonlyOnUpdate()),
|
||||
|
||||
Text::make(__('Name'), 'display_name')
|
||||
->rules('required', 'string', 'max:255')
|
||||
->translatable(),
|
||||
|
||||
Text::make(__('Guard name'), 'guard_name')
|
||||
->rules('required', 'string', 'max:255'),
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Nova\Resources\System\Roles;
|
||||
|
||||
use App\Models\System\Roles\Role as RoleModel;
|
||||
use App\Nova\Resource;
|
||||
use App\Repos\System\Nova\NovaRepo;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
@@ -12,16 +14,16 @@ class Role extends Resource
|
||||
/**
|
||||
* The model the resource corresponds to.
|
||||
*
|
||||
* @var class-string<\App\Models\Resources\System\Roles\Role>
|
||||
* @var class-string<RoleModel>
|
||||
*/
|
||||
public static $model = \App\Models\System\Roles\Role::class;
|
||||
public static $model = RoleModel::class;
|
||||
|
||||
/**
|
||||
* The single value that should be used to represent the resource when being displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'name';
|
||||
public static $title = 'display_name';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
@@ -69,12 +71,16 @@ class Role extends Resource
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
|
||||
Text::make(__('Name'), 'name')
|
||||
->rules('required', 'string', 'max:255', 'unique:roles,name'),
|
||||
Text::make(__('Code'), 'name')
|
||||
->rules('required', 'string', 'max:255', 'unique:roles,name')
|
||||
->readonly(NovaRepo::readonlyOnUpdate()),
|
||||
|
||||
Text::make(__('Guard name'), 'guard_name')
|
||||
Text::make(__('Name'), 'display_name')
|
||||
->rules('required', 'string', 'max:255')
|
||||
->translatable(),
|
||||
|
||||
Text::make(__('Guard name'), 'guard_name')
|
||||
->rules('required', 'string', 'max:255'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -48,15 +48,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,14 @@ class NovaRepo
|
||||
return fn () => Gate::allows('isMe', auth()->user());
|
||||
}
|
||||
|
||||
/**
|
||||
* Readonly only on "update" pages
|
||||
*/
|
||||
public static function readonlyOnUpdate(): Closure
|
||||
{
|
||||
return fn ($request) => $request->isUpdateOrUpdateAttachedRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Depends on region
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
Schema::table($tableNames['permissions'], function (Blueprint $table) {
|
||||
$table->jsonb('display_name')->nullable();
|
||||
});
|
||||
|
||||
Schema::table($tableNames['roles'], function (Blueprint $table) {
|
||||
$table->jsonb('display_name')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
Schema::table($tableNames['permissions'], function (Blueprint $table) {
|
||||
$table->dropColumn('display_name');
|
||||
});
|
||||
|
||||
Schema::table($tableNames['roles'], function (Blueprint $table) {
|
||||
$table->dropColumn('display_name');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -28,7 +28,6 @@ class UsersTableSeeder extends Seeder
|
||||
'superadmin',
|
||||
'admin',
|
||||
'operator',
|
||||
'user',
|
||||
])->each(fn ($role) => Role::create(['name' => $role]));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user