1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AccessController.php
См. документацию.
1<?php
8
10
13use Bitrix\Catalog\Access\Install\AccessInstaller\InstallStatus;
27
29{
31
35 public function __construct(int $userId)
36 {
37 parent::__construct($userId);
38
39 $this->ruleFactory = new CatalogRuleFactory();
40 $this->iblockRuleFactory = new IblockRuleFactory();
41 $this->filterFactory = new CatalogFilterFactory();
42 }
43
44 public static function getCurrent(): self
45 {
46 global $USER;
47
48 $userId = 0;
49 if (isset($USER) && $USER instanceof \CUser)
50 {
51 $userId = (int)$USER->GetID();
52 }
53
54 return static::getInstance($userId);
55 }
56
66 public function check(string $action, AccessibleItem $item = null, $params = null): bool
67 {
68 if (!ModuleManager::isModuleInstalled('crm') || InstallStatus::inProgress())
69 {
70 return $this->checkLegacy($action);
71 }
72
73 if (
75 && State::isExternalCatalog()
76 )
77 {
78 return true;
79 }
80
81 $params ??= [];
82 if (is_array($params))
83 {
84 $params['action'] = $action;
85 }
86
87 return parent::check($action, $item, $params);
88 }
89
90 public function checkByValue(string $action, string $value): bool
91 {
92 return $this->check(
93 $action,
94 null,
95 ['value' => $value]
96 );
97 }
98
103 public function getPermissionValue(string $action)
104 {
105 $ruleObject = $this->ruleFactory->createFromAction($action, $this);
106 if (! $ruleObject instanceof BaseRule)
107 {
108 return null;
109 }
110
111 $params = ['action' => $action];
112
113 return
114 $ruleObject instanceof VariableRule
115 ? $ruleObject->getPermissionMultiValues($params)
116 : $ruleObject->getPermissionValue($params)
117 ;
118 }
119
125 private function checkLegacy(string $action): bool
126 {
127 if (CurrentUser::get()->isAdmin())
128 {
129 return true;
130 }
131
132 $legacyActions = ActionDictionary::getLegacyMap();
133 $legacyAction = null;
134 if (array_key_exists($action, $legacyActions))
135 {
136 $legacyAction = $action;
137 }
138 else
139 {
140 foreach ($legacyActions as $oldAction => $newActions)
141 {
142 if (in_array($action, $newActions, true))
143 {
144 $legacyAction = $oldAction;
145
146 break;
147 }
148 }
149 }
150
151 return $legacyAction && CurrentUser::get()->canDoOperation($legacyAction);
152 }
153
154 public function isAdmin()
155 {
156 return $this->user->isAdmin() || (Loader::includeModule("bitrix24") && \CBitrix24::isPortalAdmin($this->user->getUserId()));
157 }
158
159 protected function loadItem(int $itemId = null): ?AccessibleItem
160 {
161 return null;
162 }
163
164 protected function loadUser(int $userId): UserModel
165 {
167 }
168
176 public function getAllowedDefaultStoreId(): ?int
177 {
178 $allowStoresIds = $this->getPermissionValue(ActionDictionary::ACTION_STORE_VIEW) ?? [];
179 if (empty($allowStoresIds))
180 {
181 return null;
182 }
183 $allowStoresIds = array_map('intval', $allowStoresIds);
184
185 $defaultStoreId = StoreTable::getDefaultStoreId();
186 if ($defaultStoreId)
187 {
188 $allStoresId = PermissionDictionary::VALUE_VARIATION_ALL;
189 if (
190 in_array($defaultStoreId, $allowStoresIds, true)
191 || in_array($allStoresId, $allowStoresIds, true)
192 )
193 {
194 return $defaultStoreId;
195 }
196 }
197
198 return reset($allowStoresIds);
199 }
200
205 public function hasIblockAccess(string $action): bool
206 {
208 $rule = $this->iblockRuleFactory->createFromAction($action, $this);
209 if (!$rule)
210 {
212 }
213
214 return $rule->execute();
215 }
216
223 public function checkCompleteRight(string $action): bool
224 {
225 $permissionValue = $this->getPermissionValue($action);
226
227 if ($permissionValue === null)
228 {
229 return false;
230 }
231
232 if (is_array($permissionValue))
233 {
234 return in_array(PermissionDictionary::VALUE_VARIATION_ALL, $permissionValue, true);
235 }
236
237 return $this->check($action);
238 }
239}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getPermissionValue(string $action)
Определения AccessController.php:103
loadItem(int $itemId=null)
Определения AccessController.php:159
checkByValue(string $action, string $value)
Определения AccessController.php:90
IblockRuleFactory $iblockRuleFactory
Определения AccessController.php:30
checkCompleteRight(string $action)
Определения AccessController.php:223
check(string $action, AccessibleItem $item=null, $params=null)
Определения AccessController.php:66
getPermissionMultiValues($params)
Определения VariableRule.php:24
static getDefaultStoreId()
Определения store.php:402
static get()
Определения currentuser.php:33
Определения loader.php:13
Определения user.php:6037
global $USER
Определения csv_new_run.php:40
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$action
Определения file_dialog.php:21