Skip to content

Commit

Permalink
Merge pull request #18 from IQSS/email_sender_overwrite
Browse files Browse the repository at this point in the history
Add global email sender configuration and functionality
  • Loading branch information
jp-tosca authored Jan 10, 2025
2 parents 1b54af9 + 76c83e8 commit 965a1ed
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/Sphinx-guides/source/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions pprOjsPlugin/PeerPreReviewProgramPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
3 changes: 3 additions & 0 deletions pprOjsPlugin/locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
36 changes: 36 additions & 0 deletions pprOjsPlugin/services/email/PPREmailSenderOverwrite.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Service to overwrite the senders email
*
*/
class PPREmailSenderOverwrite {

private $pprPlugin;

public function __construct($plugin) {
$this->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;
}

}
6 changes: 5 additions & 1 deletion pprOjsPlugin/settings/PPRPluginSettings.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PPRPluginSettings {

'accessKeyLifeTime' => ['int', 30],
'fileUploadTextOverrideEnabled' => ['bool', null],
'globalEmailSender' => ['string', '[email protected]'],
);
private $pprPlugin;

Expand Down Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions pprOjsPlugin/templates/ppr/pluginSettingsForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
1 change: 1 addition & 0 deletions pprOjsPlugin/tests/src/settings/PPRPluginSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function test_default_values() {
'reviewerSurveyHtml' => [null, null],
'accessKeyLifeTime' => [null, 30],
'fileUploadTextOverrideEnabled' => [null, null],
'globalEmailSender' => [null, '[email protected]'],
);

foreach (PPRPluginSettings::CONFIG_VARS as $configVar => $varInfo) {
Expand Down

0 comments on commit 965a1ed

Please sign in to comment.