1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UserBot.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Entity\User;
4
5use Bitrix\Im\Integration\Socialnetwork\Extranet;
6use Bitrix\Im\V2\Chat\ChatError;
7use Bitrix\Im\V2\Entity\User\Data\BotData;
8use Bitrix\Im\V2\Result;
9use Bitrix\Imbot\Bot\CopilotChatBot;
10use Bitrix\Main\Loader;
11
12class UserBot extends User
13{
14 private ?BotData $botData = null;
15
16 protected function fillOnlineData(bool $withStatus = false): void
17 {
18 return;
19 }
20
21 public function isOnlineDataFilled(bool $withStatus): bool
22 {
23 return true;
24 }
25
26 protected function checkAccessInternal(User $otherUser): Result
27 {
28 $result = new Result();
29
30 if (!static::$moduleManager::isModuleInstalled('intranet'))
31 {
32 if (!$this->hasAccessBySocialNetwork($otherUser->getId()))
33 {
35 }
36
37 return $result;
38 }
39
40 if (Loader::includeModule('imbot') && $this->getBotData()->getCode() === CopilotChatBot::BOT_CODE)
41 {
42 return $result->addError(new ChatError(ChatError::ACCESS_DENIED));
43 }
44
45 global $USER;
46 if ($otherUser->isExtranet())
47 {
48 if ($otherUser->getId() === $USER->GetID())
49 {
50 if ($USER->IsAdmin())
51 {
52 return $result;
53 }
54
55 if (static::$loader::includeModule('bitrix24'))
56 {
57 if (\CBitrix24::IsPortalAdmin($otherUser->getId()) || \Bitrix\Bitrix24\Integrator::isIntegrator($otherUser->getId()))
58 {
59 return $result;
60 }
61 }
62 }
63
64 $inGroup = Extranet::isUserInGroup(
65 $this->getId(),
66 $otherUser->getId(),
67 false
68 );
69
70 if ($inGroup)
71 {
72 return $result;
73 }
74
75
76 return $result->addError(new ChatError(ChatError::ACCESS_DENIED));
77 }
78
79 return $result;
80 }
81
82 public function toRestFormat(array $option = []): array
83 {
84 $userData = parent::toRestFormat($option);
85
86 if (isset($userData['botData']))
87 {
88 return $userData;
89 }
90
91 $botData = $this->getBotData()->toRestFormat();
92 $userData['botData'] = empty($botData) ? null : $botData;
93
94 return $userData;
95 }
96
97 public function getBotData(): BotData
98 {
99 if ($this->botData !== null)
100 {
101 return $this->botData;
102 }
103
104 return BotData::getInstance($this->getId());
105 }
106
107 public function getType(): UserType
108 {
109 return UserType::BOT;
110 }
111}
static isUserInGroup($userId, $currentUserId=null, bool $filterActiveUser=true)
Определения extranet.php:112
const ACCESS_DENIED
Определения ChatError.php:19
static getInstance(?int $id)
Определения BotData.php:34
toRestFormat(array $option=[])
Определения UserBot.php:82
isOnlineDataFilled(bool $withStatus)
Определения UserBot.php:21
checkAccessInternal(User $otherUser)
Определения UserBot.php:26
fillOnlineData(bool $withStatus=false)
Определения UserBot.php:16
hasAccessBySocialNetwork(int $idOtherUser)
Определения User.php:241
array $userData
Определения User.php:61
isExtranet()
Определения User.php:531
Определения result.php:20
getCode()
Определения entity.php:804
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $USER
Определения csv_new_run.php:40
$option
Определения options.php:1711