• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/access/rule/taskcompleterule.php
  • Класс: BitrixTasksAccessRuleTaskCompleteRule
  • Вызов: TaskCompleteRule::execute
public function execute(AccessibleItem $task = null, $params = null): bool
{
	if (!$task)
	{
		$this->controller->addError(static::class, 'Incorrect task');
		return false;
	}

	if ($task->isClosed())
	{
		$this->controller->addError(static::class, 'Task already completed');
		return false;
	}

	if ($this->user->isAdmin())
	{
		return true;
	}

	if ($task->getStatus() === Status::SUPPOSEDLY_COMPLETED)
	{
		if (
			$task->isMember($this->user->getUserId(), RoleDictionary::ROLE_DIRECTOR)
			|| $this->isSubordinateTask($task)
		)
		{
			return true;
		}
		$this->controller->addError(static::class, 'Task is supposedly completed');
		return false;
	}

	if (
		$task->isMember($this->user->getUserId(), RoleDictionary::ROLE_DIRECTOR)
		|| $task->isMember($this->user->getUserId(), RoleDictionary::ROLE_RESPONSIBLE)
		|| $task->isMember($this->user->getUserId(), RoleDictionary::ROLE_ACCOMPLICE)
	)
	{
		return true;
	}

	if (
		$task->getGroupId()
		&& Loader::includeModule("socialnetwork")
		&& BitrixSocialnetworkInternalsRegistryFeaturePermRegistry::getInstance()->get(
			$task->getGroupId(),
			'tasks',
			'edit_tasks',
			$this->user->getUserId()
		)
	)
	{
		return true;
	}

	if ($this->isSubordinateTask($task))
	{
		return true;
	}

	$this->controller->addError(static::class, 'Access to complete task denied');
	return false;
}