• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/engine/checkpermissions.php
  • Класс: BitrixDocumentGeneratorEngineCheckPermissions
  • Вызов: CheckPermissions::onBeforeAction
public function onBeforeAction(Event $event)
{
	if($this->entity === UserPermissions::ENTITY_SETTINGS)
	{
		if(!Driver::getInstance()->getUserPermissions()->canModifySettings())
		{
			$this->errorCollection[] = new Error('You do not have permissions to modify settings');
		}
	}
	elseif($this->entity === UserPermissions::ENTITY_DOCUMENTS)
	{
		if($this->actionType === UserPermissions::ACTION_CREATE)
		{
			foreach($this->action->getArguments() as $argument)
			{
				if($argument instanceof Template)
				{
					if(!Driver::getInstance()->getUserPermissions()->canCreateDocumentOnTemplate($argument->ID))
					{
						$this->errorCollection[] = new Error('You do not have permissions to create document on this template');
					}
				}
			}
		}
		elseif($this->actionType === UserPermissions::ACTION_MODIFY)
		{
			foreach($this->action->getArguments() as $argument)
			{
				if($argument instanceof Document)
				{
					if(!Driver::getInstance()->getUserPermissions()->canModifyDocument($argument->ID))
					{
						$this->errorCollection[] = new Error('You do not have permissions to modify this document');
					}
				}
			}
		}
		elseif(!Driver::getInstance()->getUserPermissions()->canViewDocuments())
		{
			$this->errorCollection[] = new Error('You do not have permissions to view documents');
		}
	}
	elseif($this->entity === UserPermissions::ENTITY_TEMPLATES)
	{
		if(!Driver::getInstance()->getUserPermissions()->canModifyTemplates())
		{
			$this->errorCollection[] = new Error('You do not have permissions to modify templates');
		}
		else
		{
			foreach($this->action->getArguments() as $argument)
			{
				if($argument instanceof Template)
				{
					if(!Driver::getInstance()->getUserPermissions()->canModifyTemplate($argument->ID))
					{
						$this->errorCollection[] = new Error('You do not have permissions to modify this template');
					}
				}
			}
		}
	}

	if(!$this->errorCollection->isEmpty())
	{
		return new EventResult(EventResult::ERROR, null, null, $this);
	}

	return null;
}