4use \Bitrix\Landing\Internals\RightsTable;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Main\UserAccessTable;
36 'unexportable' =>
'unexportable',
37 'knowledge_menu24' =>
'knowledge_menu24',
38 'knowledge_admin' =>
'knowledge_admin',
39 'knowledge_create' =>
'knowledge_create',
40 'knowledge_unexportable' =>
'knowledge_unexportable',
41 'knowledge_extension' =>
'knowledge_extension',
42 'group_create' =>
'group_create',
43 'group_admin' =>
'group_admin',
44 'group_menu24' =>
'group_menu24',
45 'group_unexportable' =>
'group_unexportable',
55 'knowledge_unexportable',
89 self::$available =
false;
98 self::$available =
true;
107 self::$globalAvailable =
false;
116 self::$globalAvailable =
true;
126 defined(
'LANDING_DISABLE_RIGHTS') &&
127 LANDING_DISABLE_RIGHTS ===
true
132 if (!self::$globalAvailable)
136 return self::$available;
145 if (self::hasAdditionalRight(self::ADDITIONAL_RIGHTS[
'admin'],
null,
false,
true))
158 return self::$allowedSites;
168 self::$userId = $uid;
177 self::$userId =
null;
190 return self::$userId;
214 $res = \CTask::getList(
216 [
'MODULE_ID' =>
'landing']
218 while ($row = $res->fetch())
220 $row[
'NAME'] = mb_substr($row[
'NAME'], 14);
221 $tasks[$row[
'ID']] = $row;
238 foreach (self::getAccessTasks() as $accessTask)
240 $tasks[$accessTask[
'NAME']] = $accessTask[
'ID'];
255 if (self::isFeatureOn())
257 $res = RightsTable::getList([
262 'ENTITY_ID' => $entityId,
263 '=ENTITY_TYPE' => $entityType
266 while ($row = $res->fetch())
268 RightsTable::delete($row[
'ID']);
282 self::ENTITY_TYPE_SITE
293 protected static function getData($entityId, $entityType, array $preDefined = [])
295 static $access =
null;
299 if ($access ===
null)
301 $access = new \CAccess;
306 'ENTITY_ID' => $entityId,
307 '=ENTITY_TYPE' => $entityType
311 $filter[
'=ACCESS_CODE'] = array_keys($preDefined);
315 $res = RightsTable::getList([
322 while ($row = $res->fetch())
324 $codes[] = $row[
'ACCESS_CODE'];
325 if (!isset($items[$row[
'ACCESS_CODE']]))
327 $row[
'TASK_ID'] = [$row[
'TASK_ID']];
328 $items[$row[
'ACCESS_CODE']] = $row;
332 $items[$row[
'ACCESS_CODE']][
'TASK_ID'][] = $row[
'TASK_ID'];
334 if (isset($preDefined[$row[
'ACCESS_CODE']]))
336 unset($preDefined[$row[
'ACCESS_CODE']]);
340 $items = array_values($items);
343 foreach ($preDefined as $accessCode => $rightCode)
346 'TASK_ID' => $rightCode,
347 'ACCESS_CODE' => $accessCode
349 $codes[] = $accessCode;
355 $codesNames = $access->getNames($codes);
356 foreach ($items as &$item)
358 if (isset($codesNames[$item[
'ACCESS_CODE']]))
360 $item[
'ACCESS_PROVIDER'] = (
361 isset($codesNames[$item[
'ACCESS_CODE']][
'provider']) &&
362 $codesNames[$item[
'ACCESS_CODE']][
'provider']
364 ? $codesNames[$item[
'ACCESS_CODE']][
'provider']
366 $item[
'ACCESS_NAME'] = isset($codesNames[$item[
'ACCESS_CODE']][
'name'])
367 ? $codesNames[$item[
'ACCESS_CODE']][
'name']
368 : $item[
'ACCESS_CODE'];
385 return self::getData(
387 self::ENTITY_TYPE_SITE,
402 $entityType == self::ENTITY_TYPE_SITE &&
403 in_array($entityId, self::$allowedSites)
406 $types = self::ACCESS_TYPES;
407 unset($types[self::ACCESS_TYPES[
'delete']]);
408 return array_values($types);
413 $entityType == self::ENTITY_TYPE_SITE
414 && !is_array($entityId) && $entityId > 0
417 $scopeOperationsSite = Site\Type::getOperationsForSite($entityId);
418 if ($scopeOperationsSite !==
null)
420 return array_values($scopeOperationsSite);
425 $operationsDefault = [];
427 $uid = self::getContextUserId();
428 $extendedMode = self::isExtendedMode();
435 self::isFeatureOn() &&
440 $entityIdFilter = $entityId;
441 if (is_array($entityIdFilter))
443 $entityIdFilter[] = 0;
452 'ENTITY_ID' => $entityIdFilter,
453 '=ENTITY_TYPE' => $entityType,
454 'USER_ACCESS.USER_ID' => $uid,
455 '!TASK_OPERATION.OPERATION.NAME' => false
459 $filter[
'ROLE_ID'] = 0;
465 $res = RightsTable::getList(
469 'OPERATION_NAME' =>
'TASK_OPERATION.OPERATION.NAME'
474 while ($row = $res->fetch())
476 if ($row[
'ENTITY_ID'] == 0)
478 $operationsDefault[] = mb_substr($row[
'OPERATION_NAME'], 8);
481 if (!isset($operations[$row[
'ENTITY_ID']]))
483 $operations[$row[
'ENTITY_ID']] = array();
485 $operations[$row[
'ENTITY_ID']][] = mb_substr($row[
'OPERATION_NAME'], 8);
486 $operations[$row[
'ENTITY_ID']] = array_unique($operations[$row[
'ENTITY_ID']]);
491 foreach ((array) $entityId as $id)
493 if (!isset($operations[$id]))
495 if ($wasChecked && !$extendedMode)
497 $operations[$id] = !empty($operationsDefault)
499 : [self::ACCESS_TYPES[
'denied']];
503 $operations[$id] = array_values(self::ACCESS_TYPES);
508 return is_array($entityId)
510 : $operations[$entityId];
523 Site::ping($siteId,
true)
526 return self::getOperations(
528 self::ENTITY_TYPE_SITE
546 static $operations = [];
547 $siteId = intval($siteId);
549 if (!is_string($accessType))
554 if (!isset($operations[$siteId]))
556 if ($siteId === 0 || !self::isOn() || Site::ping($siteId, $deleted))
558 $operations[$siteId] = self::getOperations(
560 self::ENTITY_TYPE_SITE
565 $operations[$siteId] = [];
569 return in_array($accessType, $operations[$siteId]);
580 static $operations = [];
581 $landingId = intval($landingId);
583 if (!is_string($accessType))
588 if (!isset($operations[$landingId]))
596 '=SITE.DELETED' => [
'Y',
'N'],
597 '=DELETED' => [
'Y',
'N']
603 $operations[$landingId] = self::getOperations(
605 self::ENTITY_TYPE_SITE
610 $operations[$landingId] = [];
614 return in_array($accessType, $operations[$landingId]);
624 protected static function setOperations($entityId, $entityType, array $rights = [])
626 if (!self::isFeatureOn())
631 $tasks = self::getAccessTasksReferences();
632 $entityId = intval($entityId);
640 foreach ($rights as $accessCode => $rightCodes)
642 $rightCodes = (array) $rightCodes;
643 if (in_array(self::ACCESS_TYPES[
'denied'], $rightCodes))
645 $rightCodes = [self::ACCESS_TYPES[
'denied']];
647 else if (!in_array(self::ACCESS_TYPES[
'read'], $rightCodes))
649 $rightCodes[] = self::ACCESS_TYPES[
'read'];
652 foreach ($rightCodes as $rightCode)
654 if (isset($tasks[$rightCode]))
657 'ENTITY_ID' => $entityId,
658 'ENTITY_TYPE' => $entityType,
659 'TASK_ID' => $tasks[$rightCode],
660 'ACCESS_CODE' => $accessCode
677 $siteId = intval($siteId);
679 if ($siteId == 0 || Site::ping($siteId))
681 return self::setOperations(
683 self::ENTITY_TYPE_SITE,
699 static $exist =
null;
703 $type = Site\Type::getCurrentScopeId();
704 $res = RightsTable::getList([
709 ? [
'=ROLE.TYPE' => $type]
713 $exist = (bool) $res->fetch();
731 self::isFeatureOn() &&
735 $tasks = self::getAccessTasksReferences();
736 $extendedRights = self::isExtendedMode();
737 $uid = self::getContextUserId();
745 'RIGHTS.USER_ACCESS.USER_ID' => $uid
748 '=RIGHTS.TASK_ID' => null
755 if ($additionalFilterOr)
761 'RIGHTS.USER_ACCESS.USER_ID' => $uid
768 $filter[
'RIGHTS.USER_ACCESS.USER_ID'] = $uid;
799 if (self::isFeatureOn())
802 $current = ($current ==
'Y') ?
'N' :
'Y';
814 if (!self::isFeatureOn())
820 foreach (self::ADDITIONAL_RIGHTS as $right)
822 $rights[$right] = [];
826 $res = Role::getList([
828 'ID',
'ACCESS_CODES',
'ADDITIONAL_RIGHTS'
831 while ($row = $res->fetch())
833 $row[
'ACCESS_CODES'] = (array) $row[
'ACCESS_CODES'];
834 $row[
'ADDITIONAL_RIGHTS'] = (array) $row[
'ADDITIONAL_RIGHTS'];
835 foreach ($row[
'ADDITIONAL_RIGHTS'] as $right)
837 if (isset($rights[$right]))
839 $rights[$right][$row[
'ID']] = $row[
'ACCESS_CODES'];
845 foreach ($rights as $code => $right)
849 $option = unserialize($option, [
'allowed_classes' =>
false]);
850 if (isset($option[0]))
852 $right[0] = $option[0];
857 isset($additionalRights[$code]) &&
858 is_array($additionalRights[$code])
861 foreach ($additionalRights[$code] as $i => $accCodes)
863 $right[$i] = (array) $accCodes;
879 \CBitrixComponent::clearComponentCache(
894 if (!is_string($code))
898 self::refreshAdditionalRights([
912 static $access =
null;
915 if (!is_string($code))
919 if ($access ===
null)
921 $access = new \CAccess;
925 $option = unserialize($option, [
'allowed_classes' =>
false]);
926 $accessCodes = isset($option[0]) ? (array)$option[0] : [];
927 $codesNames = $access->getNames($accessCodes);
929 foreach ($accessCodes as $code)
931 if (isset($codesNames[$code]))
934 isset($codesNames[$code][
'provider']) &&
935 $codesNames[$code][
'provider']
937 ? $codesNames[$code][
'provider']
939 $name = isset($codesNames[$code][
'name'])
940 ? $codesNames[$code][
'name']
944 'PROVIDER' => $provider,
961 $type = Site\Type::getCurrentScopeId();
963 foreach (self::ADDITIONAL_RIGHTS as $right)
965 if (mb_strpos($right,
'_') > 0)
967 [$prefix, ] = explode(
'_', $right);
968 $prefix = mb_strtoupper($prefix);
969 if ($prefix != $type)
974 else if ($type !==
null)
978 $rights[$right] =
Loc::getMessage(
'LANDING_RIGHTS_R_'.mb_strtoupper($right));
991 if (\
Bitrix\Main\Loader::includeModule(
'crm'))
993 $access = new \CCrmPerms(self::getContextUserId());
994 if (!$access->havePerm(
'WEBFORM', BX_CRM_PERM_NONE,
'WRITE'))
997 $res = Site::getList([
1002 'CODE' =>
'/' .
Site\Type::PSEUDO_SCOPE_CODE_FORMS .
'%',
1004 'CHECK_PERMISSIONS' =>
'N'
1007 while ($row = $res->fetch())
1009 self::$allowedSites[] = $row[
'ID'];
1025 public static function hasAdditionalRight($code, $type =
null,
bool $checkExtraRights =
false,
bool $strict =
false)
1027 static $options = [];
1029 if ($checkExtraRights && self::hasExtraRights())
1034 if (!is_string($code))
1040 $type = Site\Type::getCurrentScopeId();
1045 $type = mb_strtolower($type);
1047 if ($type ==
Site\Type::SCOPE_CODE_GROUP)
1051 $code = $type .
'_' . $code;
1054 if (array_key_exists($code, self::ADDITIONAL_RIGHTS))
1056 if (!self::isFeatureOn())
1061 if (!self::getContextUserId())
1068 if (in_array($code, self::REVERSE_RIGHTS))
1076 if (!isset($options[$code]))
1079 $options[$code] = unserialize($options[$code], [
'allowed_classes' =>
false]);
1081 $option = $options[$code];
1083 if (!is_array($option) && !$strict)
1093 if (self::isExtendedMode())
1095 if (isset($option[0]) && is_array($option[0]))
1097 $accessCodes = $option[0];
1102 if (isset($option[0]))
1106 foreach ($option as $roleAccess)
1108 $accessCodes = array_merge($accessCodes, (array)$roleAccess);
1110 $accessCodes = array_unique($accessCodes);
1115 static $accessCodesStatic = [];
1118 $accessCodesStr = implode(
'|', $accessCodes);
1120 if (array_key_exists($accessCodesStr, $accessCodesStatic))
1122 return $accessCodesStatic[$accessCodesStr];
1125 $res = UserAccessTable::getList([
1130 '=ACCESS_CODE' => $accessCodes,
1131 'USER_ID' => self::getContextUserId()
1134 $accessCodesStatic[$accessCodesStr] = (boolean)$res->fetch();
1135 return $accessCodesStatic[$accessCodesStr];
static getOption($code, $default=null)
const FEATURE_PERMISSIONS_AVAILABLE
static setOption($code, $value)
static checkFeature(string $feature, array $params=array())
static hasAccessForLanding($landingId, $accessType)
static setAdditionalRightExtended($code, array $accessCodes=[])
static setOperationsForSite($siteId, array $rights=[])
static removeDataForSite($siteId)
static setContextUserId(int $uid)
static getOperations($entityId, $entityType)
static setOperations($entityId, $entityType, array $rights=[])
static removeData($entityId, $entityType)
static getAccessFilter(array $additionalFilterOr=[])
static getAccessTasksReferences()
static getDataForSite($siteId, array $preDefined=[])
static getOperationsForSite($siteId)
static getAdditionalRightExtended($code)
static clearContextUserId()
static getAdditionalRightsLabels()
static getData($entityId, $entityType, array $preDefined=[])
static hasAdditionalRight($code, $type=null, bool $checkExtraRights=false, bool $strict=false)
static hasAccessForSite($siteId, $accessType, $deleted=false)
static refreshAdditionalRights(array $additionalRights=[])
static getContextUserId()
static getExpectedRoleIds()
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getList(array $parameters=array())