feat(阶段四): 添加 SOP 模板权限策略

- 创建 SopTemplatePolicy 策略类
- 实现查看、创建、更新、删除权限
- 实现发布和归档权限
- 已发布的模板不能编辑和删除
- 只有草稿状态可以发布
- 只有已发布状态可以归档
- 在 AppServiceProvider 中注册策略
This commit is contained in:
2026-03-09 13:25:05 +08:00
parent ebd1392580
commit 74de79e4c3
2 changed files with 81 additions and 0 deletions

View File

@@ -3,8 +3,11 @@
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
@@ -27,5 +30,8 @@ class AppServiceProvider extends ServiceProvider
// 注册文档观察者,用于自动管理 Meilisearch 索引
Document::observe(DocumentObserver::class);
// 注册策略
Gate::policy(SopTemplate::class, SopTemplatePolicy::class);
}
}