- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/access/rule/templatesaverule.php
- Класс: BitrixTasksAccessRuleTemplateSaveRule
- Вызов: TemplateSaveRule::execute
public function execute(AccessibleItem $template = null, $params = null): bool
{
if (!$template)
{
$this->controller->addError(static::class, 'Incorrect template');
return false;
}
if (!$this->checkParams($params))
{
$this->controller->addError(static::class, 'Incorrect params');
return false;
}
$this->oldTemplate = $template;
$this->newTemplate = $params;
if (
!$this->oldTemplate->getId()
&& !$this->controller->check(ActionDictionary::ACTION_TEMPLATE_CREATE, $this->oldTemplate, $params)
)
{
$this->controller->addError(static::class, 'Access to create or update template denied');
return false;
}
elseif (!$this->controller->check(ActionDictionary::ACTION_TEMPLATE_EDIT, $this->oldTemplate, $params))
{
$this->controller->addError(static::class, 'Access to create or update template denied');
return false;
}
if (!$this->canAssignMembersExtranet())
{
return false;
}
if (!$this->newTemplate->isRegular())
{
return true;
}
$members = $this->newTemplate->getMembers();
$user = UserModel::createFromId($members[RoleDictionary::ROLE_DIRECTOR][0]);
if (
$this->newTemplate->getGroupId()
&& $this->oldTemplate->getGroupId() !== $this->newTemplate->getGroupId()
&& !$this->canSetGroup($user->getUserId(), $this->newTemplate->getGroupId())
)
{
$this->controller->addError(static::class, 'Access to set group denied');
return false;
}
$responsibleList = $members[RoleDictionary::ROLE_RESPONSIBLE] ?? [];
foreach ($responsibleList as $responsibleId)
{
if (!$this->canAssign($user, $responsibleId, [], $template->getGroupId()))
{
$this->controller->addError(static::class, 'Access to assign responsible denied');
return false;
}
}
$accompliceList = $members[RoleDictionary::ROLE_ACCOMPLICE] ?? [];
foreach ($accompliceList as $accompliceId)
{
if (!$this->canAssign($user, $accompliceId, [], $template->getGroupId()))
{
$this->controller->addError(static::class, 'Access to assign accomplice denied');
return false;
}
}
return true;
}