• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::chatTaskDelete
static function chatTaskDelete($arParams, $n, CRestServer $server)
{
	$arParams = array_change_key_case($arParams, CASE_UPPER);

	if (!isset($arParams['LINK_ID']) || (int)$arParams['LINK_ID'] <= 0)
	{
		throw new BitrixRestRestException('LINK_ID can`t be empty', 'LINK_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
	}

	$linkId = (int)$arParams['LINK_ID'];
	$task = new BitrixImV2LinkTaskTaskItem($linkId);
	if ($task->getId() === null)
	{
		throw new BitrixRestRestException('Task not found', BitrixImV2EntityTaskTaskError::NOT_FOUND, CRestServer::STATUS_NOT_FOUND);
	}

	$chatId = $task->getChatId();
	$chat = BitrixImV2Chat::getInstance($chatId);

	if (!$chat->hasAccess())
	{
		throw new BitrixRestRestException('You do not have access to this chat', BitrixImV2RestRestError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	global $USER;
	$userId = (int)$USER->GetID();

	if ($userId !== $task->getAuthorId() && !$USER->IsAdmin())
	{
		throw new BitrixRestRestException('You do not have access to delete this task', BitrixImV2EntityTaskTaskError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	$deleteResult = (new BitrixImV2LinkTaskTaskService())->unregisterTask($task, false);

	if (!$deleteResult->isSuccess())
	{
		throw new BitrixRestRestException('Failed to delete task', BitrixImV2EntityTaskTaskError::DELETE_ERROR, CRestServer::STATUS_INTERNAL);
	}

	return true;
}