Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PermissionConfig.php
1<?php
3
15
16Loc::loadMessages(__FILE__);
17
19{
20 public const SECTION_CATALOG = 'SECTION_CATALOG';
21 public const SECTION_CATALOG_SETTINGS = 'SECTION_CATALOG_SETTINGS';
22 public const SECTION_INVENTORY_MANAGMENT = 'SECTION_INVENTORY_MANAGMENT';
23 public const SECTION_SETTINGS = 'SECTION_SETTINGS';
24 public const SECTION_RESERVATION = 'SECTION_RESERVATION';
25 public const SECTION_STORE_DOCUMENT_ARRIVAL = 'SECTION_STORE_DOCUMENT_ARRIVAL';
26 public const SECTION_STORE_DOCUMENT_STORE_ADJUSTMENT = 'SECTION_STORE_DOCUMENT_STORE_ADJUSTMENT';
27 public const SECTION_STORE_DOCUMENT_MOVING = 'SECTION_STORE_DOCUMENT_MOVING';
28 public const SECTION_STORE_DOCUMENT_DEDUCT = 'SECTION_STORE_DOCUMENT_DEDUCT';
29 public const SECTION_STORE_DOCUMENT_SALES_ORDER = 'SECTION_STORE_DOCUMENT_SALES_ORDER';
30
36 public function getAccessRights(): array
37 {
39 {
40 return $this->getAccessRightsWithInventoryManagement();
41 }
42
43 return $this->getAccessRightsGeneral();
44 }
45
51 private function getAccessRightsWithInventoryManagement(): array
52 {
53 $res = [];
54
55 $sections = $this->getSections(true);
56 $storeDocumentsMap = $this->getStoreDocumentSectionCodesMap();
57 foreach ($sections as $sectionName => $permissions)
58 {
59 $isStoreSectionName = isset($storeDocumentsMap[$sectionName]);
60 $rights = [];
61 foreach ($permissions as $permissionId)
62 {
63 if ($isStoreSectionName)
64 {
65 [$permissionId, $documentId] = explode('_', $permissionId);
66 $rights[] = PermissionDictionary::getStoreDocumentPermission($permissionId, $documentId);
67 }
68 else
69 {
70 $rights[] = PermissionDictionary::getPermission($permissionId);
71 }
72 }
73
74 $res[] = [
75 'sectionCode' => $sectionName,
76 'sectionTitle' => Loc::getMessage('CATALOG_CONFIG_PERMISSIONS_' . $sectionName) ?? $sectionName,
77 'sectionHint' => Loc::getMessage('HINT_CATALOG_CONFIG_PERMISSIONS_' . $sectionName),
78 'rights' => $rights
79 ];
80 }
81
82 $res = $this->appendArticleLinks($res);
83
84 return $res;
85 }
86
94 private function appendArticleLinks(array $res): array
95 {
96 $articles = new PermissionArticles();
97
98 foreach ($res as $i => $info)
99 {
100 if (isset($info['sectionHint']))
101 {
102 $articleLink = $articles->getSectionArticleLink($info['sectionCode']);
103 if ($articleLink)
104 {
105 $res[$i]['sectionHint'] .= " {$articleLink}";
106 }
107 }
108
109 foreach ($info['rights'] as $z => $right)
110 {
111 $permissionId = $right['id'];
112
113 if (isset($right['hint']))
114 {
115 $articleLink = $articles->getPermissionArticleLink($permissionId);
116 if ($articleLink)
117 {
118 $res[$i]['rights'][$z]['hint'] .= " {$articleLink}";
119 }
120 }
121 }
122 }
123
124 return $res;
125 }
126
132 private function getAccessRightsGeneral(): array
133 {
134 $res = [];
135
136 $sections = $this->getSections(false);
137 foreach ($sections as $sectionName => $permissions)
138 {
139 $rights = [];
140 foreach ($permissions as $permissionId)
141 {
142 $rights[] = PermissionDictionary::getPermission($permissionId);
143 }
144
145 $res[] = [
146 'sectionTitle' => Loc::getMessage('CATALOG_CONFIG_PERMISSIONS_' . $sectionName) ?? $sectionName,
147 'rights' => $rights
148 ];
149 }
150
151 return $res;
152 }
153
159 public function getUserGroups(): array
160 {
161 $list = RoleUtil::getRoles();
162
163 $members = $this->getRoleMembersMap();
164 $accessRights = $this->getRoleAccessRightsMap();
165
166 $roles = [];
167 foreach ($list as $row)
168 {
169 $roleId = (int) $row['ID'];
170
171 $roles[] = [
172 'id' => $roleId,
173 'title' => RoleDictionary::getRoleName($row['NAME']),
174 'accessRights' => $accessRights[$roleId] ?? [],
175 'members' => $members[$roleId] ?? [],
176 ];
177 }
178
179 return $roles;
180 }
181
189 private function getSections(bool $withInventoryManagmentSections): array
190 {
191 $sections = [
192 self::SECTION_CATALOG => $this->getCommonCatalogSection(),
193 ];
194
195 if ($withInventoryManagmentSections)
196 {
197 $sections[self::SECTION_INVENTORY_MANAGMENT] = [
198 PermissionDictionary::CATALOG_INVENTORY_MANAGEMENT_ACCESS,
199 PermissionDictionary::CATALOG_STORE_MODIFY,
200 PermissionDictionary::CATALOG_STORE_VIEW,
201 ];
202
203 if (Loader::includeModule('report'))
204 {
205 $sections[self::SECTION_INVENTORY_MANAGMENT][] = PermissionDictionary::CATALOG_STORE_ANALYTIC_VIEW;
206 }
207 $sections[self::SECTION_INVENTORY_MANAGMENT][] = PermissionDictionary::CATALOG_SETTINGS_STORE_DOCUMENT_CARD_EDIT;
208
209 foreach ($this->getStoreDocumentSectionCodesMap() as $code => $typeId)
210 {
211 $sections[$code] = $this->getStoreDocumentsSectionPermissions($typeId);
212 }
213
214 $reservationSection = $this->getReservationSection();
215 if ($reservationSection)
216 {
217 $sections[self::SECTION_RESERVATION] = $reservationSection;
218 }
219 }
220
221 $sections[self::SECTION_CATALOG_SETTINGS] = $this->getCatalogSettingsSection();
222 $sections[self::SECTION_SETTINGS] = [
223 PermissionDictionary::CATALOG_SETTINGS_ACCESS,
224 PermissionDictionary::CATALOG_SETTINGS_EDIT_RIGHTS,
225 PermissionDictionary::CATALOG_SETTINGS_SELL_NEGATIVE_COMMODITIES,
226 ];
227
228 if ($withInventoryManagmentSections)
229 {
230 $sections[self::SECTION_RESERVATION][] = PermissionDictionary::CATALOG_RESERVE_SETTINGS;
231 }
232
233 return $sections;
234 }
235
236 private function getReservationSection(): array
237 {
238 $result = [];
239
240 if (Loader::includeModule('crm'))
241 {
242 $result[] = PermissionDictionary::CATALOG_RESERVE_DEAL;
243 }
244
245 // TODO: now - not used, maybe in future.
246 //$result[] = PermissionDictionary::CATALOG_STORE_RESERVE;
247
248 return $result;
249 }
250
251 private function getCommonCatalogSection(): array
252 {
253 $result = [
254 PermissionDictionary::CATALOG_PRODUCT_READ,
255 PermissionDictionary::CATALOG_PRODUCT_PURCHASING_PRICE_VIEW,
256 PermissionDictionary::CATALOG_PRODUCT_ADD,
257 PermissionDictionary::CATALOG_PRODUCT_EDIT,
258 PermissionDictionary::CATALOG_PRODUCT_DELETE,
259 PermissionDictionary::CATALOG_PRODUCT_EDIT_CATALOG_PRICE,
260 PermissionDictionary::CATALOG_PRODUCT_EDIT_ENTITY_PRICE,
261 PermissionDictionary::CATALOG_PRODUCT_SET_DISCOUNT,
262 ];
263
264 if (Loader::includeModule('bitrix24'))
265 {
266 $result[] = PermissionDictionary::CATALOG_PRODUCT_PUBLIC_VISIBILITY;
267 }
268
269 $result[] = PermissionDictionary::CATALOG_IMPORT_EXECUTION;
270 $result[] = PermissionDictionary::CATALOG_EXPORT_EXECUTION;
271
272 return $result;
273 }
274
275 private function getCatalogSettingsSection(): array
276 {
277 $result = [
278 PermissionDictionary::CATALOG_SETTINGS_PRODUCT_CARD_EDIT,
279 PermissionDictionary::CATALOG_SETTINGS_PRODUCT_CARD_SET_PROFILE_FOR_USERS,
280 PermissionDictionary::CATALOG_VAT_MODIFY,
281 PermissionDictionary::CATALOG_MEASURE_MODIFY,
282 PermissionDictionary::CATALOG_PRICE_GROUP_MODIFY,
283 PermissionDictionary::CATALOG_PRODUCT_PRICE_EXTRA_EDIT,
284 ];
285
286 $onlyBox = !ModuleManager::isModuleInstalled('bitrix24');
287 if ($onlyBox)
288 {
289 array_push($result, ...[
290 PermissionDictionary::CATALOG_IMPORT_EDIT,
291 PermissionDictionary::CATALOG_EXPORT_EDIT,
292 ]);
293 }
294
295 return $result;
296 }
297
298 private function getStoreDocumentSectionCodesMap(): array
299 {
300 return [
301 self::SECTION_STORE_DOCUMENT_ARRIVAL => StoreDocumentTable::TYPE_ARRIVAL,
302 self::SECTION_STORE_DOCUMENT_STORE_ADJUSTMENT => StoreDocumentTable::TYPE_STORE_ADJUSTMENT,
303 self::SECTION_STORE_DOCUMENT_MOVING => StoreDocumentTable::TYPE_MOVING,
304 self::SECTION_STORE_DOCUMENT_DEDUCT => StoreDocumentTable::TYPE_DEDUCT,
305 self::SECTION_STORE_DOCUMENT_SALES_ORDER => StoreDocumentTable::TYPE_SALES_ORDERS,
306 ];
307 }
308
316 private function getStoreDocumentsSectionPermissions(string $typeId): array
317 {
318 $permissions = [
319 PermissionDictionary::CATALOG_STORE_DOCUMENT_VIEW,
320 PermissionDictionary::CATALOG_STORE_DOCUMENT_MODIFY,
321 PermissionDictionary::CATALOG_STORE_DOCUMENT_CONDUCT,
322 PermissionDictionary::CATALOG_STORE_DOCUMENT_CANCEL,
323 PermissionDictionary::CATALOG_STORE_DOCUMENT_DELETE,
324 ];
325
326 $typesWithNag = [
329 //StoreDocumentTable::TYPE_SALES_ORDERS,
330 ];
331 if (in_array($typeId, $typesWithNag, true) && !State::isProductBatchMethodSelected())
332 {
333 $permissions[] = PermissionDictionary::CATALOG_STORE_DOCUMENT_ALLOW_NEGATION_PRODUCT_QUANTITY;
334 }
335
336 $result = [];
337 foreach ($permissions as $permission)
338 {
339 $result[] = "{$permission}_{$typeId}";
340 }
341
342 return $result;
343 }
344
350 private function getRoleMembersMap(): array
351 {
352 return (new RoleMembersInfo)->getMemberInfos();
353 }
354
360 private function getRoleAccessRightsMap(): array
361 {
362 $result = [];
363
364 $rows = PermissionTable::getList([
365 'select' => [
366 'ROLE_ID',
367 'PERMISSION_ID',
368 'VALUE',
369 ],
370 ]);
371 foreach ($rows as $row)
372 {
373 $roleId = $row['ROLE_ID'];
374
375 $result[$roleId][] = [
376 'id' => $row['PERMISSION_ID'],
377 'value' => $row['VALUE']
378 ];
379 }
380
381 return $result;
382 }
383
389 public function getInventoryManagementPermissions(): array
390 {
391 $result = [];
392
393 $sections = $this->getSections(false);
394 $sectionsWithInventoryManagment = $this->getSections(true);
395
396 foreach ($sectionsWithInventoryManagment as $code => $permissions)
397 {
398 $generalPermissions = $sections[$code] ?? null;
399 if (!isset($generalPermissions))
400 {
401 array_push($result, ... $permissions);
402 continue;
403 }
404
405
406 foreach ($permissions as $permissionId)
407 {
408 if (!in_array($permissionId, $generalPermissions, true))
409 {
410 $result[] = $permissionId;
411 }
412 }
413 }
414
415 return $result;
416 }
417}
static isUsedInventoryManagement()
Definition state.php:40
static isProductBatchMethodSelected()
Definition state.php:909
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29