From 9810beb952a6f88c48d74eabbbc8b8cfd9483b5b Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Fri, 22 Jul 2022 12:33:52 -0400 Subject: [PATCH] #28: remove unneeded config.inc.php ithenticate setting to enable plugin --- PlagiarismPlugin.inc.php | 48 +++++++++++++++++++++++++--------- PlagiarismSettingsForm.inc.php | 4 +-- README.md | 6 ++--- locale/en_US/locale.po | 2 +- templates/settingsForm.tpl | 2 +- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/PlagiarismPlugin.inc.php b/PlagiarismPlugin.inc.php index ae86caf..f64cc53 100644 --- a/PlagiarismPlugin.inc.php +++ b/PlagiarismPlugin.inc.php @@ -44,35 +44,59 @@ public function getDescription() { * @copydoc LazyLoadPlugin::getCanEnable() */ function getCanEnable($contextId = null) { - return !Config::getVar('ithenticate', 'ithenticate'); + if ($contextId === null) { + $contextId = $this->getCurrentContextId(); + } + list($username, $password) = $this->getForcedCredentials($contextId); + // Automatically enabled (and cannot be manually enabled) if username and password are in config.inc.php + return !(isset($username) && isset($password)); } /** * @copydoc LazyLoadPlugin::getCanDisable() */ function getCanDisable($contextId = null) { - return !Config::getVar('ithenticate', 'ithenticate'); + if ($contextId === null) { + $contextId = $this->getCurrentContextId(); + } + list($username, $password) = $this->getForcedCredentials($contextId); + // Automatically enabled (and cannot be manually disabled) if username and password are in config.inc.php + return !(isset($username) && isset($password)); } /** * @copydoc LazyLoadPlugin::getEnabled() */ function getEnabled($contextId = null) { - return parent::getEnabled($contextId) || Config::getVar('ithenticate', 'ithenticate'); + if ($contextId === null) { + $contextId = $this->getCurrentContextId(); + } + list($username, $password) = $this->getForcedCredentials($contextId); + // Can be enabled in the UI, or can be automatically enabled if username and password are set in config.inc.php + return parent::getEnabled($contextId) || (isset($username) && isset($password)); } /** * Fetch credentials from config.inc.php, if available + * @param $contextId int Preferred context (but site can override) * @return array username and password, or null(s) **/ - function getForcedCredentials() { - $request = Application::getRequest(); - $context = $request->getContext(); - $contextPath = $context->getPath(); - $username = Config::getVar('ithenticate', 'username[' . $contextPath . ']', - Config::getVar('ithenticate', 'username')); - $password = Config::getVar('ithenticate', 'password[' . $contextPath . ']', - Config::getVar('ithenticate', 'password')); + function getForcedCredentials($contextId) { + $context = null; + if ($contextId) { + $contextDao = Application::getContextDAO(); + $context = $contextDao->getById($contextId); + } + if ($context) { + $contextPath = $context->getPath(); + $username = Config::getVar('ithenticate', 'username[' . $contextPath . ']', + Config::getVar('ithenticate', 'username')); + $password = Config::getVar('ithenticate', 'password[' . $contextPath . ']', + Config::getVar('ithenticate', 'password')); + } else { + $username = Config::getVar('ithenticate', 'username'); + $password = Config::getVar('ithenticate', 'password'); + } return [$username, $password]; } @@ -141,7 +165,7 @@ public function callback($hookName, $args) { // try to get credentials for current context otherwise use default config $contextId = $context->getId(); - list($username, $password) = $this->getForcedCredentials(); + list($username, $password) = $this->getForcedCredentials($contextId); if (empty($username) || empty($password)) { $username = $this->getSetting($contextId, 'ithenticateUser'); $password = $this->getSetting($contextId, 'ithenticatePass'); diff --git a/PlagiarismSettingsForm.inc.php b/PlagiarismSettingsForm.inc.php index 14167f3..d1711f6 100644 --- a/PlagiarismSettingsForm.inc.php +++ b/PlagiarismSettingsForm.inc.php @@ -33,7 +33,7 @@ function __construct($plugin, $contextId) { * Initialize form data. */ function initData() { - list($username, $password) = $this->_plugin->getForcedCredentials(); + list($username, $password) = $this->_plugin->getForcedCredentials($this->_contextId); $this->_data = array( 'ithenticateUser' => $this->_plugin->getSetting($this->_contextId, 'ithenticateUser'), 'ithenticatePass' => $this->_plugin->getSetting($this->_contextId, 'ithenticatePass'), @@ -82,7 +82,7 @@ function _checkConnection($formPassword, $form) { $contextDao = Application::getContextDAO(); $context = $contextDao->getById($this->_contextId); // if credentials are forced, don't bother testing them. The user can't do anything about a failure on this form. - list($username, $password) = $this->_plugin->getForcedCredentials(); + list($username, $password) = $this->_plugin->getForcedCredentials($this->_contextId); if (!empty($username) && !empty($password)) { return false; } diff --git a/README.md b/README.md index 10adbd7..baa98e5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Watch [the demo](https://www.ithenticate.com/demo) to know more about the featur ## Configuration -You may set the credentials in config.inc.php, or you may set the credentials per-journal in the plugin settings. If credentials are present in config.inc.php, they will override those entered in the plugin settings form. +You may set the credentials in config.inc.php, or you may set the credentials per-journal in the plugin settings. If credentials are present in config.inc.php, they will override those entered in the plugin settings form and will automatically enable the plugin. The config.inc.php settings format is: @@ -35,9 +35,6 @@ The config.inc.php settings format is: [ithenticate] -; Enable iThenticate to submit manuscripts after submit step 4 -;ithenticate = On - ; Credentials can be set by context : specify journal path ; The username to access the API (usually an email address) ;username[MyJournal_path] = "user@email.com" @@ -52,3 +49,4 @@ The config.inc.php settings format is: ;password = "password" ``` +If you have an entry in this section for `ithenticate = On` from an earlier version, you can remove it. diff --git a/locale/en_US/locale.po b/locale/en_US/locale.po index e25bd74..61106e9 100644 --- a/locale/en_US/locale.po +++ b/locale/en_US/locale.po @@ -36,7 +36,7 @@ msgid "plugins.generic.plagiarism.manager.settings.loginFailed" msgstr "iThenticate login failed." msgid "plugins.generic.plagiarism.manager.settings.areForced" -msgstr "iThenticate settings were found in config.inc.php and the settings here will not be used." +msgstr "iThenticate settings were found in config.inc.php. The settings here will not be used." msgid "plugins.generic.plagiarism.errorMessage" msgstr "Upload of submission {$submissionId} to iThenticate failed with error: {$errorMessage}" diff --git a/templates/settingsForm.tpl b/templates/settingsForm.tpl index 5b212e2..cac39fb 100644 --- a/templates/settingsForm.tpl +++ b/templates/settingsForm.tpl @@ -11,7 +11,7 @@
{translate key="plugins.generic.plagiarism.manager.settings.description"}
{if $ithenticateForced} -
{translate key="plugins.generic.plagiarism.manager.settings.areForced"}
+
{translate key="plugins.generic.plagiarism.manager.settings.areForced"}
{/if} {fbvFormArea id="webFeedSettingsFormArea"}