34 'getUsersAccessibility' => [
36 ActionFilter\Authentication::class,
37 ActionFilter\Csrf::class
40 new ActionFilter\Cors()
45 ActionFilter\Authentication::class,
46 ActionFilter\Csrf::class
49 new ActionFilter\Cors()
54 ActionFilter\Authentication::class,
55 ActionFilter\Csrf::class
58 new ActionFilter\Cors()
63 ActionFilter\Authentication::class,
64 ActionFilter\Csrf::class
67 new ActionFilter\Cors()
72 ActionFilter\Authentication::class,
73 ActionFilter\Csrf::class
76 new ActionFilter\Cors()
79 'getConferenceLink' => [
81 ActionFilter\Authentication::class,
82 ActionFilter\Csrf::class
85 new ActionFilter\Cors()
88 'getIcsFileContent' => [
90 ActionFilter\Authentication::class,
91 ActionFilter\Csrf::class
94 new ActionFilter\Cors()
97 'handleTimelineNotify' => [
99 ActionFilter\Authentication::class,
100 ActionFilter\Csrf::class
103 new ActionFilter\Cors()
111 Sharing\Helper::disableOptionPayAttentionToNewSharingFeature();
116 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
122 $result = $sharing->enable();
123 if (!$result->isSuccess())
129 return $sharing->getLinkInfo();
134 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
140 $result = $sharing->disable();
141 if (!$result->isSuccess())
152 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
158 $result = $sharing->deactivateUserLink($hash);
159 if (!$result->isSuccess())
171 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
177 $result = $sharing->increaseFrequentUse($hash);
178 if (!$result->isSuccess())
190 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
195 $userId = \CCalendar::GetCurUserId();
196 $result = (
new Sharing\Sharing($userId))->generateUserJointLink($memberIds);
197 if (!$result->isSuccess())
204 return $result->getData();
209 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
214 $userId = \CCalendar::GetCurUserId();
218 'pathToUser' => Option::get(
'intranet',
'path_user',
'/company/personal/user/#USER_ID#/',
'-'),
226 $userIds =
$request->getPost(
'userIds');
227 $fromTs =
$request->getPost(
'timestampFrom') / 1000;
228 $toTs =
$request->getPost(
'timestampTo') / 1000;
230 if (!is_array($userIds) || !$fromTs || !$toTs)
236 'userIds' => array_map(
'intval', $userIds),
237 'timestampFrom' => $fromTs,
238 'timestampTo' => $toTs
239 ]))->getUsersAccessibilitySegmentsInUtc();
249 public function saveEventAction(): array
252 $sqlHelper = $connection->getSqlHelper();
257 $userName = $sqlHelper->forSql(trim(
$request[
'userName'] ??
''));
258 $userContact = $sqlHelper->forSql(trim(
$request[
'userContact'] ??
''));
259 $parentLinkHash = $sqlHelper->forSql(trim(
$request[
'parentLinkHash'] ??
''));
260 $ownerId = (int)(
$request[
'ownerId'] ??
null);
261 $ownerCreated = (
$request[
'ownerCreated'] ??
null) ===
'true';
263 $contactDataError = !Sharing\SharingEventManager::validateContactData($userContact);
264 $contactNameError = !Sharing\SharingEventManager::validateContactName($userName);
265 if ($contactDataError || $contactNameError)
270 'contactDataError' => $contactDataError,
271 'contactNameError' => $contactNameError,
276 $link = Link\Factory::getInstance()->getLinkByHash($parentLinkHash);
280 || !$link->isActive()
281 || $link->getObjectType() !== Sharing\Link\Helper::USER_SHARING_TYPE
282 || $link->getObjectId() !== $ownerId
292 'CONTACT_DATA' => $userContact,
311 $eventData = Sharing\SharingEventManager::getEventDataFromRequest(
$request);
312 $eventData[
'eventName'] = Sharing\SharingEventManager::getSharingEventNameByUserName($userName);
314 $event = Sharing\SharingEventManager::prepareEventForSave($eventData, $userId, $link);
316 $sharingEventManager =
new Sharing\SharingEventManager($event, $userId, $ownerId, $link);
317 $eventCreateResult = $sharingEventManager->createEvent(
false, $userParams[
'NAME']);
319 if ($errors = $eventCreateResult->getErrors())
327 $event = $eventCreateResult->getData()[
'event'];
329 $eventLink = $eventCreateResult->getData()[
'eventLink'];
331 Sharing\Analytics::getInstance()->sendMeetingCreated($link);
334 $this->autoAcceptSharingEvent($event->getId(), $ownerId);
335 foreach ($link->getMembers() as $member)
337 $this->autoAcceptSharingEvent($event->getId(), $member->getId());
341 $event = (
new Mappers\Factory())->getEvent()->getById($event->getId());
343 $notificationService =
null;
344 if (SharingEventManager::isEmailCorrect($userContact))
346 $notificationService = (
new Sharing\Notification\Mail())
347 ->setEventLink($eventLink)
352 $notificationService?->notifyAboutMeetingCreated($userContact);
355 'eventId' => $event->getId(),
356 'eventName' => $event->getName(),
357 'eventLinkId' => $eventLink->getId(),
358 'eventLinkHash' => $eventLink->getHash(),
359 'eventLinkShortUrl' => Sharing\Helper::getShortUrl($eventLink->getUrl()),
363 public function saveCrmEventAction(): array
368 if (!Loader::includeModule(
'crm'))
376 $sqlHelper = $connection->getSqlHelper();
379 $crmDealLinkHash = $sqlHelper->forSql(trim(
$request[
'crmDealLinkHash'] ??
''));
380 $ownerId = (int)(
$request[
'ownerId'] ??
null);
381 $ownerCreated = (
$request[
'ownerCreated'] ??
null) ===
'true';
384 $crmDealLink = Link\Factory::getInstance()->getLinkByHash($crmDealLinkHash);
388 || !$crmDealLink->isActive()
389 || $crmDealLink->getObjectType() !== Sharing\Link\Helper::CRM_DEAL_SHARING_TYPE
390 || $crmDealLink->getOwnerId() !== $ownerId
398 if (!$crmDealLink->getContactId()|| !$crmDealLink->getContactType())
400 $userName = $sqlHelper->forSql(trim(
$request[
'userName'] ??
''));
401 $userContact = $sqlHelper->forSql(trim(
$request[
'userContact'] ??
''));
403 $contactDataError = !Sharing\SharingEventManager::validateContactData($userContact);
404 $contactNameError = !Sharing\SharingEventManager::validateContactName($userName);
405 if ($contactDataError || $contactNameError)
410 'contactDataError' => $contactDataError,
411 'contactNameError' => $contactNameError,
417 $contactType = $crmDealLink->getContactType();
418 $contactId = $crmDealLink->getContactId();
419 $contactData = \Bitrix\Crm\Service\Container::getInstance()
420 ->getEntityBroker($contactType)
421 ->getById($contactId)
431 if ($contactType === \CCrmOwnerType::Contact)
433 $userName = $contactData->getFullName();
435 elseif ($contactType === \CCrmOwnerType::Company)
437 $userName = $contactData->getTitle();
444 'CONTACT_DATA' => $userContact,
455 $eventData = Sharing\SharingEventManager::getCrmEventDataFromRequest(
$request);
456 $eventData[
'eventName'] = Sharing\SharingEventManager::getSharingEventNameByUserName($userName);
458 $event = Sharing\SharingEventManager::prepareEventForSave($eventData, $userId, $crmDealLink);
460 $sharingEventManager =
new Sharing\SharingEventManager($event, $userId, $ownerId, $crmDealLink);
461 $eventCreateResult = $sharingEventManager->createEvent(
false, $userParams[
'NAME']);
463 if ($errors = $eventCreateResult->getErrors())
471 $event = $eventCreateResult->getData()[
'event'];
473 $eventLink = $eventCreateResult->getData()[
'eventLink'];
475 Sharing\Analytics::getInstance()->sendMeetingCreated($crmDealLink);
477 $dateFrom =
$request[
'dateFrom'] ??
null;
478 $timezone =
$request[
'timezone'] ??
null;
484 $crmDealLink->setLastStatus(
null);
485 (
new Sharing\Link\CrmDealLinkMapper())->update($crmDealLink);
488 (
new Sharing\Crm\ActivityManager($event->getId(), $crmDealLink, $userName))
489 ->createCalendarSharingActivity($activityName, $event->getDescription(), $eventStart)
493 $this->autoAcceptSharingEvent($event->getId(), $ownerId);
494 foreach ($crmDealLink->getMembers() as $member)
496 $this->autoAcceptSharingEvent($event->getId(), $member->getId());
500 if ($crmDealLink->getContactId() > 0)
502 Crm\Integration\Calendar\Notification\Manager::getSenderInstance($crmDealLink)
503 ->setCrmDealLink($crmDealLink)
505 ->setEventLink($eventLink)
506 ->sendCrmSharingAutoAccepted()
511 (
new Sharing\Notification\Mail())
512 ->setEventLink($eventLink)
514 ->notifyAboutMeetingCreated($userContact)
519 'eventId' => $event->getId(),
520 'eventName' => $event->getName(),
521 'eventLinkId' => $eventLink->getId(),
522 'eventLinkHash' => $eventLink->getHash(),
523 'eventLinkShortUrl' => Sharing\Helper::getShortUrl($eventLink->getUrl()),
532 public function deleteEventAction(): array
536 $eventId = (int)
$request[
'eventId'];
540 $eventLink = Link\Factory::getInstance()->getLinkByHash($eventLinkHash);
543 || !$eventLink->isActive()
544 || $eventLink->getObjectType() !== Sharing\Link\Helper::EVENT_SHARING_TYPE
553 $event = (
new Mappers\Event())->getById($eventId);
561 if ($event->getId() !== $eventLink->getEventId())
568 $sharingEventManager =
new Sharing\SharingEventManager($event, $eventLink->getHostId(), $eventLink->getOwnerId());
569 $eventDeleteResult = $sharingEventManager->deleteEvent();
571 if ($eventDeleteResult->getErrors())
577 $sharingEventManager->deactivateEventLink($eventLink);
588 $cookieName =
'CALENDAR_SHARING_FIRST_PAGE_VISITED';
589 $cookie =
new Cookie($cookieName,
'Y',
null,
false);
597 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
604 $saveResult = \Bitrix\Calendar\Sharing\Link\Rule\Helper::getInstance()->saveLinkRule($linkHash, $ruleArray);
608 $this->
addError(
new Error(
'Error while trying to save rule'));
614 private function currentUserIsNotResponsible(
Sharing\
Link\
Link $link): bool
616 if (!Loader::includeModule(
'crm'))
621 if (!($link instanceof Sharing\Link\CrmDealLink))
626 $currentUserId = (
new Crm\Service\Context())->getUserId();
628 return $this->getAssignedId($link) !== $currentUserId;
631 private function getAssignedId(Sharing\Link\CrmDealLink $link): ?int
633 $entityBroker = Crm\Service\Container::getInstance()->getEntityBroker(\CCrmOwnerType::Deal);
639 $entity = $entityBroker->getById($link->getEntityId());
645 return $entity->getAssignedById();
657 public function getConferenceLinkAction(
string $eventLinkHash): array
663 $eventLink = Link\Factory::getInstance()->getLinkByHash($eventLinkHash);
664 if (!$eventLink || !$eventLink->isActive() || $eventLink->getObjectType() !== Sharing\Link\Helper::EVENT_SHARING_TYPE)
671 $conferenceLink = (
new Sharing\SharingConference($eventLink))->getConferenceLink();
673 if (!$conferenceLink)
675 $this->
addError(
new Error(
'Error while creating conference link'));
680 $result[
'conferenceLink'] = $conferenceLink;
688 public function getIcsFileContentAction(
string $eventLinkHash): string
694 $eventLink = Link\Factory::getInstance()->getLinkByHash($eventLinkHash);
697 || !$eventLink->isActive()
698 || $eventLink->getObjectType() !== Sharing\Link\Helper::EVENT_SHARING_TYPE
707 $event = (
new Mappers\Event())->getById($eventLink->getEventId());
716 $event->setName(SharingEventManager::getSharingEventNameByUserId($eventLink->getOwnerId()));
718 'eventUrl' => Sharing\Helper::getShortUrl($eventLink->getUrl()),
719 'conferenceUrl' => Sharing\Helper::getShortUrl($eventLink->getUrl() . Sharing\Helper::ACTION_CONFERENCE),
723 public function getDeletedSharedEventAction(
int $entryId): array
725 if (Loader::includeModule(
'intranet') && !\
Bitrix\Intranet\Util::isIntranetUser())
730 $event = \CCalendar::getDeletedSharedEvent($entryId);
732 if (is_array($event))
735 $eventId = $entryId === $event[
'ID'] ? $entryId : $event[
'PARENT_ID'];
736 $link = (
new Sharing\Link\Factory())->getDeletedEventLinkByEventId($eventId);
740 'canceledTimestamp' => $link->getCanceledTimestamp(),
741 'externalUserName' => $link->getExternalUserName(),
742 'externalUserId' => $link->getHostId(),
749 'link' => $linkArray,
750 'userTimezone' => $this->getUserTimezoneName(),
754 public function handleTimelineNotifyAction(): array
758 if (!Loader::includeModule(
'crm'))
766 $sqlHelper = $connection->getSqlHelper();
768 $linkHash = $sqlHelper->forSql(trim(
$request[
'linkHash'] ??
''));
769 $entityType = $sqlHelper->forSql(trim(
$request[
'entityType'] ??
''));
770 $notifyType = $sqlHelper->forSql(trim(
$request[
'notifyType']) ??
'');
771 $entityId = (int)(
$request[
'entityId'] ??
null);
772 $dateFrom =
$request[
'dateFrom'] ??
null;
773 $timezone =
$request[
'timezone'] ??
null;
777 $link = Link\Factory::getInstance()->getLinkByHash($linkHash);
780 || !$link->isActive()
781 || $link->getObjectId() !== $entityId
782 || $link->getObjectType() !== $entityType
790 if (in_array($notifyType, Sharing\Crm\NotifyManager::NOTIFY_TYPES,
true))
792 (
new Sharing\Crm\NotifyManager($link, $notifyType))
795 $link->setLastStatus($notifyType);
796 (
new Sharing\Link\CrmDealLinkMapper())->update($link);
804 $value = $collapsed ===
'Y' ?
'Y' :
'N';
805 \CUserOptions::SetOption(
'calendar',
'sharingSettingsCollapsed', $value);
808 private function getUserTimezoneName(): string
810 $userId = \CCalendar::GetCurUserId();
812 return \CCalendar::getUserTimezoneName($userId);
815 private function autoAcceptSharingEvent(
int $eventId,
int $userId)
817 \CCalendarEvent::SetMeetingStatus([
818 'eventId' => $eventId,
821 'sharingAutoAccept' =>
true,