From f2df3d759a8aeb01c85c80dd6e8acbe7750744f3 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Thu, 9 Jan 2025 19:42:30 -0500 Subject: [PATCH 1/8] Add global email sender configuration and functionality --- docs/Sphinx-guides/source/features.md | 1 + .../PeerPreReviewProgramPlugin.inc.php | 4 +++ pprOjsPlugin/locale/en_US/locale.po | 3 ++ .../email/PPREmailSenderOverwrite.inc.php | 36 +++++++++++++++++++ .../settings/PPRPluginSettings.inc.php | 6 +++- .../templates/ppr/pluginSettingsForm.tpl | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php diff --git a/docs/Sphinx-guides/source/features.md b/docs/Sphinx-guides/source/features.md index 3d2e970..1588075 100644 --- a/docs/Sphinx-guides/source/features.md +++ b/docs/Sphinx-guides/source/features.md @@ -63,6 +63,7 @@ Additionally, we use other plugins and customizations made by other contributors - Send submission approved confirmation email to author - Removes the Coauthors from the submission confirmation email the Author receives - Add a checkbox to allow authors to choose if contributors should be notified +- Global email Sender ### Scheduled Tasks diff --git a/pprOjsPlugin/PeerPreReviewProgramPlugin.inc.php b/pprOjsPlugin/PeerPreReviewProgramPlugin.inc.php index c4e7adb..0602cc8 100644 --- a/pprOjsPlugin/PeerPreReviewProgramPlugin.inc.php +++ b/pprOjsPlugin/PeerPreReviewProgramPlugin.inc.php @@ -97,6 +97,10 @@ function register($category, $path, $mainContextId = null) { $addEditorEmailService = new PPRReviewAddEditorEmailService($this); $addEditorEmailService->register(); + $this->import('services.email.PPREmailSenderOverwrite'); + $addEditorEmailService = new PPREmailSenderOverwrite($this); + $addEditorEmailService->register(); + // THIS HOOK WILL ONLY BE CALLED WHEN THE acron PLUGIN IS RELOADED HookRegistry::register('AcronPlugin::parseCronTab', array($this, 'addScheduledTasks')); } diff --git a/pprOjsPlugin/locale/en_US/locale.po b/pprOjsPlugin/locale/en_US/locale.po index e7f61c0..f722847 100644 --- a/pprOjsPlugin/locale/en_US/locale.po +++ b/pprOjsPlugin/locale/en_US/locale.po @@ -80,6 +80,9 @@ msgstr "Send review submitted confirmation email to reviewer" msgid "plugins.generic.pprPlugin.settings.reviewReminderEmailOverrideEnabled.label" msgstr "Add review reminder action email template override based on review being accepted" +msgid "plugins.generic.pprPlugin.settings.globalEmailSender.label" +msgstr "Global email sender" + msgid "plugins.generic.pprPlugin.settings.reviewAddEditorToBccEnabled.label" msgstr "Add Managing Editor as BCC to thank reviewer email" diff --git a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php new file mode 100644 index 0000000..c832bef --- /dev/null +++ b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php @@ -0,0 +1,36 @@ +pprPlugin = $plugin; + } + + function register() { + + $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + + if (!empty($globalEmailSender)) { + HookRegistry::register('Mail::send', array($this, 'overwriteSender')); + } + } + + /** + * Overwrite the sender of the email + */ + function overwriteSender($hookName, $hookArgs) { + + $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + + $mail = $hookArgs[0]; + $mail->setFrom($globalEmailSender, 'Peer Pre-Review'); + return false; + } + +} \ No newline at end of file diff --git a/pprOjsPlugin/settings/PPRPluginSettings.inc.php b/pprOjsPlugin/settings/PPRPluginSettings.inc.php index 64181e3..5edf5d1 100644 --- a/pprOjsPlugin/settings/PPRPluginSettings.inc.php +++ b/pprOjsPlugin/settings/PPRPluginSettings.inc.php @@ -63,6 +63,7 @@ class PPRPluginSettings { 'accessKeyLifeTime' => ['int', 30], 'fileUploadTextOverrideEnabled' => ['bool', null], + 'globalEmailSender' => ['string', 'peerprereview@iq.harvard.edu'], ); private $pprPlugin; @@ -287,11 +288,14 @@ public function reviewerSurveyHtml() { return $this->getValue('reviewerSurveyHtml'); } - public function accessKeyLifeTime() { return $this->getValue('accessKeyLifeTime'); } + public function globalEmailSender() { + return $this->getValue('globalEmailSender'); + } + private function getValue($propertyName) { return $this->pprPlugin->getSetting($this->contextId, $propertyName) ?? self::CONFIG_VARS[$propertyName][1]; } diff --git a/pprOjsPlugin/templates/ppr/pluginSettingsForm.tpl b/pprOjsPlugin/templates/ppr/pluginSettingsForm.tpl index 4936755..021bb9c 100644 --- a/pprOjsPlugin/templates/ppr/pluginSettingsForm.tpl +++ b/pprOjsPlugin/templates/ppr/pluginSettingsForm.tpl @@ -93,6 +93,7 @@ {fbvElement type="checkbox" name="submissionApprovedEmailEnabled" label="plugins.generic.pprPlugin.settings.submissionApprovedEmailEnabled.label" id="submissionApprovedEmailEnabled" checked=$submissionApprovedEmailEnabled} {fbvElement type="checkbox" name="submissionConfirmationContributorsEmailDisabled" label="plugins.generic.pprPlugin.settings.submissionConfirmationContributorsEmailDisabled.label" id="submissionConfirmationContributorsEmailDisabled" checked=$submissionConfirmationContributorsEmailDisabled} {fbvElement type="checkbox" name="emailContributorsEnabled" label="plugins.generic.pprPlugin.settings.emailContributorsEnabled.label" id="emailContributorsEnabled" checked=$emailContributorsEnabled} + {fbvElement type="text" name="globalEmailSender" label="plugins.generic.pprPlugin.settings.globalEmailSender.label" id="globalEmailSender" value=$globalEmailSender} {/fbvFormSection} {fbvFormSection title="plugins.generic.pprPlugin.settings.section.tasks" list="true"} From df8a9891f97bc1ab7b2b58c45b82056e5a2df3e1 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Fri, 10 Jan 2025 10:39:58 -0500 Subject: [PATCH 2/8] Add default global email sender configuration to settings test --- .../tests/src/settings/PPRReportPluginSettingsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php b/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php index c6992e3..9aeff34 100644 --- a/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php +++ b/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php @@ -17,6 +17,7 @@ public function test_default_values() { // fieldName => [methodName, defaultValue] 'submissionsReviewsReportEnabled' => [null, null], 'submissionsReviewsReportRecipients' => [null, []], + 'globalEmailSender' => [null, 'peerprereview@iq.harvard.edu'], ); foreach (PPRReportPluginSettings::CONFIG_VARS as $configVar => $varInfo) { From 3ac8828e4bc4a9b5f2b9fa01b44f3e163294c4ef Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Fri, 10 Jan 2025 10:53:23 -0500 Subject: [PATCH 3/8] Remove default global email sender configuration from settings test --- .../tests/src/settings/PPRReportPluginSettingsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php b/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php index 9aeff34..c6992e3 100644 --- a/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php +++ b/pprReviewsReportPlugin/tests/src/settings/PPRReportPluginSettingsTest.php @@ -17,7 +17,6 @@ public function test_default_values() { // fieldName => [methodName, defaultValue] 'submissionsReviewsReportEnabled' => [null, null], 'submissionsReviewsReportRecipients' => [null, []], - 'globalEmailSender' => [null, 'peerprereview@iq.harvard.edu'], ); foreach (PPRReportPluginSettings::CONFIG_VARS as $configVar => $varInfo) { From 76c83e8014282b003740fbda8f93cc3bd04e0466 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Fri, 10 Jan 2025 10:59:23 -0500 Subject: [PATCH 4/8] Add global email sender configuration to settings test --- pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php b/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php index 818131f..47fdb93 100644 --- a/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php +++ b/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php @@ -64,6 +64,7 @@ public function test_default_values() { 'reviewerSurveyHtml' => [null, null], 'accessKeyLifeTime' => [null, 30], 'fileUploadTextOverrideEnabled' => [null, null], + 'globalEmailSender' => [null, 'peerprereview@iq.harvard.edu'], ); foreach (PPRPluginSettings::CONFIG_VARS as $configVar => $varInfo) { From 33b20a00f23d392fd34fa8fd891310ea14ec82e6 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Fri, 10 Jan 2025 12:27:53 -0500 Subject: [PATCH 5/8] Update email sender to use fixed address instead of global configuration --- .../services/email/PPREmailSenderOverwrite.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php index c832bef..13a4b81 100644 --- a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php +++ b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php @@ -14,7 +14,7 @@ public function __construct($plugin) { function register() { - $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + //$globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); if (!empty($globalEmailSender)) { HookRegistry::register('Mail::send', array($this, 'overwriteSender')); @@ -26,10 +26,11 @@ function register() { */ function overwriteSender($hookName, $hookArgs) { - $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + //$globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); $mail = $hookArgs[0]; - $mail->setFrom($globalEmailSender, 'Peer Pre-Review'); + //$mail->setFrom($globalEmailSender, 'Peer Pre-Review'); + $mail->setFrom('peerprereview@iq.harvard.edu', 'Peer Pre-Review'); return false; } From ae59523c9f43893a30f7f190e2c3aa46ad620268 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Fri, 10 Jan 2025 14:07:52 -0500 Subject: [PATCH 6/8] Refactor email sender to use global configuration instead of hardcoded address --- .../services/email/PPREmailSenderOverwrite.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php index 13a4b81..7065eca 100644 --- a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php +++ b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php @@ -14,7 +14,7 @@ public function __construct($plugin) { function register() { - //$globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); if (!empty($globalEmailSender)) { HookRegistry::register('Mail::send', array($this, 'overwriteSender')); @@ -26,11 +26,11 @@ function register() { */ function overwriteSender($hookName, $hookArgs) { - //$globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); + $globalEmailSender = $this->pprPlugin->getPluginSettings()->globalEmailSender(); $mail = $hookArgs[0]; - //$mail->setFrom($globalEmailSender, 'Peer Pre-Review'); - $mail->setFrom('peerprereview@iq.harvard.edu', 'Peer Pre-Review'); + $mail->setFrom($globalEmailSender, 'Peer Pre-Review'); + //$mail->setFrom('peerprereview@iq.harvard.edu', 'Peer Pre-Review'); return false; } From d6135a80d2fb569d098c5d53d07eee1308751897 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Mon, 13 Jan 2025 10:37:59 -0500 Subject: [PATCH 7/8] Update global email sender address in configuration --- pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php | 1 - pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php index 7065eca..c832bef 100644 --- a/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php +++ b/pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php @@ -30,7 +30,6 @@ function overwriteSender($hookName, $hookArgs) { $mail = $hookArgs[0]; $mail->setFrom($globalEmailSender, 'Peer Pre-Review'); - //$mail->setFrom('peerprereview@iq.harvard.edu', 'Peer Pre-Review'); return false; } diff --git a/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php b/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php index 47fdb93..f4a0dbd 100644 --- a/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php +++ b/pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php @@ -64,7 +64,7 @@ public function test_default_values() { 'reviewerSurveyHtml' => [null, null], 'accessKeyLifeTime' => [null, 30], 'fileUploadTextOverrideEnabled' => [null, null], - 'globalEmailSender' => [null, 'peerprereview@iq.harvard.edu'], + 'globalEmailSender' => [null, 'peerprereview@pre-review.iq.harvard.edu'], ); foreach (PPRPluginSettings::CONFIG_VARS as $configVar => $varInfo) { From 320cdd176924e4fd9efd3bab5928084256386ef5 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosca Villanueva Date: Mon, 13 Jan 2025 13:11:42 -0500 Subject: [PATCH 8/8] Update global email sender address in PPRPluginSettings --- pprOjsPlugin/settings/PPRPluginSettings.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pprOjsPlugin/settings/PPRPluginSettings.inc.php b/pprOjsPlugin/settings/PPRPluginSettings.inc.php index 5edf5d1..be833a6 100644 --- a/pprOjsPlugin/settings/PPRPluginSettings.inc.php +++ b/pprOjsPlugin/settings/PPRPluginSettings.inc.php @@ -63,7 +63,7 @@ class PPRPluginSettings { 'accessKeyLifeTime' => ['int', 30], 'fileUploadTextOverrideEnabled' => ['bool', null], - 'globalEmailSender' => ['string', 'peerprereview@iq.harvard.edu'], + 'globalEmailSender' => ['string', 'peerprereview@pre-review.iq.harvard.edu'], ); private $pprPlugin;