Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
AccessService.php
1<?php
2
4
8
10{
12 {
13 return $this->hasUserMinIBlockTypePermission();
14 }
15
17 {
18 return $this->hasUserMinIBlockTypePermission();
19 }
20
22 {
23 $response = new CheckPermissionsResponse();
24
25 $checkPermissionsResponse = $this->checkIBlockPermission($iBlockId, IblockRight::READ);
26 $response->fillFromResponse($checkPermissionsResponse);
27
28 return $response;
29 }
30
31 public function canUserReadElement(int $elementId, int $sectionId = 0): CheckPermissionsResponse
32 {
33 $response = new CheckPermissionsResponse();
34
35 $checkPermissionsResponse = $this->checkElementPermission($elementId, $sectionId);
36 $response->fillFromResponse($checkPermissionsResponse);
37
38 if ($response->isSuccess())
39 {
40 $elementRight = $checkPermissionsResponse->getElementRight();
41
42 if (
43 ($elementId === 0 && !$elementRight?->canAdd())
44 || ($elementId !== 0 && !$elementRight?->canRead())
45 )
46 {
47 $response->addError(self::getAccessDeniedError());
48 }
49 }
50
51 return $response;
52 }
53
54 public function canUserAddElement(int $sectionId, int $iBlockId): CheckPermissionsResponse
55 {
56 $response = new CheckPermissionsResponse();
57
58 $checkPermissionResponse = $this->checkElementPermission(0, $sectionId, ElementRight::ADD, $iBlockId);
59 $response->fillFromResponse($checkPermissionResponse);
60
61 return $response;
62 }
63
64 private function hasUserMinIBlockTypePermission(): CheckPermissionsResponse
65 {
66 $response = new CheckPermissionsResponse();
67
68 $checkPermissionResult = $this->checkIBlockTypePermission();
69 $permission = $checkPermissionResult->getPermission();
70
71 $response
72 ->setPermission($permission)
73 ->addErrors($checkPermissionResult->getErrors())
74 ;
75
76 if ($response->isSuccess() && $this->isAccessDeniedPermission($permission))
77 {
78 $response->addError(self::getAccessDeniedError());
79 }
80
81 return $response;
82 }
83}
checkIBlockPermission(int $iBlockId=null, string $entityMethod=null)
checkIBlockTypePermission(string $iBlockTypeId=null)
checkElementPermission(int $elementId=0, int $sectionId=0, string $entityMethod=null, int $iBlockId=null,)
canUserReadElement(int $elementId, int $sectionId=0)