- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/integration/eventhandler.php
- Класс: Bitrix\Sender\Integration\EventHandler
- Вызов: EventHandler::onBeforeUpdateLetterTable
static function onBeforeUpdateLetterTable(MainEntity\Event $event, MainEntity\EventResult $result)
{
$data = $event->getParameters();
if (Bitrix24\Service::isCloud() && isset($data['fields']['STATUS']))
{
$oldRow = LetterTable::getRowById($data['primary']['ID']);
$updatedBy = $data['fields']['UPDATED_BY'] ?? $oldRow['UPDATED_BY'];
if (in_array($data['fields']['STATUS'], Dispatch\Semantics::getWorkStates()))
{
$user = new User($updatedBy);
if (!$user->isAgreementAccepted())
{
$result->addError(
new MainEntity\EntityError(Agreement::getErrorText(), 'NEED_ACCEPT_AGREEMENT')
);
return;
}
$letter = Entity\Letter::createInstanceById($data['primary']['ID']);
if (is_null($letter))
{
$result->addError(
new MainEntity\EntityError(
Loc::getMessage("SENDER_LETTER_ONBEFOREUPDATE_ERROR_LETTER_NOT_AVAILABLE"), 'FEATURE_NOT_AVAILABLE'
)
);
return;
}
if (!$letter->getMessage()->isAvailable())
{
if ($letter->getState()->isWaiting() || $letter->getState()->isSending())
{
$letter->stop();
}
$result->addError(
new MainEntity\EntityError(
Loc::getMessage("SENDER_LETTER_ONBEFOREUPDATE_ERROR_FEATURE_NOT_AVAILABLE"), 'FEATURE_NOT_AVAILABLE'
)
);
return;
}
$isEmail = ($oldRow['MESSAGE_CODE'] === Message\iBase::CODE_MAIL);
$isEmailBlocked = Bitrix24\Limitation\Rating::isBlocked();
if ($isEmail && $isEmailBlocked)
{
$result->addError(
new MainEntity\EntityError(
Bitrix24\Limitation\Rating::getNotifyText('blocked')
)
);
}
if ($isEmail)
{
// check sender email:
$emailFrom = $letter->getMessage()->getConfiguration()->getOption('EMAIL_FROM')->getValue();
if (!Sender\AllowedSender::isAllowed($emailFrom, $updatedBy))
{
$result->addError(
new MainEntity\EntityError(
Loc::getMessage("SENDER_LETTER_ONBEFOREUPDATE_ERROR_INVALID_FROM_EMAIL"), 'WRONG_EMAIL_FROM'
)
);
}
}
}
}
}