- 更新 UserResource 添加角色和权限管理 - 添加角色选择字段(多选) - 添加直接权限配置(按模块分组的复选框列表) - 在用户列表中显示角色和权限数量 - 添加角色筛选器 - 防止删除超级管理员 - 创建 ViewUser 页面显示用户详细权限信息 - 显示所有权限(角色权限 + 直接权限) - 按模块分组展示权限 - 区分显示直接权限 - 创建 UserPolicy 控制用户管理权限 - 基于 user.* 权限控制访问 - 保护超级管理员不被编辑和删除 - 防止用户删除自己 - 在 AppServiceProvider 中注册 UserPolicy
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\SopTemplate;
|
|
use App\Observers\DocumentObserver;
|
|
use App\Policies\SopTemplatePolicy;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// 配置 Carbon 使用中文
|
|
Carbon::setLocale('zh_CN');
|
|
|
|
// 注册文档观察者,用于自动管理 Meilisearch 索引
|
|
Document::observe(DocumentObserver::class);
|
|
|
|
// 注册策略
|
|
Gate::policy(\App\Models\Document::class, \App\Policies\DocumentPolicy::class);
|
|
Gate::policy(\App\Models\Terminal::class, \App\Policies\TerminalPolicy::class);
|
|
Gate::policy(SopTemplate::class, SopTemplatePolicy::class);
|
|
Gate::policy(\Spatie\Permission\Models\Role::class, \App\Policies\RolePolicy::class);
|
|
Gate::policy(\App\Models\User::class, \App\Policies\UserPolicy::class);
|
|
}
|
|
}
|