• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::chatUrlDelete
static function chatUrlDelete($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'];
	$url = new BitrixImV2LinkUrlUrlItem($linkId);
	if ($url->getId() === null)
	{
		throw new BitrixRestRestException('Url not found', BitrixImV2EntityUrlUrlError::NOT_FOUND, CRestServer::STATUS_NOT_FOUND);
	}

	$chatId = $url->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 !== $url->getAuthorId() && !$USER->IsAdmin())
	{
		throw new BitrixRestRestException('You do not have access to delete this url', BitrixImV2EntityUrlUrlError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	$urls = new BitrixImV2LinkUrlUrlCollection();
	$urls->add($url);

	$deleteResult = (new BitrixImV2LinkUrlUrlService())->deleteUrls($urls);

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

	return true;
}