Skip to content

Commit

Permalink
pkp#28: remove unneeded config.inc.php ithenticate setting to enable …
Browse files Browse the repository at this point in the history
…plugin
  • Loading branch information
ctgraham committed Jul 22, 2022
1 parent 4076085 commit 9810beb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
48 changes: 36 additions & 12 deletions PlagiarismPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions PlagiarismSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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] = "[email protected]"
Expand All @@ -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.
2 changes: 1 addition & 1 deletion locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
2 changes: 1 addition & 1 deletion templates/settingsForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<div id="description">{translate key="plugins.generic.plagiarism.manager.settings.description"}</div>
{if $ithenticateForced}
<div id="ithenticate_notice"><b>{translate key="plugins.generic.plagiarism.manager.settings.areForced"}</b></div>
<div id="ithenticate_notice"><span class="error">{translate key="plugins.generic.plagiarism.manager.settings.areForced"}</span></div>
{/if}

{fbvFormArea id="webFeedSettingsFormArea"}
Expand Down

0 comments on commit 9810beb

Please sign in to comment.