Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messageaccess.php
1<?php
2
3namespace Bitrix\Mail\Helper;
4
8
13{
14 public static function createToken($mailBoxId, $messageId, $entityType, $entityId, $ufId = '0'): string
15 {
16 return md5(sprintf(
17 '%u:%u:%u:%s:%s:%u', // '%u:%u:%u:%s:%s:%u'
18 time(),
19 $mailBoxId,
20 $messageId,
21 $entityType,
22 $ufId,
23 $entityId
24 ));
25 }
26
27 public static function createSecret(): string
28 {
29 return bin2hex(\Bitrix\Main\Security\Random::getBytes(16));
30 }
31
32 public static function isMailboxOwner(int $mailboxId, int $userId): bool
33 {
34 return Message::isMailboxOwner($mailboxId, $userId);
35 }
36
37 public static function isMessageOwner(\Bitrix\Mail\Item\Message $message, $userId): bool
38 {
39 return \Bitrix\Mail\MessageAccess::createForMessage($message, $userId)->isOwner();
40 }
41
42 public static function checkAccessForChat(int $chatId, int $userId): bool
43 {
44 if (Main\Loader::includeModule('im'))
45 {
46 $data = \CIMChat::GetChatData(['ID' => $chatId]);
47 $userInChat = $data['userInChat'][$chatId] ?? [];
48 if (in_array($userId, $userInChat, true))
49 {
50 return true;
51 }
52 }
53
54 return false;
55 }
56
57 public static function checkAccessForCalendarEvent(int $calendarEventId, int $userId): bool
58 {
59 if (Main\Loader::includeModule('calendar'))
60 {
61 $attendeeIds = [];
62 $entry = \CCalendarEvent::getEventForViewInterface($calendarEventId);
63
64 if ($entry && isset($entry['ATTENDEE_LIST']))
65 {
66 foreach($entry['ATTENDEE_LIST'] as $attendee)
67 {
68 $attendeeId = (int)$attendee['id'];
69 if ($attendeeId > 0)
70 {
71 $attendeeIds[] = $attendeeId;
72 }
73 }
74 }
75
76 if (in_array($userId, $attendeeIds, true))
77 {
78 return true;
79 }
80 }
81
82 return false;
83 }
84}
static isMessageOwner(\Bitrix\Mail\Item\Message $message, $userId)
static isMailboxOwner(int $mailboxId, int $userId)
static checkAccessForChat(int $chatId, int $userId)
static createToken($mailBoxId, $messageId, $entityType, $entityId, $ufId='0')
static checkAccessForCalendarEvent(int $calendarEventId, int $userId)