Skip to content

Commit

Permalink
pkp#229 OrcidProfilePlugin-705
Browse files Browse the repository at this point in the history
  • Loading branch information
withanage committed Jan 29, 2023
1 parent 3eec210 commit d0d9575
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
16 changes: 10 additions & 6 deletions OrcidProfilePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
use PKP\plugins\PluginRegistry;
use PKP\submission\PKPSubmission;
use APP\plugins\generic\orcidProfile\mailables\OrcidCollectAuthorId;
use APP\plugins\generic\orcidProfile\classes\form\OrcidProfileSettingsForm;
use APP\plugins\generic\orcidProfile\classes\form\OrcidProfileStatusForm;
use APP\plugins\generic\orcidProfile\classes\OrcidValidator;
use APP\plugins\generic\orcidProfile\pages\OrcidHandler;


class OrcidProfilePlugin extends GenericPlugin
{
Expand Down Expand Up @@ -254,7 +259,7 @@ public function setupCallbackHandler($hookName, $params)
{
$page = $params[0];
if ($this->getEnabled() && $page == 'orcidapi') {
$this->import('pages/OrcidHandler');

define('HANDLER_CLASS', 'OrcidHandler');
return true;
}
Expand Down Expand Up @@ -826,10 +831,11 @@ function setEnabled($enabled) {

public function manage($args, $request)
{
$context = $request->getContext();
$contextId = ($context == null) ? 0 : $context->getId();

switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$contextId = ($context == null) ? 0 : $context->getId();

$templateMgr = TemplateManager::getManager();
$templateMgr->registerPlugin('function', 'plugin_url', [$this, 'smartyPluginUrl']);
Expand All @@ -845,8 +851,7 @@ public function manage($args, $request)
'ALL' => 'plugins.generic.orcidProfile.manager.settings.logLevel.all'
]);

$this->import('classes.form.OrcidProfileSettingsForm');
$form = new OrcidProfileSettingsForm($this, $contextId);
$form = new OrcidProfileSettingsForm($this, $contextId);
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
Expand All @@ -858,7 +863,6 @@ public function manage($args, $request)
}
return new JSONMessage(true, $form->fetch($request));
case 'status':
$this->import('classes.form.OrcidProfileStatusForm');
$form = new OrcidProfileStatusForm($this, $contextId);
$form->initData();
return new JSONMessage(true, $form->fetch($request));
Expand Down
1 change: 1 addition & 0 deletions classes/OrcidValidator.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

namespace APP\plugins\generic\orcidProfile\classes;

class OrcidValidator {

Expand Down
16 changes: 9 additions & 7 deletions classes/form/OrcidProfileSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* @brief Form for site admins to modify ORCID Profile plugin settings
*/

namespace APP\plugins\generic\orcidProfile\classes\form;

use PKP\form\Form;
use APP\plugins\generic\orcidProfile\classes\OrcidValidator;

import('lib.pkp.classes.form.Form');
import('plugins.generic.orcidProfile.classes.OrcidValidator');

class OrcidProfileSettingsForm extends Form {

Expand Down Expand Up @@ -50,15 +52,15 @@ function __construct($plugin, $contextId) {
$orcidValidator = new OrcidValidator($plugin);
$this->validator = $orcidValidator;
parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));

if (!$this->plugin->isGloballyConfigured()) {
$this->addCheck(new FormValidator($this, 'orcidProfileAPIPath', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidAPIPathRequired'));
$this->addCheck(new FormValidatorCustom($this, 'orcidClientId', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidClientId.error', function ($clientId) {
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'orcidProfileAPIPath', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidAPIPathRequired'));
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'orcidClientId', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidClientId.error', function ($clientId) {
return $this->validator->validateClientId($clientId);
}));
$this->addCheck(new FormValidatorCustom($this, 'orcidClientSecret', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidClientSecret.error', function ($clientSecret) {
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'orcidClientSecret', 'required', 'plugins.generic.orcidProfile.manager.settings.orcidClientSecret.error', function ($clientSecret) {
return $this->validator->validateClientSecret($clientSecret);
}));
}
Expand Down
5 changes: 3 additions & 2 deletions classes/form/OrcidProfileStatusForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* @brief Form for site admins to modify ORCID Profile plugin settings
*/

namespace APP\plugins\generic\orcidProfile\classes\form;

import('lib.pkp.classes.form.Form');
import('plugins.generic.orcidProfile.classes.OrcidValidator');
use PKP\form\Form;
use APP\plugins\generic\orcidProfile\classes\OrcidValidator;

class OrcidProfileStatusForm extends Form {

Expand Down
1 change: 0 additions & 1 deletion pages/OrcidHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function authorize($request, &$args, $roleAssignments)
$targetOp = $request->getUserVar('targetOp');
if ($op === 'orcidAuthorize' && in_array($targetOp, ['profile', 'submit'])) {
// ... but user must be logged in for orcidAuthorize with profile or submit
import('lib.pkp.classes.security.authorization.UserRequiredPolicy');
$this->addPolicy(new UserRequiredPolicy($request));
}

Expand Down

0 comments on commit d0d9575

Please sign in to comment.