CCrmRole::GetUserPerms

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRole
  4. GetUserPerms
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_role.php
  • Класс: \CCrmRole
  • Вызов: CCrmRole::GetUserPerms
public function GetUserPerms($userId)
{
	$userId = intval($userId);
	if($userId <= 0)
	{
		return [];
	}

	static $memoryCache = [];
	if (isset($memoryCache[$userId]))
	{
		return $memoryCache[$userId];
	}

	$userAccessCodes = \Bitrix\Crm\Service\Container::getInstance()
		->getUserPermissions($userId)
		->getAttributesProvider()
		->getUserAttributesCodes()
	;

	$cache = Main\Application::getInstance()->getCache();
	$cacheId = 'crm_user_permission_roles_' . $userId . '_' . md5(serialize($userAccessCodes));

	if ($cache->initCache(self::CACHE_TIME, $cacheId, self::CACHE_PATH))
	{
		$roles = $cache->getVars();
	}
	else
	{
		$cache->startDataCache();
		$roles = [];

		if (!empty($userAccessCodes))
		{
			$rolesRelations = RoleRelationTable::getList([
				'filter' => [
					'@RELATION' => $userAccessCodes,
				],
				'select' => [
					'ROLE_ID'
				]
			]);
			while ($roleRelation = $rolesRelations->fetch())
			{
				$roles[] = $roleRelation['ROLE_ID'];
			}
		}
		$cache->endDataCache($roles);
	}

	$result = RolePermission::getPermissionsByRoles($roles);
	$memoryCache[$userId] = $result;

	return $result;
}

Добавить комментарий