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

	$params = array_change_key_case($params, CASE_UPPER);
	$params['CHAT_ID'] = (int)$params['CHAT_ID'];
	$params['USER_ID'] = (int)$params['USER_ID'];

	if ($params['CHAT_ID'] <= 0)
	{
		throw new BitrixRestRestException("Chat ID can't be empty", "CHAT_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}
	if ($params['USER_ID'] <= 0)
	{
		throw new BitrixRestRestException("User ID can't be empty", "USER_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}

	//check if current user if owner of chat
	$chat = BitrixImModelChatTable::getRowById($params['CHAT_ID']);
	if (!$chat)
	{
		throw new BitrixRestRestException("Chat was not found", "CHAT_NOT_FOUND", CRestServer::STATUS_WRONG_REQUEST);
	}
	$owner = (int)$chat['AUTHOR_ID'];
	if ((int)$USER->GetID() !== $owner)
	{
		throw new BitrixRestRestException("You cannot perform this operation", "NO_ACCESS", CRestServer::STATUS_WRONG_REQUEST);
	}

	//check if renamed user is call auth
	$userToRename = BitrixImUser::getInstance($params['USER_ID']);
	if (!$userToRename)
	{
		throw new BitrixRestRestException("User was not found", "USER_NOT_FOUND", CRestServer::STATUS_WRONG_REQUEST);
	}
	$externalAuth = $userToRename->getExternalAuthId();
	if ($externalAuth !== 'call')
	{
		throw new BitrixRestRestException("You cannot rename this user", "WRONG_USER_AUTH_TYPE", CRestServer::STATUS_WRONG_REQUEST);
	}

	$userManager = new CUser;
	$userManager->Update($params['USER_ID'], [
		'NAME' => $params['NAME']
	]);

	$relations = BitrixImChat::getRelation($params['CHAT_ID'], ['WITHOUT_COUNTERS' => 'Y']);

	if (CModule::IncludeModule("pull"))
	{
		BitrixPullEvent::add(array_keys($relations), [
			'module_id' => 'im',
			'command' => 'callUserNameUpdate',
			'params' => [
				'userId' => $params['USER_ID'],
				'name' => $params['NAME']
			],
			'extra' => BitrixImCommon::getPullExtra()
		]);
	}
}