Your IP : 3.19.54.158
<?php
/**
* Bitrix Framework
* @package bitrix
* @subpackage tasks
* @copyright 2001-2021 Bitrix
*/
namespace Bitrix\Tasks\Access\Rule;
use Bitrix\Tasks\Access\ActionDictionary;
use Bitrix\Tasks\Access\Permission\PermissionDictionary;
use Bitrix\Main\Access\AccessibleItem;
use Bitrix\Tasks\Access\Role\RoleDictionary;
class TemplateEditRule extends \Bitrix\Main\Access\Rule\AbstractRule
{
public function execute(AccessibleItem $template = null, $params = null): bool
{
if (!$template)
{
return false;
}
if ($this->user->isAdmin())
{
return true;
}
if (!$template->getId())
{
return $this->controller->check(ActionDictionary::ACTION_TEMPLATE_CREATE, $template, $params);
}
if (!$this->controller->check(ActionDictionary::ACTION_TEMPLATE_READ, $template, $params))
{
return false;
}
if ($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_EDIT)
&& $isInDepartment
)
{
return true;
}
if (
$this->user->getPermission(PermissionDictionary::TEMPLATE_NON_DEPARTMENT_EDIT)
&& !$isInDepartment
)
{
return true;
}
return false;
}
}