1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CheckActionAccess.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Controller\Filter;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Permission;
7use Bitrix\Im\V2\Permission\Action;
8use Bitrix\Im\V2\Permission\GlobalAction;
9use Bitrix\Main\Engine\ActionFilter\Base;
10use Bitrix\Main\Event;
11use Bitrix\Main\EventResult;
12
14{
15 private Action|GlobalAction $actionToDo;
19 private ?\Closure $targetGetter;
20
25 public function __construct(Action|GlobalAction $action, ?\Closure $targetGetter = null)
26 {
27 parent::__construct();
28 $this->actionToDo = $action;
29 $this->targetGetter = $targetGetter;
30 }
31
32 public function onBeforeAction(Event $event)
33 {
34 $targetGetter = $this->targetGetter;
35 $target = $targetGetter ? $targetGetter($this) : null;
36
37 if ($this->actionToDo instanceof GlobalAction)
38 {
39 return $this->canDoGlobalAction($this->actionToDo, $target);
40 }
41
42 return $this->canDoAction($this->actionToDo, $target);
43 }
44
45 private function canDoAction(Action $action, mixed $target): ?EventResult
46 {
47 $chat = $this->getChat();
48 if (!$chat instanceof Chat)
49 {
51
52 return new EventResult(EventResult::ERROR, null, null, $this);
53 }
54
55 if (!$chat->canDo($action, $target))
56 {
58
59 return new EventResult(EventResult::ERROR, null, null, $this);
60 }
61
62 return null;
63 }
64
65 private function canDoGlobalAction(GlobalAction $action, mixed $target): ?EventResult
66 {
67 $userId = (int)$this->getAction()->getCurrentUser()?->getId();
68 if (!Permission::canDoGlobalAction($userId, $action, $target))
69 {
71
72 return new EventResult(EventResult::ERROR, null, null, $this);
73 }
74
75 return null;
76 }
77
78 private function getChat(): ?Chat
79 {
80 $arguments = $this->getAction()->getArguments();
81
82 return $arguments['chat'] ?? $arguments['message']?->getChat() ?? $arguments['messages']?->getCommonChat() ?? null;
83 }
84}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const ACCESS_DENIED
Определения ChatError.php:19
const NOT_FOUND
Определения ChatError.php:20
__construct(Action|GlobalAction $action, ?\Closure $targetGetter=null)
Определения CheckActionAccess.php:25
addError(Error $error)
Определения base.php:80
$event
Определения prolog_after.php:141
$action
Определения file_dialog.php:21