snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-18 04:19:15 +05:00
commit 7cc7e6b4f3
10077 changed files with 900756 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting\Invitation;
readonly class Invitee
{
public function __construct(
private string $entityType,
private string $id,
private ?string $emailAddress = null,
) {}
public function getEntityType(): string
{
return $this->entityType;
}
public function getId(): string
{
return $this->id;
}
public function getEmailAddress(): ?string
{
return $this->emailAddress;
}
}

View File

@@ -0,0 +1,286 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting\Invitation;
use Espo\Core\Binding\BindingContainerBuilder;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\InjectableFactory;
use Espo\Core\Mail\Exceptions\SendingError;
use Espo\Core\Mail\SmtpParams;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Log;
use Espo\Core\Utils\Metadata;
use Espo\Entities\User;
use Espo\Modules\Crm\Business\Event\Invitations;
use Espo\Modules\Crm\Entities\Call;
use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Lead;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Repository\RDBRelation;
use Espo\Tools\Email\SendService;
use LogicException;
/**
* @since 9.0.0
*/
class Sender
{
private const string TYPE_INVITATION = 'invitation';
private const string TYPE_CANCELLATION = 'cancellation';
public function __construct(
private SendService $sendService,
private User $user,
private InjectableFactory $injectableFactory,
private EntityManager $entityManager,
private Config $config,
private Metadata $metadata,
private Log $log,
) {}
/**
* @param Meeting|Call $entity
* @param ?Invitee[] $targets
* @return Entity[] Entities an invitation was sent to.
* @throws SendingError
* @throws Forbidden
*/
public function sendInvitation(Meeting|Call $entity, ?array $targets = null): array
{
return $this->sendInternal($entity, self::TYPE_INVITATION, $targets);
}
/**
* @param Meeting|Call $entity
* @param ?Invitee[] $targets
* @return Entity[] Entities an invitation was sent to.
* @throws SendingError
* @throws Forbidden
*/
public function sendCancellation(Meeting|Call $entity, ?array $targets = null): array
{
return $this->sendInternal($entity, self::TYPE_CANCELLATION, $targets);
}
/**
* @param ?Invitee[] $targets
* @return (User|Contact|Lead)[]
*/
private function getRecipients(Meeting|Call $entity, string $type, ?array $targets): array
{
$linkList = [
Meeting::LINK_USERS,
Meeting::LINK_CONTACTS,
Meeting::LINK_LEADS,
];
$output = [];
foreach ($linkList as $link) {
/** @var RDBRelation<User>|RDBRelation<Contact>|RDBRelation<Lead> $builder */
$builder = $this->entityManager->getRelation($entity, $link);
if ($targets === null && $type === self::TYPE_INVITATION) {
$builder->where(['@relation.status=' => Meeting::ATTENDEE_STATUS_NONE]);
}
$collection = $builder->find();
foreach ($collection as $attendee) {
$emailAddress = $attendee->getEmailAddress();
if ($targets) {
$target = self::findTarget($attendee, $targets);
if (!$target) {
continue;
}
if ($target->getEmailAddress()) {
$emailAddress = $target->getEmailAddress();
}
}
if (!$emailAddress) {
continue;
}
$output[] = $attendee;
}
}
return $output;
}
/**
* @param ?Invitee[] $targets
* @return Entity[]
* @throws SendingError
* @throws Forbidden
*/
private function sendInternal(Meeting|Call $entity, string $type, ?array $targets): array
{
$this->checkStatus($entity, $type);
$sender = $this->getSender();
$sentAddressList = [];
$resultEntityList = [];
$recipients = $this->getRecipients($entity, $type, $targets);
foreach ($recipients as $recipient) {
$link = $this->getLinkName($recipient);
$this->entityManager
->getRelation($entity, $link)
->updateColumns($recipient, ['status' => Meeting::ATTENDEE_STATUS_NONE]);
}
foreach ($recipients as $attendee) {
$emailAddress = $attendee->getEmailAddress();
$link = $this->getLinkName($attendee);
if ($targets) {
$target = self::findTarget($attendee, $targets);
if ($target?->getEmailAddress()) {
$emailAddress = $target->getEmailAddress();
}
}
if (!$emailAddress || in_array($emailAddress, $sentAddressList)) {
continue;
}
try {
if ($type === self::TYPE_INVITATION) {
$sender->sendInvitation($entity, $attendee, $link, $emailAddress);
}
if ($type === self::TYPE_CANCELLATION) {
$sender->sendCancellation($entity, $attendee, $link, $emailAddress);
}
} catch (SendingError $e) {
$this->log->error("Could not send event invitation to {entityType} {id}.", [
'exception' => $e,
'entityType' => $attendee->getEntityType(),
'id' => $attendee->getId(),
]);
continue;
}
$sentAddressList[] = $emailAddress;
$resultEntityList[] = $attendee;
}
return $resultEntityList;
}
/**
* @param Invitee[] $targets
*/
private static function findTarget(Entity $entity, array $targets): ?Invitee
{
foreach ($targets as $target) {
if (
$entity->getEntityType() === $target->getEntityType() &&
$entity->getId() === $target->getId()
) {
return $target;
}
}
return null;
}
private function getSender(): Invitations
{
$smtpParams = !$this->config->get('eventInvitationForceSystemSmtp') ?
$this->sendService->getUserSmtpParams($this->user->getId()) :
null;
$builder = BindingContainerBuilder::create();
if ($smtpParams) {
$builder->bindInstance(SmtpParams::class, $smtpParams);
}
return $this->injectableFactory->createWithBinding(Invitations::class, $builder->build());
}
/**
* @throws Forbidden
*/
private function checkStatus(Meeting|Call $entity, string $type): void
{
$entityType = $entity->getEntityType();
if ($type === self::TYPE_CANCELLATION) {
if (!in_array($entity->getStatus(), $this->getCanceledStatusList($entityType))) {
throw new Forbidden("Can't send invitation for not canceled event.");
}
return;
}
$notActualStatusList = [
...($this->metadata->get("scopes.$entityType.completedStatusList") ?? []),
...$this->getCanceledStatusList($entityType),
];
if (in_array($entity->getStatus(), $notActualStatusList)) {
throw new Forbidden("Can't send invitation for not actual event.");
}
}
/**
* @return string[]
*/
private function getCanceledStatusList(string $entityType): array
{
return $this->metadata->get("scopes.$entityType.canceledStatusList") ?? [];
}
private function getLinkName(User|Contact|Lead $recipient): string
{
$linkMap = [
User::ENTITY_TYPE => Meeting::LINK_USERS,
Contact::ENTITY_TYPE => Meeting::LINK_CONTACTS,
Lead::ENTITY_TYPE => Meeting::LINK_LEADS,
];
return $linkMap[$recipient::ENTITY_TYPE] ?? throw new LogicException();
}
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting\Invitation;
use Espo\Core\Binding\BindingContainerBuilder;
use Espo\Core\InjectableFactory;
use Espo\Entities\User;
/**
* @since 9.0.0
*/
class SenderFactory
{
public function __construct(
private InjectableFactory $injectableFactory,
) {}
/**
* Create a sender for a user. The SMTP of the user will be used (if not disabled in the config).
*/
public function createForUser(User $user): Sender
{
return $this->injectableFactory->createWithBinding(
Sender::class,
BindingContainerBuilder::create()
->bindInstance(User::class, $user)
->build()
);
}
}

View File

@@ -0,0 +1,122 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting;
use Espo\Core\Acl;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Mail\Exceptions\SendingError;
use Espo\Core\Record\ServiceContainer as RecordServiceContainer;
use Espo\Modules\Crm\Entities\Call;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\Modules\Crm\Tools\Meeting\Invitation\Sender;
use Espo\Modules\Crm\Tools\Meeting\Invitation\Invitee;
use Espo\ORM\Entity;
class InvitationService
{
private const TYPE_INVITATION = 'invitation';
private const TYPE_CANCELLATION = 'cancellation';
public function __construct(
private RecordServiceContainer $recordServiceContainer,
private Acl $acl,
private Sender $invitationSender,
) {}
/**
* Send invitation emails for a meeting (or call). Checks access. Uses user's SMTP if available.
*
* @param ?Invitee[] $targets
* @return Entity[] Entities an invitation was sent to.
* @throws NotFound
* @throws Forbidden
* @throws Error
* @throws SendingError
*/
public function send(string $entityType, string $id, ?array $targets = null): array
{
return $this->sendInternal($entityType, $id, $targets, self::TYPE_INVITATION);
}
/**
* Send cancellation emails for a meeting (or call). Checks access. Uses user's SMTP if available.
*
* @param ?Invitee[] $targets
* @return Entity[] Entities a cancellation was sent to.
* @throws NotFound
* @throws Forbidden
* @throws Error
* @throws SendingError
*/
public function sendCancellation(string $entityType, string $id, ?array $targets = null): array
{
return $this->sendInternal($entityType, $id, $targets, self::TYPE_CANCELLATION);
}
/**
* @param ?Invitee[] $targets
* @return Entity[]
* @throws NotFound
* @throws Forbidden
* @throws Error
* @throws SendingError
*/
private function sendInternal(
string $entityType,
string $id,
?array $targets,
string $type,
): array {
$entity = $this->recordServiceContainer
->get($entityType)
->getEntity($id);
if (!$entity) {
throw new NotFound();
}
if (!$this->acl->checkEntityEdit($entity)) {
throw new Forbidden("No edit access.");
}
if (!$entity instanceof Meeting && !$entity instanceof Call) {
throw new Error("Not supported entity type.");
}
if ($type === self::TYPE_CANCELLATION) {
return $this->invitationSender->sendCancellation($entity, $targets);
}
return $this->invitationSender->sendInvitation($entity, $targets);
}
}

View File

@@ -0,0 +1,42 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting;
use Espo\Entities\User;
/**
* Checks whether an online meeting can be created.
*
* @since 10.0.0
*/
interface MeetingServiceAvailabilityChecker
{
public function check(User $user): bool;
}

View File

@@ -0,0 +1,54 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Metadata;
use RuntimeException;
class MeetingServiceAvailabilityCheckerFactory
{
public function __construct(
private Metadata $metadata,
private InjectableFactory $injectableFactory,
) {}
public function create(string $name): MeetingServiceAvailabilityChecker
{
/** @var ?class-string<MeetingServiceAvailabilityChecker> $className */
$className = $this->metadata->get("app.meetingServices.$name.availabilityCheckerClassName");
if (!$className) {
throw new RuntimeException("Service '$name' not available.");
}
return $this->injectableFactory->create($className);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting;
use Espo\Core\Utils\Metadata;
use Espo\Entities\User;
use Espo\Tools\App\AppParam;
/**
* @noinspection PhpUnused
*/
class MeetingServicesAppParam implements AppParam
{
public function __construct(
private Metadata $metadata,
private User $user,
private MeetingServiceAvailabilityCheckerFactory $factory,
) {}
/**
* @return array<int, mixed>
*/
public function get(): array
{
$output = [];
/** @var array<string, array<string, mixed>> $services */
$services = $this->metadata->get("app.meetingServices") ?? [];
foreach ($services as $name => $item) {
$enabled = $item['enabled'] ?? false;
if (!$enabled) {
continue;
}
$checker = $this->factory->create($name);
if (!$checker->check($this->user)) {
continue;
}
$output[] = [
'name' => $name
];
}
return $output;
}
}

View File

@@ -0,0 +1,276 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Modules\Crm\Tools\Meeting;
use Espo\Core\Acl;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\HookManager;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\Record\Collection as RecordCollection;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\Modules\Crm\Entities\Call;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Collection;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
use LogicException;
class Service
{
private const string NOTE_TYPE_EVENT_CONFIRMATION = 'EventConfirmation';
public function __construct(
private User $user,
private EntityManager $entityManager,
private HookManager $hookManager,
private Acl $acl,
private Metadata $metadata
) {}
/**
* Set an acceptance for a current user.
*
* @throws BadRequest
* @throws NotFound
* @throws Forbidden
*/
public function setAcceptance(string $entityType, string $id, string $status): void
{
/** @var string[] $statusList */
$statusList = $this->entityManager
->getDefs()
->getEntity($entityType)
->getField('acceptanceStatus')
->getParam('options') ?? [];
if (!in_array($status, $statusList) || $status === Meeting::ATTENDEE_STATUS_NONE) {
throw new BadRequest("Acceptance status not allowed.");
}
$entity = $this->entityManager->getEntityById($entityType, $id);
if (!$entity) {
throw new NotFound();
}
if (!$entity instanceof CoreEntity) {
throw new LogicException();
}
if (!$entity->hasLinkMultipleId(Meeting::LINK_USERS, $this->user->getId())) {
throw new Forbidden();
}
$currentStatus = $this->entityManager
->getRDBRepository($entityType)
->getRelation($entity, Meeting::LINK_USERS)
->getColumn($this->user, 'status');
if ($currentStatus === $status) {
return;
}
$this->entityManager
->getRDBRepository($entityType)
->getRelation($entity, Meeting::LINK_USERS)
->updateColumnsById($this->user->getId(), ['status' => $status]);
if ($this->metadata->get(['scopes', $entityType, 'stream'])) {
$this->createEventConfirmationNote($entity, $status);
}
$actionData = [
'eventName' => $entity->get(Field::NAME),
'eventType' => $entity->getEntityType(),
'eventId' => $entity->getId(),
'dateStart' => $entity->get(Meeting::FIELD_DATE_START),
'status' => $status,
'link' => 'users',
'inviteeType' => User::ENTITY_TYPE,
'inviteeId' => $this->user->getId(),
];
$this->hookManager->process($entityType, 'afterConfirmation', $entity, [], $actionData);
}
private function createEventConfirmationNote(CoreEntity $entity, string $status): void
{
$options = ['createdById' => $this->user->getId()];
$style = $this->metadata
->get(['entityDefs', $entity->getEntityType(), 'fields', 'acceptanceStatus', 'style', $status]);
$this->entityManager->createEntity(Note::ENTITY_TYPE, [
'type' => self::NOTE_TYPE_EVENT_CONFIRMATION,
'parentId' => $entity->getId(),
'parentType' => $entity->getEntityType(),
'relatedId' => $this->user->getId(),
'relatedType' => $this->user->getEntityType(),
'data' => [
'status' => $status,
'style' => $style,
],
], $options);
}
/**
* @param string[] $ids
* @throws Forbidden
*/
public function massSetHeld(string $entityType, array $ids): void
{
if (!$this->acl->checkScope($entityType, Acl\Table::ACTION_EDIT)) {
throw new Forbidden();
}
if (!$this->acl->checkField($entityType, Meeting::FIELD_STATUS, Acl\Table::ACTION_EDIT)) {
throw new Forbidden("No edit access to 'status' field.");
}
foreach ($ids as $id) {
$entity = $this->entityManager->getEntityById($entityType, $id);
if (!$entity || !$this->acl->checkEntityEdit($entity)) {
continue;
}
$entity->set(Meeting::FIELD_STATUS, Meeting::STATUS_HELD);
$this->entityManager->saveEntity($entity);
}
}
/**
* @param string[] $ids
* @throws Forbidden
*/
public function massSetNotHeld(string $entityType, array $ids): void
{
if (!$this->acl->checkScope($entityType, Acl\Table::ACTION_EDIT)) {
throw new Forbidden();
}
if (!$this->acl->checkField($entityType, Meeting::FIELD_STATUS, Acl\Table::ACTION_EDIT)) {
throw new Forbidden("No edit access to 'status' field.");
}
foreach ($ids as $id) {
$entity = $this->entityManager->getEntityById($entityType, $id);
if (!$entity || !$this->acl->checkEntityEdit($entity)) {
continue;
}
$entity->set(Meeting::FIELD_STATUS, Meeting::STATUS_NOT_HELD);
$this->entityManager->saveEntity($entity);
}
}
/**
* Get all attendees.
*
* @throws Forbidden
* @throws NotFound
* @return RecordCollection<Entity>
*/
public function getAttendees(string $entityType, string $id): RecordCollection
{
$entity = $this->entityManager->getEntityById($entityType, $id);
if (!in_array($entityType, [Meeting::ENTITY_TYPE, Call::ENTITY_TYPE])) {
throw new LogicException();
}
if (!$entity) {
throw new NotFound();
}
if (!$this->acl->checkEntityRead($entity)) {
throw new Forbidden();
}
$linkList = [
Meeting::LINK_USERS,
Meeting::LINK_CONTACTS,
Meeting::LINK_LEADS,
];
$linkList = array_filter($linkList, function ($item) use ($entityType) {
return $this->acl->checkField($item, $entityType);
});
$linkList = array_values($linkList);
$list = [];
foreach ($linkList as $link) {
$itemCollection = $this->entityManager
->getRDBRepository($entityType)
->getRelation($entity, $link)
->select([
Attribute::ID,
Field::NAME,
'acceptanceStatus',
Field::EMAIL_ADDRESS,
])
->order(Field::NAME)
->find();
$list = array_merge($list, [...$itemCollection]);
}
/** @var Collection<Entity> $collection */
$collection = $this->entityManager->getCollectionFactory()->create(null, $list);
foreach ($collection as $e) {
if (
$this->acl->checkEntityRead($e) &&
$this->acl->checkField($e->getEntityType(), Field::EMAIL_ADDRESS)
) {
continue;
}
if (!$e->get(Field::EMAIL_ADDRESS)) {
continue;
}
$e->set(Field::EMAIL_ADDRESS, 'dummy@dummy.dummy');
}
return RecordCollection::create($collection);
}
}