- 更新 DocumentPolicy 添加权限检查 - viewAny/view/create/update/delete/download 都检查相应权限 - 保留现有的分组访问控制逻辑 - 保留安全日志记录功能 - 更新 TerminalPolicy 添加权限检查 - 所有方法都基于 terminal.* 权限 - 新增 sync 方法用于配置同步权限检查 - 更新 SopTemplatePolicy 添加权限检查 - 所有方法都基于 sop-template.* 权限 - 保留现有的状态检查逻辑(已发布不可编辑/删除) - 创建 SystemSettingPolicy - 实现 viewAny/view/update 权限检查 - 创建 ActivityLogPolicy - 实现 viewAny/view/export 权限检查 - 创建 GroupPolicy - 实现完整的 CRUD 权限检查 - 删除前检查关联文档和用户 - 在 AppServiceProvider 中注册所有策略
96 lines
1.9 KiB
PHP
96 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\SopTemplate;
|
|
use App\Models\User;
|
|
|
|
class SopTemplatePolicy
|
|
{
|
|
/**
|
|
* 查看任何 SOP 模板
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->can('sop-template.view');
|
|
}
|
|
|
|
/**
|
|
* 查看 SOP 模板
|
|
*/
|
|
public function view(User $user, SopTemplate $sopTemplate): bool
|
|
{
|
|
return $user->can('sop-template.view');
|
|
}
|
|
|
|
/**
|
|
* 创建 SOP 模板
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->can('sop-template.create');
|
|
}
|
|
|
|
/**
|
|
* 更新 SOP 模板
|
|
*/
|
|
public function update(User $user, SopTemplate $sopTemplate): bool
|
|
{
|
|
// 首先检查权限
|
|
if (!$user->can('sop-template.update')) {
|
|
return false;
|
|
}
|
|
|
|
// 已发布的模板不能直接编辑
|
|
if ($sopTemplate->status === 'published') {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除 SOP 模板
|
|
*/
|
|
public function delete(User $user, SopTemplate $sopTemplate): bool
|
|
{
|
|
// 首先检查权限
|
|
if (!$user->can('sop-template.delete')) {
|
|
return false;
|
|
}
|
|
|
|
// 已发布的模板不能删除
|
|
if ($sopTemplate->status === 'published') {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 发布 SOP 模板
|
|
*/
|
|
public function publish(User $user, SopTemplate $sopTemplate): bool
|
|
{
|
|
// 首先检查权限
|
|
if (!$user->can('sop-template.publish')) {
|
|
return false;
|
|
}
|
|
|
|
return $sopTemplate->status === 'draft';
|
|
}
|
|
|
|
/**
|
|
* 归档 SOP 模板
|
|
*/
|
|
public function archive(User $user, SopTemplate $sopTemplate): bool
|
|
{
|
|
// 首先检查权限
|
|
if (!$user->can('sop-template.archive')) {
|
|
return false;
|
|
}
|
|
|
|
return $sopTemplate->status === 'published';
|
|
}
|
|
}
|