feat(权限): 完善所有策略的权限检查

- 更新 DocumentPolicy 添加权限检查
  - viewAny/view/create/update/delete/download 都检查相应权限
  - 保留现有的分组访问控制逻辑
  - 保留安全日志记录功能
- 更新 TerminalPolicy 添加权限检查
  - 所有方法都基于 terminal.* 权限
  - 新增 sync 方法用于配置同步权限检查
- 更新 SopTemplatePolicy 添加权限检查
  - 所有方法都基于 sop-template.* 权限
  - 保留现有的状态检查逻辑(已发布不可编辑/删除)
- 创建 SystemSettingPolicy
  - 实现 viewAny/view/update 权限检查
- 创建 ActivityLogPolicy
  - 实现 viewAny/view/export 权限检查
- 创建 GroupPolicy
  - 实现完整的 CRUD 权限检查
  - 删除前检查关联文档和用户
- 在 AppServiceProvider 中注册所有策略
This commit is contained in:
2026-03-11 10:08:22 +08:00
parent c2b83e7857
commit 386fe42f76
7 changed files with 249 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ class SopTemplatePolicy
*/
public function viewAny(User $user): bool
{
return true;
return $user->can('sop-template.view');
}
/**
@@ -20,7 +20,7 @@ class SopTemplatePolicy
*/
public function view(User $user, SopTemplate $sopTemplate): bool
{
return true;
return $user->can('sop-template.view');
}
/**
@@ -28,7 +28,7 @@ class SopTemplatePolicy
*/
public function create(User $user): bool
{
return true;
return $user->can('sop-template.create');
}
/**
@@ -36,6 +36,11 @@ class SopTemplatePolicy
*/
public function update(User $user, SopTemplate $sopTemplate): bool
{
// 首先检查权限
if (!$user->can('sop-template.update')) {
return false;
}
// 已发布的模板不能直接编辑
if ($sopTemplate->status === 'published') {
return false;
@@ -49,6 +54,11 @@ class SopTemplatePolicy
*/
public function delete(User $user, SopTemplate $sopTemplate): bool
{
// 首先检查权限
if (!$user->can('sop-template.delete')) {
return false;
}
// 已发布的模板不能删除
if ($sopTemplate->status === 'published') {
return false;
@@ -62,6 +72,11 @@ class SopTemplatePolicy
*/
public function publish(User $user, SopTemplate $sopTemplate): bool
{
// 首先检查权限
if (!$user->can('sop-template.publish')) {
return false;
}
return $sopTemplate->status === 'draft';
}
@@ -70,6 +85,11 @@ class SopTemplatePolicy
*/
public function archive(User $user, SopTemplate $sopTemplate): bool
{
// 首先检查权限
if (!$user->can('sop-template.archive')) {
return false;
}
return $sopTemplate->status === 'published';
}
}