Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
elementright.php
1<?php
2
4
9
11{
13
14 const ACCESS_DENIED = "ACCESS_DENIED";
15
16 const ADD = "canAdd";
17 const READ = "canRead";
18 const EDIT = "canEdit";
19 const DELETE = "canDelete";
20 const FULL_EDIT = "canFullEdit";
21 public const EDIT_RIGHTS = 'canEditRights';
22
23 private $listsPermission;
24 private $rightParam;
25 private $socnetGroupClosed = false;
26
27 public function __construct(RightParam $rightParam)
28 {
29 $this->rightParam = $rightParam;
30
31 $this->socnetGroupClosed = $this->rightParam->getClosedStatusSocnetGroup();
32
33 $this->errorCollection = new ErrorCollection;
34 }
35
41 public function setListsPermission($listsPermission)
42 {
43 $this->listsPermission = $listsPermission;
44 }
45
51 public function canRead()
52 {
53 if (
54 (
55 $this->rightParam->getEntityId() &&
56 $this->listsPermission < \CListPermissions::CAN_READ &&
57 !\CIBlockElementRights::userHasRightTo(
58 $this->rightParam->getIblockId(), $this->rightParam->getEntityId(), "element_read")
59 ) ||
60 (
61 !$this->rightParam->getEntityId() &&
62 $this->listsPermission < \CListPermissions::CAN_READ &&
63 !\CIBlockSectionRights::userHasRightTo(
64 $this->rightParam->getIblockId(), $this->rightParam->getEntityId(), "element_read")
65 )
66 )
67 {
68 $this->errorCollection->setError(new Error("Access denied", self::ACCESS_DENIED));
69 return false;
70 }
71 return true;
72 }
73
79 public function canEdit()
80 {
81 $sectionId = $this->rightParam->getSectionId() ?? $this->rightParam->getEntityId(); // compatibility
82
83 $canEdit = (
84 !$this->socnetGroupClosed && ((
85 $this->rightParam->getEntityId() > 0 &&
86 (
87 $this->listsPermission >= \CListPermissions::CAN_WRITE ||
88 \CIBlockElementRights::UserHasRightTo(
89 $this->rightParam->getIblockId(), $this->rightParam->getEntityId(), 'element_edit')
90 )
91 )
92 || (
93 $this->rightParam->getEntityId() == 0
94 && (
95 $this->listsPermission >= \CListPermissions::CAN_WRITE ||
96 \CIBlockSectionRights::UserHasRightTo(
97 $this->rightParam->getIblockId(), $sectionId, 'section_element_bind')
98 )
99 ))
100 );
101
102 if ($canEdit)
103 {
104 return true;
105 }
106 else
107 {
108 $this->errorCollection->setError(new Error("Access denied", self::ACCESS_DENIED));
109 return false;
110 }
111 }
112
118 public function canAdd()
119 {
120 $sectionId = $this->rightParam->getSectionId() ?? $this->rightParam->getEntityId(); // compatibility
121
122 $canAdd = (
123 !$this->socnetGroupClosed &&
124 (
125 $this->listsPermission > \CListPermissions::CAN_READ
126 || \CIBlockSectionRights::UserHasRightTo(
127 $this->rightParam->getIblockId(), $sectionId, 'section_element_bind'
128 )
129 )
130 );
131
132 if ($canAdd)
133 {
134 return true;
135 }
136 else
137 {
138 $this->errorCollection->setError(new Error('Access denied', self::ACCESS_DENIED));
139
140 return false;
141 }
142 }
143
149 public function canDelete()
150 {
151 $canDelete = (
152 !$this->socnetGroupClosed
153 && $this->rightParam->getEntityId()
154 && (
155 $this->listsPermission >= \CListPermissions::CAN_WRITE
156 || \CIBlockElementRights::UserHasRightTo(
157 $this->rightParam->getIblockId(), $this->rightParam->getEntityId(), 'element_delete'
158 )
159 )
160 );
161
162 if ($canDelete)
163 {
164 return true;
165 }
166 else
167 {
168 $this->errorCollection->setError(new Error("Access denied", self::ACCESS_DENIED));
169 return false;
170 }
171 }
172
178 public function canFullEdit()
179 {
180 $canFullEdit = (
181 !$this->socnetGroupClosed
182 && (
183 $this->listsPermission >= \CListPermissions::IS_ADMIN
184 || \CIBlockRights::UserHasRightTo(
185 $this->rightParam->getIblockId(), $this->rightParam->getIblockId(), 'iblock_edit'
186 )
187 )
188 );
189
190 if ($canFullEdit)
191 {
192 return true;
193 }
194 else
195 {
196 $this->errorCollection->setError(new Error("Access denied", self::ACCESS_DENIED));
197 return false;
198 }
199 }
200
204 public function canEditRights()
205 {
206 $canEditRights = (
207 !$this->socnetGroupClosed
208 && (
209 (
210 $this->rightParam->getEntityId() > 0
211 && \CIBlockElementRights::UserHasRightTo(
212 $this->rightParam->getIblockId(),
213 $this->rightParam->getEntityId(),
214 'element_rights_edit'
215 )
216 )
217 || (
218 $this->rightParam->getEntityId() === 0
219 && \CIBlockSectionRights::UserHasRightTo(
220 $this->rightParam->getIblockId(),
221 $this->rightParam->getSectionId() ?? 0,
222 'element_rights_edit'
223 )
224 )
225 )
226 );
227
228 if ($canEditRights)
229 {
230 return true;
231 }
232
233 $this->errorCollection->setError(new Error('Access denied', self::ACCESS_DENIED));
234
235 return false;
236 }
237}
__construct(RightParam $rightParam)