Skip to content

Commit

Permalink
Merge branch 'fixesContextPluginAndNotConfiguredError' into 'main'
Browse files Browse the repository at this point in the history
Implements plugin behavior to be enabled only in the journal context.

See merge request softwares-pkp/plugins_ojs/OASwitchboard!16
  • Loading branch information
YvesLepidus committed Mar 11, 2024
2 parents f6f1144 + cab67cb commit 473d39e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion OASwitchboardPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public function sendOASwitchboardMessage($hookName, $args)
$publication = & $args[0];
$submission = & $args[2];
$contextId = PKPApplication::get()->getRequest()->getContext()->getId();
$OASwitchboard = new OASwitchboardService($this, $contextId, $submission);
$request = PKPApplication::get()->getRequest();
$userId = $request->getUser()->getId();

try {
if ($publication->getData('status') === STATUS_PUBLISHED) {
$OASwitchboard = new OASwitchboardService($this, $contextId, $submission);
$OASwitchboard->sendP1PioMessage();
$this->sendNotification($userId, __('plugins.generic.OASwitchboard.sendMessageWithSuccess'), NOTIFICATION_TYPE_SUCCESS);
}
Expand All @@ -133,4 +133,16 @@ public function sendOASwitchboardMessage($hookName, $args)
throw $e;
}
}

public function getCanEnable()
{
$request = Application::get()->getRequest();
return $request->getContext() !== null;
}

public function getCanDisable()
{
$request = Application::get()->getRequest();
return $request->getContext() !== null;
}
}
12 changes: 12 additions & 0 deletions classes/OASwitchboardService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function __construct($plugin, $contextId, $submission)
$this->plugin = $plugin;
$this->contextId = $contextId;
$this->submission = $submission;
$this->validatePluginIsConfigured($this->plugin);

$httpClient = Application::get()->getHttpClient();
$useSandboxApi = $this->plugin->getSetting($this->contextId, 'isSandBoxAPI');
$this->apiClient = new OASwitchboardAPIClient($httpClient, $useSandboxApi);
Expand Down Expand Up @@ -58,4 +60,14 @@ private function getAuthTokenByCredentials()
$credentials['password']
);
}

private function validatePluginIsConfigured($plugin)
{
$username = $this->plugin->getSetting($this->contextId, 'username');
$password = $this->plugin->getSetting($this->contextId, 'password');
$useSandboxApi = $this->plugin->getSetting($this->contextId, 'isSandBoxAPI');
if (is_null($username) || is_null($password) || is_null($useSandboxApi)) {
throw new Exception(__("plugins.generic.OASwitchboard.pluginIsNotConfigured"));
}
}
}
3 changes: 3 additions & 0 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ msgstr "Password:"
msgid "plugins.generic.OASwitchboard.settings.apiAuthenticatorFailed"
msgstr "Failed to authenticate, please check the OA Switchboard API credentials again"

msgid "plugins.generic.OASwitchboard.pluginIsNotConfigured"
msgstr "The OA Switchboard plugin needs to be configured to successfully send the P1-PIO message."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess"
msgstr "The P1-PIO message was successfully sent to the OA Switchboard"

Expand Down
3 changes: 3 additions & 0 deletions locale/es_ES/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ msgstr "Contraseña:"
msgid "plugins.generic.OASwitchboard.settings.apiAuthenticatorFailed"
msgstr "No se pudo autenticar, por favor, comprueba las credenciales de API de OA Switchboard nuevamente"

msgid "plugins.generic.OASwitchboard.pluginIsNotConfigured"
msgstr "El módulo OA Switchboard debe configurarse para enviar correctamente el mensaje P1-PIO."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess"
msgstr "El mensaje P1-PIO se envió correctamente al OA Switchboard"

Expand Down
3 changes: 3 additions & 0 deletions locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ msgstr "Senha:"
msgid "plugins.generic.OASwitchboard.settings.apiAuthenticatorFailed"
msgstr "Não foi possível autenticar, por favor, cheque novamente as credenciais da API OA Switchboard"

msgid "plugins.generic.OASwitchboard.pluginIsNotConfigured"
msgstr "O plugin OA Switchboard precisa ser configurado para que envie a mensagem P1-PIO com êxito."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess"
msgstr "A mensagem P1-PIO foi enviada com sucesso para o OA Switchboard"

Expand Down

0 comments on commit 473d39e

Please sign in to comment.