Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
right.php
1<?php
3
9
10class Right implements Errorable
11{
13
14 const ACCESS_DENIED = 'ACCESS_DENIED';
15
16 private $entityRight;
17 private $rightParam;
18
19 private $listsPermission;
20
21 public function __construct(RightParam $rightParam, RightEntity $entityRight)
22 {
23 $this->entityRight = $entityRight;
24 $this->rightParam = $rightParam;
25
26 $this->listsPermission = $this->getListsPermission();
27
28 $this->entityRight->setListsPermission($this->listsPermission);
29
30 $this->errorCollection = new ErrorCollection;
31 }
32
40 public function checkPermission($entityMethod = '')
41 {
42 if ($this->listsPermission < 0)
43 {
44 switch ($this->listsPermission)
45 {
46 case \CListPermissions::WRONG_IBLOCK_TYPE:
47 $this->errorCollection->setError(
48 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_WRONG_IBLOCK_TYPE')),
49 self::ACCESS_DENIED
50 );
51 break;
52 case \CListPermissions::WRONG_IBLOCK:
53 $this->errorCollection->setError(
54 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_WRONG_IBLOCK')),
55 self::ACCESS_DENIED
56 );
57 break;
58 case \CListPermissions::LISTS_FOR_SONET_GROUP_DISABLED:
59 $this->errorCollection->setError(
60 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_SONET_GROUP_DISABLED'),
61 self::ACCESS_DENIED)
62 );
63 break;
64 default:
65 $this->errorCollection->setError(
66 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_ACCESS_DENIED'),
67 self::ACCESS_DENIED)
68 );
69 break;
70 }
71 }
72
73 if ($entityMethod)
74 {
75 if (method_exists($this->entityRight, $entityMethod))
76 {
77 if (!$this->entityRight->$entityMethod())
78 {
79 $this->errorCollection->setError(
80 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_ACCESS_DENIED'),
81 self::ACCESS_DENIED)
82 );
83 }
84 }
85 else
86 {
87 $this->errorCollection->setError(
88 new Error(Loc::getMessage('LISTS_LIB_SECURITY_RIGHT_ERROR_ACCESS_DENIED'),
89 self::ACCESS_DENIED)
90 );
91 }
92 }
93
94 if ($this->hasErrors())
95 {
96 return false;
97 }
98
99 return true;
100 }
101
102 private function getListsPermission()
103 {
104 return \CListPermissions::checkAccess(
105 $this->rightParam->getUser(),
106 $this->rightParam->getIblockTypeId(),
107 $this->rightParam->getIblockId(),
108 $this->rightParam->getSocnetGroupId()
109 );
110 }
111
112 public function getPermission(): int|string
113 {
114 return $this->listsPermission;
115 }
116}
__construct(RightParam $rightParam, RightEntity $entityRight)
Definition right.php:21
checkPermission($entityMethod='')
Definition right.php:40
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29