Rights::refreshAdditionalRights

  1. Bitrix24 API (v. 23.675.0)
  2. landing
  3. Rights
  4. refreshAdditionalRights
  • Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/rights.php
  • Класс: BitrixLandingRights
  • Вызов: Rights::refreshAdditionalRights
static function refreshAdditionalRights(array $additionalRights = [])
{
	if (!self::isFeatureOn())
	{
		return;
	}

	$rights = [];
	foreach (self::ADDITIONAL_RIGHTS as $right)
	{
		$rights[$right] = [];
	}

	// get additional from all roles
	$res = Role::getList([
		'select' => [
			'ID', 'ACCESS_CODES', 'ADDITIONAL_RIGHTS'
		]
	]);
	while ($row = $res->fetch())
	{
		$row['ACCESS_CODES'] = (array) $row['ACCESS_CODES'];
		$row['ADDITIONAL_RIGHTS'] = (array) $row['ADDITIONAL_RIGHTS'];
		foreach ($row['ADDITIONAL_RIGHTS'] as $right)
		{
			if (isset($rights[$right]))
			{
				$rights[$right][$row['ID']] = $row['ACCESS_CODES'];
			}
		}
	}

	// refresh options
	foreach ($rights as $code => $right)
	{
		// gets current from option
		$option = Manager::getOption('access_codes_' . $code, '');
		$option = unserialize($option, ['allowed_classes' => false]);
		if (isset($option[0]))
		{
			$right[0] = $option[0];
		}

		// rewrite some rights, if need
		if (
			isset($additionalRights[$code]) &&
			is_array($additionalRights[$code])
		)
		{
			foreach ($additionalRights[$code] as $i => $accCodes)
			{
				$right[$i] = (array) $accCodes;
			}
		}

		// set new rights in option
		Manager::setOption('access_codes_' . $code, $right ? serialize($right) : '');

		// clear menu cache
		if (Manager::isB24())
		{
			Manager::getCacheManager()->clearByTag(
				'bitrix24_left_menu'
			);
			Manager::getCacheManager()->cleanDir(
				'menu'
			);
			CBitrixComponent::clearComponentCache(
				'bitrix:menu'
			);
		}
	}
}

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