Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BaseRule.php
1<?php
2
4
11
13{
14 /* @var AccessController $controller */
15 /* @var UserModel $user */
16
24 public function execute(AccessibleItem $item = null, $params = null): bool
25 {
26 if ($this->controller->isAdmin())
27 {
28 return true;
29 }
30
31 if (!Feature::isAccessControllerCheckingEnabled())
32 {
33 $userDepartments = $this->user->getUserDepartments();
34
35 if (empty($userDepartments))
36 {
37 return false;
38 }
39
40 return count($userDepartments) > 1 || $userDepartments[0] !== 0;
41 }
42
43 if (!$params)
44 {
45 return false;
46 }
47
48 $params['item'] = $item;
49
50 return $this->check($params);
51 }
52
53 public function getPermissionValue($params): ?int
54 {
55 if (!Feature::isAccessControllerCheckingEnabled())
56 {
57 return 1;
58 }
59
60 $permissionCode = static::getPermissionCode($params);
61
62 if (!$permissionCode)
63 {
64 return null;
65 }
66
67 return $this->user->getPermission($permissionCode);
68 }
69
73 protected function check($params): bool
74 {
75 return (bool)$this->getPermissionValue($params);
76 }
77
82 protected static function getPermissionCode(array $params): ?string
83 {
84 $permissionCode = ActionDictionary::getActionPermissionMap()[$params['action']];
85
86 if (!$permissionCode)
87 {
88 return null;
89 }
90
91 return (string)$permissionCode;
92 }
93}
execute(AccessibleItem $item=null, $params=null)
Definition BaseRule.php:24
static getPermissionCode(array $params)
Definition BaseRule.php:82