fix: 项目权限 - 100%
This commit is contained in:
@@ -551,15 +551,12 @@ class ProjectTask extends AbstractModel
|
||||
*/
|
||||
public function updateTask($data, &$updateMarking = [])
|
||||
{
|
||||
//
|
||||
AbstractModel::transaction(function () use ($data, &$updateMarking) {
|
||||
// 主任务
|
||||
$mainTask = $this->parent_id > 0 ? self::find($this->parent_id) : null;
|
||||
// 工作流
|
||||
if (Arr::exists($data, 'flow_item_id')) {
|
||||
$isProjectOwner = $this->useridInTheProject(User::userid()) === 2;
|
||||
if (!$isProjectOwner && !$this->isOwner()) {
|
||||
throw new ApiException('仅限项目或任务负责人修改任务状态');
|
||||
}
|
||||
if ($this->flow_item_id == $data['flow_item_id']) {
|
||||
throw new ApiException('任务状态未发生改变');
|
||||
}
|
||||
@@ -580,6 +577,7 @@ class ProjectTask extends AbstractModel
|
||||
throw new ApiException("当前状态[{$currentFlowItem->name}]不可流转到[{$newFlowItem->name}]");
|
||||
}
|
||||
if ($currentFlowItem->userlimit) {
|
||||
$isProjectOwner = $this->useridInTheProject(User::userid()) === 2;
|
||||
if (!$isProjectOwner && !in_array(User::userid(), $currentFlowItem->userids)) {
|
||||
throw new ApiException("当前状态[{$currentFlowItem->name}]仅限状态负责人或项目负责人修改");
|
||||
}
|
||||
@@ -1730,11 +1728,10 @@ class ProjectTask extends AbstractModel
|
||||
* @param int $task_id
|
||||
* @param bool $archived true:仅限未归档, false:仅限已归档, null:不限制
|
||||
* @param bool $trashed true:仅限未删除, false:仅限已删除, null:不限制
|
||||
* @param string $action 动作名称
|
||||
* @param array $with
|
||||
* @return self
|
||||
*/
|
||||
public static function userTask($task_id, $archived = true, $trashed = true, $action = '', $with = [])
|
||||
public static function userTask($task_id, $archived = true, $trashed = true, $with = [])
|
||||
{
|
||||
$builder = self::with($with)->allData()->where("project_tasks.id", intval($task_id));
|
||||
if ($trashed === false) {
|
||||
@@ -1757,7 +1754,7 @@ class ProjectTask extends AbstractModel
|
||||
try {
|
||||
$project = Project::userProject($task->project_id);
|
||||
} catch (\Throwable $e) {
|
||||
if ($task->owner !== null || (empty($action) && $task->permission(4))) {
|
||||
if ($task->owner !== null || $task->permission(4)) {
|
||||
$project = Project::find($task->project_id);
|
||||
if (empty($project)) {
|
||||
throw new ApiException('项目不存在或已被删除', [ 'task_id' => $task_id ], -4002);
|
||||
@@ -1766,52 +1763,7 @@ class ProjectTask extends AbstractModel
|
||||
throw new ApiException($e->getMessage(), [ 'task_id' => $task_id ], -4002);
|
||||
}
|
||||
}
|
||||
if ($action) {
|
||||
self::userTaskPermission($action, $project, $task);
|
||||
}
|
||||
//
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否有执行特定动作的权限
|
||||
* @param string $action 动作名称
|
||||
* @param Project $project 项目实例
|
||||
* @param Task $task 任务实例
|
||||
* @return bool
|
||||
*/
|
||||
public static function userTaskPermission($action, $project, $task = null)
|
||||
{
|
||||
$permissions = ProjectPermission::getPermission($project->id, $action);
|
||||
foreach ($permissions as $permission) {
|
||||
switch ($permission) {
|
||||
case 1:
|
||||
// 项目负责人
|
||||
if (!$project->owner) {
|
||||
throw new ApiException('仅限项目负责人操作', [ 'project_id' => $project->id ]);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// 任务负责人
|
||||
if (!$task->isOwner()) {
|
||||
throw new ApiException('仅限任务负责人操作', [ 'project_id' => $project->id ]);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// 项目成员
|
||||
$instance = new self();
|
||||
if (!($instance->useridInTheProject(User::userid()) === 1)) {
|
||||
throw new ApiException('仅限项目成员操作', [ 'project_id' => $project->id ]);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// 任务成员(任务成员 = 任务创建人+任务协助人+任务负责人)
|
||||
if ($task->isCreater()) {
|
||||
throw new ApiException('仅限任务成员操作', [ 'project_id' => $project->id ]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user