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

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

	if (
		!$template->getId()
	)
	{
		return true;
	}

	if (
		$template->getTemplatePermission($this->user, PermissionDictionary::TEMPLATE_VIEW)
		|| $template->getTemplatePermission($this->user, PermissionDictionary::TEMPLATE_FULL)
	)
	{
		return true;
	}

	$isInDepartment = $template->isInDepartment($this->user->getUserId(), false, [RoleDictionary::ROLE_DIRECTOR]);

	if (
		$this->user->getPermission(PermissionDictionary::TEMPLATE_DEPARTMENT_VIEW)
		&& $isInDepartment
	)
	{
		return true;
	}

	if (
		$this->user->getPermission(PermissionDictionary::TEMPLATE_NON_DEPARTMENT_VIEW)
		&& !$isInDepartment
	)
	{
		return true;
	}

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