From 8d989583de6a548b5caae0e5b7183cd5dbd64d06 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 30 Jan 2025 16:12:48 -0500 Subject: [PATCH] DomainEmailAddress - Add search display and formbuilder form Removes unused handling from the quickform --- CRM/Admin/Form/Options.php | 25 --- ang/afform/afformSiteEmailAddress.aff.html | 12 ++ ang/afform/afformSiteEmailAddress.aff.php | 11 ++ .../afsearchSiteEmailAddresses.aff.html | 3 + ang/afform/afsearchSiteEmailAddresses.aff.php | 11 ++ .../SavedSearch_Site_Email_Addresses.mgd.php | 179 ++++++++++++++++++ schema/Core/DomainEmailAddress.entityType.php | 6 +- templates/CRM/Admin/Form/Options.tpl | 7 - templates/CRM/Admin/Page/Options.tpl | 6 - tests/phpunit/CRM/Core/OptionGroupTest.php | 16 -- 10 files changed, 221 insertions(+), 55 deletions(-) create mode 100644 ang/afform/afformSiteEmailAddress.aff.html create mode 100644 ang/afform/afformSiteEmailAddress.aff.php create mode 100644 ang/afform/afsearchSiteEmailAddresses.aff.html create mode 100644 ang/afform/afsearchSiteEmailAddresses.aff.php create mode 100644 managed/administer/SavedSearch_Site_Email_Addresses.mgd.php diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index ecadf60c3b05..d2f5961ec68b 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -343,7 +343,6 @@ public function buildQuickForm(): void { 'email_greeting', 'postal_greeting', 'addressee', - 'from_email_address', 'case_status', 'encounter_medium', 'case_type', @@ -439,18 +438,6 @@ public static function formRule($fields, $files, $self) { } - if ($optionGroupName === 'from_email_address') { - $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']); - if (!CRM_Utils_Rule::email($formEmail)) { - $errors['label'] = ts('Please enter a valid email address.'); - } - - $formName = explode('"', $fields['label']); - if (empty($formName[1]) || count($formName) != 3) { - $errors['label'] = ts('Please follow the proper format for From Email Address'); - } - } - $dataType = self::getOptionGroupDataType($optionGroupName); if ($dataType && $optionGroupName !== 'activity_type') { $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE); @@ -528,10 +515,6 @@ public function postProcess() { $params['filter'] = $params['contact_type_id']; } - //make sure we only have a single space, CRM-6977 and dev/mail/15 - if ($this->_gName == 'from_email_address') { - $params['label'] = $this->sanitizeFromEmailAddress($params['label']); - } // set value of filter if not present in params if ($this->_id && !array_key_exists('filter', $params)) { if ($this->_gName == 'participant_role') { @@ -560,11 +543,6 @@ public function postProcess() { } } - public function sanitizeFromEmailAddress($email) { - preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $email, $parts); - return "\"{$parts[1]}\" <$parts[2]>"; - } - /** * Is the option group one of our greetings. * @@ -579,9 +557,6 @@ protected function isGreetingOptionGroup(): bool { * @return array */ protected function getFieldsToExcludeFromPurification(): array { - if ($this->_gName === 'from_email_address') { - return ['label']; - } return []; } diff --git a/ang/afform/afformSiteEmailAddress.aff.html b/ang/afform/afformSiteEmailAddress.aff.html new file mode 100644 index 000000000000..191297e041e8 --- /dev/null +++ b/ang/afform/afformSiteEmailAddress.aff.html @@ -0,0 +1,12 @@ + + +
+
+ + +
+ + +
+ +
diff --git a/ang/afform/afformSiteEmailAddress.aff.php b/ang/afform/afformSiteEmailAddress.aff.php new file mode 100644 index 000000000000..c264a71b88a9 --- /dev/null +++ b/ang/afform/afformSiteEmailAddress.aff.php @@ -0,0 +1,11 @@ + 'form', + 'title' => ts('Site Email Address'), + 'icon' => 'fa-list-alt', + 'server_route' => 'civicrm/admin/form/site-email-address', + 'permission' => [ + 'administer CiviCRM system', + ], +]; diff --git a/ang/afform/afsearchSiteEmailAddresses.aff.html b/ang/afform/afsearchSiteEmailAddresses.aff.html new file mode 100644 index 000000000000..07413b44e199 --- /dev/null +++ b/ang/afform/afsearchSiteEmailAddresses.aff.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/ang/afform/afsearchSiteEmailAddresses.aff.php b/ang/afform/afsearchSiteEmailAddresses.aff.php new file mode 100644 index 000000000000..3a329e05b04b --- /dev/null +++ b/ang/afform/afsearchSiteEmailAddresses.aff.php @@ -0,0 +1,11 @@ + 'search', + 'title' => ts('Site Email Addresses'), + 'icon' => 'fa-list-alt', + 'server_route' => 'civicrm/admin/options/from_email_address', + 'permission' => [ + 'administer CiviCRM system', + ], +]; diff --git a/managed/administer/SavedSearch_Site_Email_Addresses.mgd.php b/managed/administer/SavedSearch_Site_Email_Addresses.mgd.php new file mode 100644 index 000000000000..2bc9e38e3cb1 --- /dev/null +++ b/managed/administer/SavedSearch_Site_Email_Addresses.mgd.php @@ -0,0 +1,179 @@ + 'SavedSearch_Site_Email_Addresses', + 'entity' => 'SavedSearch', + 'cleanup' => 'unused', + 'update' => 'unmodified', + 'params' => [ + 'version' => 4, + 'values' => [ + 'name' => 'Site_Email_Addresses', + 'label' => ts('Site Email Addresses'), + 'api_entity' => 'DomainEmailAddress', + 'api_params' => [ + 'version' => 4, + 'select' => [ + 'name', + 'email', + 'description', + 'is_active', + 'is_default', + ], + 'orderBy' => [], + 'where' => [ + ['domain_id:name', '=', 'current_domain'], + ], + 'groupBy' => [], + 'join' => [], + 'having' => [], + ], + ], + 'match' => ['name'], + ], + ], + [ + 'name' => 'SavedSearch_Site_Email_Addresses_SearchDisplay_Site_Email_Addresses', + 'entity' => 'SearchDisplay', + 'cleanup' => 'unused', + 'update' => 'unmodified', + 'params' => [ + 'version' => 4, + 'values' => [ + 'name' => 'Site_Email_Addresses', + 'label' => ts('Site Email Addresses'), + 'saved_search_id.name' => 'Site_Email_Addresses', + 'type' => 'table', + 'settings' => [ + 'description' => ts('You can use this page to define one or more general Email Addresses that can be selected as the From Address.'), + 'sort' => [], + 'limit' => 50, + 'pager' => [ + 'hide_single' => TRUE, + 'show_count' => TRUE, + ], + 'placeholder' => 5, + 'columns' => [ + [ + 'type' => 'field', + 'key' => 'name', + 'dataType' => 'String', + 'label' => ts('Display Name'), + 'sortable' => TRUE, + ], + [ + 'type' => 'field', + 'key' => 'email', + 'dataType' => 'String', + 'label' => ts('Email'), + 'sortable' => TRUE, + ], + [ + 'type' => 'field', + 'key' => 'description', + 'dataType' => 'Text', + 'label' => ts('Description'), + 'sortable' => TRUE, + ], + [ + 'type' => 'field', + 'key' => 'is_active', + 'dataType' => 'Boolean', + 'label' => ts('Enabled'), + 'sortable' => TRUE, + ], + [ + 'type' => 'field', + 'key' => 'is_default', + 'dataType' => 'Boolean', + 'label' => ts('Default'), + 'sortable' => TRUE, + 'icons' => [ + [ + 'icon' => 'fa-circle-check', + 'side' => 'left', + 'if' => ['is_default', '=', TRUE], + ], + ], + 'rewrite' => ' ', + ], + [ + 'text' => ts(''), + 'style' => 'default', + 'size' => 'btn-xs', + 'icon' => 'fa-bars', + 'links' => [ + [ + 'entity' => 'DomainEmailAddress', + 'action' => 'update', + 'join' => '', + 'target' => 'crm-popup', + 'icon' => 'fa-pencil', + 'text' => ts('Edit Email Address'), + 'style' => 'default', + 'path' => '', + 'task' => '', + 'condition' => [], + ], + [ + 'task' => 'disable', + 'entity' => 'DomainEmailAddress', + 'join' => '', + 'target' => 'crm-popup', + 'icon' => 'fa-toggle-off', + 'text' => ts('Disable Email Addresses'), + 'style' => 'default', + 'path' => '', + 'action' => '', + 'condition' => [], + ], + [ + 'task' => 'enable', + 'entity' => 'DomainEmailAddress', + 'join' => '', + 'target' => 'crm-popup', + 'icon' => 'fa-toggle-on', + 'text' => ts('Enable Email Addresses'), + 'style' => 'default', + 'path' => '', + 'action' => '', + 'condition' => [], + ], + ], + 'type' => 'menu', + 'alignment' => 'text-right', + ], + ], + 'actions' => FALSE, + 'classes' => [ + 'table', + 'table-striped', + 'crm-sticky-header', + ], + 'toolbar' => [ + [ + 'entity' => 'DomainEmailAddress', + 'text' => ts('Add Email Address'), + 'icon' => 'fa-plus', + 'target' => 'crm-popup', + 'action' => 'add', + 'style' => 'primary', + 'join' => '', + 'path' => '', + 'task' => '', + 'condition' => [], + ], + ], + 'cssRules' => [ + ['disabled', 'is_active', '=', FALSE], + ], + ], + ], + 'match' => [ + 'saved_search_id', + 'name', + ], + ], + ], +]; diff --git a/schema/Core/DomainEmailAddress.entityType.php b/schema/Core/DomainEmailAddress.entityType.php index 331b15fc2bf8..38a99015bb3b 100644 --- a/schema/Core/DomainEmailAddress.entityType.php +++ b/schema/Core/DomainEmailAddress.entityType.php @@ -13,7 +13,11 @@ 'icon' => 'fa-envelope', 'label_field' => 'name', ], - 'getPaths' => fn() => [], + 'getPaths' => fn() => [ + 'browse' => 'civicrm/admin/options/from_email_address', + 'add' => 'civicrm/admin/form/site-email-address', + 'update' => 'civicrm/admin/form/site-email-address#?email=[id]', + ], 'getIndices' => fn() => [ 'UI_domain_id_is_default' => [ 'fields' => [ diff --git a/templates/CRM/Admin/Form/Options.tpl b/templates/CRM/Admin/Form/Options.tpl index 44a0cd8de904..90cf54109f85 100644 --- a/templates/CRM/Admin/Form/Options.tpl +++ b/templates/CRM/Admin/Form/Options.tpl @@ -23,13 +23,6 @@ {ts}Enter the "class path" for this custom search here.{/ts} - {elseif $gName eq 'from_email_address'} - - {ts}FROM Email Address{/ts} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_option_value' field='label' id=$id}{/if} - {$form.label.html}
- {ts}Include double-quotes (") around the name and angle-brackets (< >) around the email address.
EXAMPLE: "Client Services" <clientservices@example.org>{/ts} - - {elseif $gName eq 'redaction_rule'} {ts}Match Value or Expression{/ts} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_option_value' field='label' id=$id}{/if} diff --git a/templates/CRM/Admin/Page/Options.tpl b/templates/CRM/Admin/Page/Options.tpl index 2a934b44d9af..7c3ebbdd41af 100644 --- a/templates/CRM/Admin/Page/Options.tpl +++ b/templates/CRM/Admin/Page/Options.tpl @@ -42,12 +42,6 @@ {ts}Define participant roles for events here (e.g. Attendee, Host, Speaker...). You can then assign roles and search for participants by role.{/ts} {elseif $gName eq 'participant_status'} {ts}Define statuses for event participants here (e.g. Registered, Attended, Cancelled...). You can then assign statuses and search for participants by status.{/ts} {ts}"Counted?" controls whether a person with that status is counted as participant for the purpose of controlling the Maximum Number of Participants.{/ts} - {elseif $gName eq 'from_email_address'} - {if $allowLoggedIn} - {ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, you can use this page to define one or more general Email Addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts} - {else} - {ts}You can use this page to define one or more general Email Addresses that can be selected as the From Address. EXAMPLE: "Client Services" <clientservices@example.org>{/ts} - {/if} {elseif $isLocked} {ts}This option group is reserved for system use. You cannot add or delete options in this list.{/ts} {else} diff --git a/tests/phpunit/CRM/Core/OptionGroupTest.php b/tests/phpunit/CRM/Core/OptionGroupTest.php index 8fbd5aae5ae2..0c07867b60cc 100644 --- a/tests/phpunit/CRM/Core/OptionGroupTest.php +++ b/tests/phpunit/CRM/Core/OptionGroupTest.php @@ -75,22 +75,6 @@ public function testsOptionGroupDataType($optionGroup, $expectedDataType) { } } - public function emailAddressTests() { - $tests[] = ['"Name"', '"Name" ']; - $tests[] = ['"Name" ', '"Name" ']; - $tests[] = ['"Name" ', '"Name" ']; - return $tests; - } - - /** - * @dataProvider emailAddressTests - */ - public function testSanitizeFromEmailAddress($dirty, $clean) { - $form = new CRM_Admin_Form_Options(); - $actual = $form->sanitizeFromEmailAddress($dirty); - $this->assertEquals($actual, $clean); - } - public static function orderByCases(): array { return [ ['weight', FALSE],