4use \Bitrix\Main\Localization\Loc;
5use \Bitrix\Landing\Internals\RightsTable;
37 'knowledge_unexportable',
38 'knowledge_extension',
47 'knowledge_unexportable'
56 $type = Site\Type::getCurrentScopeId();
68 while ($role = $res->fetch())
73 $resRight = RightsTable::getList([
79 'TASK_ID' => [$taskReadId, $taskDenyId],
80 'ROLE_ID' => $role[
'ID'],
84 if (!$resRight->fetch())
89 'TASK_ID' => $taskReadId,
90 'ROLE_ID' => $role[
'ID'],
101 $keyDemoInstalled =
'role_demo_installed';
104 $keyDemoInstalled .=
'_' . mb_strtolower($type);
116 static $roles =
null;
118 $type = Site\Type::getCurrentScopeId();
127 $access = new \CAccess;
138 while ($row = $res->fetch())
140 if (!trim($row[
'TITLE']))
144 $row[
'ACCESS_CODES'] = !$row[
'ACCESS_CODES'] ? [] : (array)$row[
'ACCESS_CODES'];
145 $roles[$row[
'ID']] = $row;
146 $codes = array_merge($codes, $row[
'ACCESS_CODES']);
152 $codesNames = $access->getNames($codes);
153 foreach ($roles as &$role)
155 foreach ($role[
'ACCESS_CODES'] as &$code)
158 isset($codesNames[$code][
'provider']) &&
159 $codesNames[$code][
'provider']
161 ? $codesNames[$code][
'provider']
163 $name = isset($codesNames[$code][
'name'])
164 ? $codesNames[$code][
'name']
168 'PROVIDER' => $provider,
178 $keyDemoInstalled =
'role_demo_installed';
181 $keyDemoInstalled .=
'_'.mb_strtolower($type);
189 self::installDemo($type);
191 return self::fetchAll();
212 $res = \Bitrix\Main\GroupTable::getList([
217 '=STRING_ID' =>
'EMPLOYEES_' . SITE_ID
220 if ($row = $res->fetch())
222 $defGroup =
'G' . $row[
'ID'];
230 if (mb_strpos($accessCode,
'_') > 0)
232 [$prefix, ] = explode(
'_', $accessCode);
233 $prefix = mb_strtoupper($prefix);
234 if ($prefix == $type)
236 $addRights[] = $accessCode;
239 else if ($type ===
null)
241 $addRights[] = $accessCode;
245 $addRightsManager = $addRights;
246 foreach (self::$forbiddenManagerRights as $rightCode)
248 $key = array_search($rightCode, $addRightsManager,
true);
251 array_splice($addRightsManager, $key, 1);
254 $addRightsAdmin = $addRights;
255 foreach (self::$forbiddenAdminRights as $rightCode)
257 $key = array_search($rightCode, $addRightsAdmin,
true);
260 array_splice($addRightsAdmin, $key, 1);
273 'additional_rights' => $addRightsAdmin,
284 'additional_rights' => $addRightsManager,
288 $type = (string)$type;
289 foreach ($demoData as $code => $rights)
291 $code = mb_strtoupper($code);
303 'ADDITIONAL_RIGHTS' => $rights[
'additional_rights']
305 if ($res->isSuccess())
309 [0 => $rights[
'rights']]
311 if ($rights[
'access'])
323 unset($demoData, $defGroup, $code, $rights);
343 $roleId = intval($roleId);
345 self::update($roleId, [
346 'ACCESS_CODES' => $codes
351 self::getRights($roleId)
365 $tasks = array_flip($tasks);
366 $roleId = intval($roleId);
369 $res = RightsTable::getlist([
375 'ROLE_ID' => $roleId,
379 while ($row = $res->fetch())
381 if (!isset($tasks[$row[
'TASK_ID']]))
385 if (!isset($return[$row[
'ENTITY_ID']]))
387 $return[$row[
'ENTITY_ID']] = [];
389 $right = $tasks[$row[
'TASK_ID']];
390 if (!in_array($right, $return[$row[
'ENTITY_ID']]))
392 $return[$row[
'ENTITY_ID']][] = $right;
406 public static function setRights($roleId, $rights = [], $additionalRights =
null)
415 $rights = (array) $rights;
417 $roleId = intval($roleId);
421 $setAdditionalRights =
function() use($roleId, $additionalRights)
424 if ($additionalRights !==
null)
426 if (!is_array($additionalRights))
428 $additionalRights = [];
430 self::update($roleId, [
431 'ADDITIONAL_RIGHTS' => $additionalRights
446 if ($row = $res->fetch())
448 $accessCodes = $row[
'ACCESS_CODES'];
451 $accessCodes = [
'G1'];
456 $setAdditionalRights();
461 $res = RightsTable::getlist([
466 'ROLE_ID' => $roleId,
470 while ($row = $res->fetch())
472 RightsTable::delete($row[
'ID']);
477 $setAdditionalRights();
487 'filter' => array_keys($rights)
489 while ($row = $res->fetch())
491 $siteExists[] = $row[
'ID'];
497 foreach ($rights as $siteId => $rightCodes)
499 if (!is_array($rightCodes))
503 if ($siteId > 0 && !in_array($siteId, $siteExists))
507 if (in_array($deniedCode, $rightCodes))
509 $rightCodes = [$deniedCode];
511 else if (!in_array($readCode, $rightCodes))
513 $rightCodes[] = $readCode;
515 foreach ($rightCodes as $rightCode)
517 if (isset($tasks[$rightCode]))
519 foreach ($accessCodes as $accessCode)
522 'ROLE_ID' => $roleId,
523 'ENTITY_ID' => $siteId,
525 'TASK_ID' => $tasks[$rightCode],
526 'ACCESS_CODE' => $accessCode
533 $setAdditionalRights();
536 "intranet_menu_binding"
547 if (is_string($type) || $type ===
null)
549 self::$expectedType = $type;
559 return self::$expectedType;
578 '=TYPE' => self::$expectedType
581 while ($row = $res->fetch())
static getOption($code, $default=null)
const FEATURE_PERMISSIONS_AVAILABLE
static setOption($code, $value)
static enableFeatureTmp($feature)
static disableFeatureTmp($feature)
static checkFeature(string $feature, array $params=array())
static setRights($id, array $rights, $additional=null)
static setAccessCodes($id, array $codes=array())
static getList(array $params=[], $initiator=null)
static getAccessTasksReferences()
static refreshAdditionalRights(array $additionalRights=[])
static checkRequiredRoles()
static installDemo($type=null)
static setRights($roleId, $rights=[], $additionalRights=null)
static $forbiddenManagerRights
static setAccessCodes($roleId, array $codes=array())
static getExpectedRoleIds()
static getRights($roleId)
static setExpectedType($type)
static $forbiddenAdminRights
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)