Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
CheckChatOwner.php
1<?php
2
4
10
11class CheckChatOwner extends Base
12{
13 public function onBeforeAction(Event $event)
14 {
15 $currentUser = $this->getAction()->getCurrentUser();
16 $currentUserId = (int)(isset($currentUser) ? $currentUser->getId() : null);
17
18 if ($this->getAction()->getName() === 'setOwner' || $this->getAction()->getName() === 'setowner')
19 {
20
21 $arguments = $this->getAction()->getArguments();
25 $chat = $arguments['chat'];
26
27 if (!isset($arguments['ownerId']))
28 {
29 $this->addError(new Error(
30 'Parameter ownerId is required',
32 ));
33 return new EventResult(EventResult::ERROR, null, null, $this);
34 }
35
36 if ($chat->getAuthorId() === $currentUserId)
37 {
38 return null;
39 }
40
41 $manageSettings = $chat->getManageSettings();
42 if ($manageSettings === Chat::MANAGE_RIGHTS_MANAGERS)
43 {
44 $selfRelation = $chat->getSelfRelation();
45 if ($selfRelation->getManager())
46 {
47 return null;
48 }
49 }
50 }
51
52 $this->addError(new Error(
54 ));
55 return new EventResult(EventResult::ERROR, null, null, $this);
56 }
57}
const MANAGE_RIGHTS_MANAGERS
Definition Chat.php:135