From d0d957595c3e68e883a758ba2f4f448cbb9a7216 Mon Sep 17 00:00:00 2001 From: withanage Date: Sun, 29 Jan 2023 10:23:41 +0100 Subject: [PATCH] https://github.com/pkp/orcidProfile/issues/229 OrcidProfilePlugin-705 --- OrcidProfilePlugin.inc.php | 16 ++++++++++------ classes/OrcidValidator.inc.php | 1 + classes/form/OrcidProfileSettingsForm.inc.php | 16 +++++++++------- classes/form/OrcidProfileStatusForm.inc.php | 5 +++-- pages/OrcidHandler.inc.php | 1 - 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/OrcidProfilePlugin.inc.php b/OrcidProfilePlugin.inc.php index 53e28d0e..9ceaaa7b 100755 --- a/OrcidProfilePlugin.inc.php +++ b/OrcidProfilePlugin.inc.php @@ -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 { @@ -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; } @@ -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']); @@ -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()) { @@ -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)); diff --git a/classes/OrcidValidator.inc.php b/classes/OrcidValidator.inc.php index 108b8ef5..b4c28f45 100644 --- a/classes/OrcidValidator.inc.php +++ b/classes/OrcidValidator.inc.php @@ -1,5 +1,6 @@ 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); })); } diff --git a/classes/form/OrcidProfileStatusForm.inc.php b/classes/form/OrcidProfileStatusForm.inc.php index bcf413fc..5c3f9f34 100644 --- a/classes/form/OrcidProfileStatusForm.inc.php +++ b/classes/form/OrcidProfileStatusForm.inc.php @@ -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 { diff --git a/pages/OrcidHandler.inc.php b/pages/OrcidHandler.inc.php index ddcf41ae..446bca12 100644 --- a/pages/OrcidHandler.inc.php +++ b/pages/OrcidHandler.inc.php @@ -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)); }