From 0ec428b1ed443acc691bcb483655880c3a225b1a Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 26 Feb 2024 14:59:03 +0200 Subject: [PATCH] target list mandatoryAttributeList usage --- .../metadata/recordDefs/TargetList.json | 12 ++-- .../Espo/Modules/Crm/Services/TargetList.php | 61 ------------------- .../Hook/Hooks/TargetListCreate.php | 1 + upgrades/8.2/scripts/AfterUpgrade.php | 1 + 4 files changed, 10 insertions(+), 65 deletions(-) delete mode 100644 application/Espo/Modules/Crm/Services/TargetList.php diff --git a/application/Espo/Modules/Crm/Resources/metadata/recordDefs/TargetList.json b/application/Espo/Modules/Crm/Resources/metadata/recordDefs/TargetList.json index 02bb84e7d0..22636f6b2f 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/recordDefs/TargetList.json +++ b/application/Espo/Modules/Crm/Resources/metadata/recordDefs/TargetList.json @@ -14,19 +14,23 @@ "relationships": { "users": { "massLink": true, - "linkRequiredForeignAccess": "read" + "linkRequiredForeignAccess": "read", + "mandatoryAttributeList": ["targetListIsOptedOut"] }, "leads": { "massLink": true, - "linkRequiredForeignAccess": "read" + "linkRequiredForeignAccess": "read", + "mandatoryAttributeList": ["targetListIsOptedOut"] }, "contacts": { "massLink": true, - "linkRequiredForeignAccess": "read" + "linkRequiredForeignAccess": "read", + "mandatoryAttributeList": ["targetListIsOptedOut"] }, "accounts": { "massLink": true, - "linkRequiredForeignAccess": "read" + "linkRequiredForeignAccess": "read", + "mandatoryAttributeList": ["targetListIsOptedOut"] } } } diff --git a/application/Espo/Modules/Crm/Services/TargetList.php b/application/Espo/Modules/Crm/Services/TargetList.php deleted file mode 100644 index 3a11368ecd..0000000000 --- a/application/Espo/Modules/Crm/Services/TargetList.php +++ /dev/null @@ -1,61 +0,0 @@ -. - * - * 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\Services; - -use Espo\Core\Select\SearchParams; -use Espo\Modules\Crm\Entities\TargetList as TargetListEntity; -use Espo\Modules\Crm\Tools\TargetList\MetadataProvider; -use Espo\Services\Record; - -/** - * @extends Record - */ -class TargetList extends Record -{ - protected function prepareLinkSearchParams(SearchParams $searchParams, string $link): SearchParams - { - $searchParams = parent::prepareLinkSearchParams($searchParams, $link); - - if ($searchParams->getSelect() === null) { - return $searchParams; - } - - $metadataProvider = $this->injectableFactory->create(MetadataProvider::class); - - if (!in_array($link, $metadataProvider->getTargetLinkList())) { - return $searchParams; - } - - $select = array_merge($searchParams->getSelect(), ['targetListIsOptedOut']); - $select = array_unique($select); - - return $searchParams->withSelect($select); - } -} diff --git a/application/Espo/Tools/LinkManager/Hook/Hooks/TargetListCreate.php b/application/Espo/Tools/LinkManager/Hook/Hooks/TargetListCreate.php index f3267a1865..1d56cb90f2 100644 --- a/application/Espo/Tools/LinkManager/Hook/Hooks/TargetListCreate.php +++ b/application/Espo/Tools/LinkManager/Hook/Hooks/TargetListCreate.php @@ -145,6 +145,7 @@ class TargetListCreate implements CreateHook $foreignLink => [ 'massLink' => true, 'linkRequiredForeignAccess' => 'read', + 'mandatoryAttributeList' => ['targetListIsOptedOut'], ], ], ]); diff --git a/upgrades/8.2/scripts/AfterUpgrade.php b/upgrades/8.2/scripts/AfterUpgrade.php index 56ed440fe5..1d89d42ea4 100644 --- a/upgrades/8.2/scripts/AfterUpgrade.php +++ b/upgrades/8.2/scripts/AfterUpgrade.php @@ -102,6 +102,7 @@ class AfterUpgrade $link => [ 'massLink' => true, 'linkRequiredForeignAccess' => 'read', + 'mandatoryAttributeList' => ['targetListIsOptedOut'], ] ] ]);