From 1d3f0fb7e47302cc60e1e09844ea38f6dcf63d95 Mon Sep 17 00:00:00 2001 From: Jhon Date: Mon, 26 Feb 2024 16:09:26 -0400 Subject: [PATCH 01/35] Performs first structural changes of adaptation Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- .gitlab-ci.yml | 2 +- ...inc.php => PlauditPreEndorsementPlugin.php | 30 +++++++++++-------- ...p => PlauditPreEndorsementSettingsForm.php | 0 README.md | 6 ++-- ...ssrefClient.inc.php => CrossrefClient.php} | 0 ...Service.inc.php => EndorsementService.php} | 0 .../{OrcidClient.inc.php => OrcidClient.php} | 0 ....inc.php => OrcidCredentialsValidator.php} | 0 ...lauditClient.inc.php => PlauditClient.php} | 0 ...O.inc.php => PlauditPreEndorsementDAO.php} | 0 ...c.php => PlauditPreEndorsementHandler.php} | 0 ...ents.inc.php => SendReadyEndorsements.php} | 0 index.php | 20 ------------- locale/{en_US => en}/emails.po | 0 locale/{en_US => en}/locale.po | 0 locale/{es_ES => es}/emails.po | 0 locale/{es_ES => es}/locale.po | 0 version.xml | 2 +- 18 files changed, 22 insertions(+), 38 deletions(-) rename PlauditPreEndorsementPlugin.inc.php => PlauditPreEndorsementPlugin.php (93%) rename PlauditPreEndorsementSettingsForm.inc.php => PlauditPreEndorsementSettingsForm.php (100%) rename classes/{CrossrefClient.inc.php => CrossrefClient.php} (100%) rename classes/{EndorsementService.inc.php => EndorsementService.php} (100%) rename classes/{OrcidClient.inc.php => OrcidClient.php} (100%) rename classes/{OrcidCredentialsValidator.inc.php => OrcidCredentialsValidator.php} (100%) rename classes/{PlauditClient.inc.php => PlauditClient.php} (100%) rename classes/{PlauditPreEndorsementDAO.inc.php => PlauditPreEndorsementDAO.php} (100%) rename classes/{PlauditPreEndorsementHandler.inc.php => PlauditPreEndorsementHandler.php} (100%) rename classes/tasks/{SendReadyEndorsements.inc.php => SendReadyEndorsements.php} (100%) delete mode 100644 index.php rename locale/{en_US => en}/emails.po (100%) rename locale/{en_US => en}/locale.po (100%) rename locale/{es_ES => es}/emails.po (100%) rename locale/{es_ES => es}/locale.po (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9685d6..5522782 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,4 @@ include: ref: main file: - 'templates/groups/pkp_plugin.yml' - - 'templates/groups/ops_plugins_unit_tests_model.yml' \ No newline at end of file + - 'templates/groups/ops_3_4_plugins_unit_tests_model.yml' \ No newline at end of file diff --git a/PlauditPreEndorsementPlugin.inc.php b/PlauditPreEndorsementPlugin.php similarity index 93% rename from PlauditPreEndorsementPlugin.inc.php rename to PlauditPreEndorsementPlugin.php index 8357567..6cacd43 100644 --- a/PlauditPreEndorsementPlugin.inc.php +++ b/PlauditPreEndorsementPlugin.php @@ -11,7 +11,11 @@ * @brief Plaudit Pre-Endorsement Plugin */ -import('lib.pkp.classes.plugins.GenericPlugin'); +namespace APP\plugins\generic\plauditPreEndorsement; + +use PKP\plugins\GenericPlugin; +use APP\core\Application; +use PKP\plugins\Hook; define('ENDORSEMENT_ORCID_URL', 'https://orcid.org/'); define('ENDORSEMENT_ORCID_URL_SANDBOX', 'https://sandbox.orcid.org/'); @@ -36,21 +40,21 @@ public function register($category, $path, $mainContextId = null) { $success = parent::register($category, $path, $mainContextId); - if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) { - return true; + if (Application::isUnderMaintenance()) { + return $success; } if ($success && $this->getEnabled($mainContextId)) { - HookRegistry::register('Templates::Submission::SubmissionMetadataForm::AdditionalMetadata', array($this, 'addEndorserFieldsToStep3')); - - HookRegistry::register('submissionsubmitstep3form::readuservars', array($this, 'allowStep3FormToReadOurFields')); - HookRegistry::register('submissionsubmitstep3form::validate', array($this, 'validateEndorsement')); - HookRegistry::register('submissionsubmitstep3form::execute', array($this, 'step3SaveEndorserEmail')); - HookRegistry::register('submissionsubmitstep4form::execute', array($this, 'step4SendEmailToEndorser')); - HookRegistry::register('Schema::get::publication', array($this, 'addOurFieldsToPublicationSchema')); - HookRegistry::register('Template::Workflow::Publication', array($this, 'addEndorserFieldsToWorkflow')); - HookRegistry::register('LoadHandler', array($this, 'setupPlauditPreEndorsementHandler')); - HookRegistry::register('AcronPlugin::parseCronTab', array($this, 'addEndorsementTasksToCrontab')); + // Hook::add('Templates::Submission::SubmissionMetadataForm::AdditionalMetadata', [$this, 'addEndorserFieldsToStep3']); + + // Hook::add('submissionsubmitstep3form::readuservars', [$this, 'allowStep3FormToReadOurFields']); + // Hook::add('submissionsubmitstep3form::validate', [$this, 'validateEndorsement']); + // Hook::add('submissionsubmitstep3form::execute', [$this, 'step3SaveEndorserEmail']); + // Hook::add('submissionsubmitstep4form::execute', [$this, 'step4SendEmailToEndorser']); + // Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); + // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); + // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); + // Hook::add('AcronPlugin::parseCronTab', [$this, 'addEndorsementTasksToCrontab']); } return $success; diff --git a/PlauditPreEndorsementSettingsForm.inc.php b/PlauditPreEndorsementSettingsForm.php similarity index 100% rename from PlauditPreEndorsementSettingsForm.inc.php rename to PlauditPreEndorsementSettingsForm.php diff --git a/README.md b/README.md index 68d1d2e..9fd45ba 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This plugin allows authors to pre-endorse their manuscripts before the posting t This plugin is compatible with the following PKP applications: -- OPS 3.3.0-x +- OPS 3.4.0-x ## Installation @@ -26,7 +26,7 @@ After taking this configuration process, the plugin is ready for use. ## License __This plugin is licensed under the GNU General Public License v3.0__ -__Copyright (c) 2022 Lepidus Tecnologia__ +__Copyright (c) 2022 - 2024 Lepidus Tecnologia__ -__Copyright (c) 2022 SciELO__ +__Copyright (c) 2022 - 2024 SciELO__ \ No newline at end of file diff --git a/classes/CrossrefClient.inc.php b/classes/CrossrefClient.php similarity index 100% rename from classes/CrossrefClient.inc.php rename to classes/CrossrefClient.php diff --git a/classes/EndorsementService.inc.php b/classes/EndorsementService.php similarity index 100% rename from classes/EndorsementService.inc.php rename to classes/EndorsementService.php diff --git a/classes/OrcidClient.inc.php b/classes/OrcidClient.php similarity index 100% rename from classes/OrcidClient.inc.php rename to classes/OrcidClient.php diff --git a/classes/OrcidCredentialsValidator.inc.php b/classes/OrcidCredentialsValidator.php similarity index 100% rename from classes/OrcidCredentialsValidator.inc.php rename to classes/OrcidCredentialsValidator.php diff --git a/classes/PlauditClient.inc.php b/classes/PlauditClient.php similarity index 100% rename from classes/PlauditClient.inc.php rename to classes/PlauditClient.php diff --git a/classes/PlauditPreEndorsementDAO.inc.php b/classes/PlauditPreEndorsementDAO.php similarity index 100% rename from classes/PlauditPreEndorsementDAO.inc.php rename to classes/PlauditPreEndorsementDAO.php diff --git a/classes/PlauditPreEndorsementHandler.inc.php b/classes/PlauditPreEndorsementHandler.php similarity index 100% rename from classes/PlauditPreEndorsementHandler.inc.php rename to classes/PlauditPreEndorsementHandler.php diff --git a/classes/tasks/SendReadyEndorsements.inc.php b/classes/tasks/SendReadyEndorsements.php similarity index 100% rename from classes/tasks/SendReadyEndorsements.inc.php rename to classes/tasks/SendReadyEndorsements.php diff --git a/index.php b/index.php deleted file mode 100644 index b8f6aa5..0000000 --- a/index.php +++ /dev/null @@ -1,20 +0,0 @@ - From 8c172b837bea513d0f4b3db7763cbf82498283d7 Mon Sep 17 00:00:00 2001 From: Jhon Date: Mon, 26 Feb 2024 17:38:17 -0400 Subject: [PATCH 02/35] WIP: Adaptation of test classes Also, refactors endorsment constants Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 6 ------ classes/CrossrefClient.php | 4 +++- classes/Endorsement.php | 13 +++++++++++++ classes/OrcidClient.php | 4 ++++ classes/PlauditClient.php | 13 ++++++++----- tests/CrossrefClientTest.php | 4 +--- tests/OrcidClientTest.php | 5 ++--- tests/PlauditClientTest.php | 19 ++++++++++--------- ...{TestResponse.inc.php => TestResponse.php} | 4 +++- tests/{TestStream.inc.php => TestStream.php} | 2 ++ 10 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 classes/Endorsement.php rename tests/{TestResponse.inc.php => TestResponse.php} (76%) rename tests/{TestStream.inc.php => TestStream.php} (78%) diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index 6cacd43..bfe80ad 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -26,12 +26,6 @@ define('ENDORSEMENT_ORCID_API_SCOPE_PUBLIC', '/authenticate'); define('ENDORSEMENT_ORCID_API_SCOPE_MEMBER', '/activities/update'); -define('ENDORSEMENT_STATUS_NOT_CONFIRMED', 0); -define('ENDORSEMENT_STATUS_CONFIRMED', 1); -define('ENDORSEMENT_STATUS_DENIED', 2); -define('ENDORSEMENT_STATUS_COMPLETED', 3); -define('ENDORSEMENT_STATUS_COULDNT_COMPLETE', 4); - class PlauditPreEndorsementPlugin extends GenericPlugin { public const HANDLER_PAGE = 'pre-endorsement-handler'; diff --git a/classes/CrossrefClient.php b/classes/CrossrefClient.php index 36dbe59..72cd3b7 100644 --- a/classes/CrossrefClient.php +++ b/classes/CrossrefClient.php @@ -1,10 +1,12 @@ getStatusCode($headers); diff --git a/classes/Endorsement.php b/classes/Endorsement.php new file mode 100644 index 0000000..bd4bb5a --- /dev/null +++ b/classes/Endorsement.php @@ -0,0 +1,13 @@ +request( 'POST', - PLAUDIT_API_URL, + self::PLAUDIT_API_URL, [ 'headers' => $headers, 'json' => $postData, @@ -48,10 +51,10 @@ public function getEndorsementStatusByResponse($response, $publication) $publicationOrcid = $this->filterOrcidNumbers($publication->getData('endorserOrcid')); if ($responseDoi == $publicationDoi && $responseOrcid == $publicationOrcid) { - return ENDORSEMENT_STATUS_COMPLETED; + return Endorsement::STATUS_COMPLETED; } } - return ENDORSEMENT_STATUS_COULDNT_COMPLETE; + return Endorsement::STATUS_COULDNT_COMPLETE; } } diff --git a/tests/CrossrefClientTest.php b/tests/CrossrefClientTest.php index 3b774ff..f07cdf3 100644 --- a/tests/CrossrefClientTest.php +++ b/tests/CrossrefClientTest.php @@ -1,8 +1,6 @@ orcid\",\"tags\":[]}]}"; $response = new TestResponse($statusOk, $bodyJson); - $this->assertEquals(ENDORSEMENT_STATUS_COMPLETED, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); + $this->assertEquals(Endorsement::STATUS_COMPLETED, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); } public function testEndorsementStatusWhenRequestSucceedButDataDiffs(): void @@ -52,13 +53,13 @@ public function testEndorsementStatusWhenRequestSucceedButDataDiffs(): void $bodyJson = "{\"endorsements\":[{\"doi\":\"10.1590/lepiduspreprints.2022\",\"orcid\":\"$this->orcid\",\"tags\":[]}]}"; $response = new TestResponse($statusOk, $bodyJson); - $this->assertEquals(ENDORSEMENT_STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); + $this->assertEquals(Endorsement::STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); $lowerCaseDoi = strtolower($this->doi); $bodyJson = "{\"endorsements\":[{\"doi\":\"$lowerCaseDoi\",\"orcid\":\"0000-0001-5542-1234\",\"tags\":[]}]}"; $response = new TestResponse($statusOk, $bodyJson); - $this->assertEquals(ENDORSEMENT_STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); + $this->assertEquals(Endorsement::STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); } public function testEndorsementStatusWhenRequestFails(): void @@ -67,6 +68,6 @@ public function testEndorsementStatusWhenRequestFails(): void $bodyJson = ""; $response = new TestResponse($statusBadRequest, $bodyJson); - $this->assertEquals(ENDORSEMENT_STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); + $this->assertEquals(Endorsement::STATUS_COULDNT_COMPLETE, $this->plauditClient->getEndorsementStatusByResponse($response, $this->publication)); } } diff --git a/tests/TestResponse.inc.php b/tests/TestResponse.php similarity index 76% rename from tests/TestResponse.inc.php rename to tests/TestResponse.php index 8399f98..fd2fc6c 100644 --- a/tests/TestResponse.inc.php +++ b/tests/TestResponse.php @@ -1,6 +1,8 @@ Date: Mon, 26 Feb 2024 18:44:23 -0400 Subject: [PATCH 03/35] Adapts Endorsement Service test class Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- tests/EndorsementServiceTest.php | 65 ++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/tests/EndorsementServiceTest.php b/tests/EndorsementServiceTest.php index a38b46b..10063bf 100644 --- a/tests/EndorsementServiceTest.php +++ b/tests/EndorsementServiceTest.php @@ -1,17 +1,21 @@ publication = new Publication(); + $this->publication = $this->createEndorsedPublication(); $this->plugin = new PlauditPreEndorsementPlugin(); $this->endorsementService = new EndorsementService($this->contextId, $this->plugin); } + public function tearDown(): void + { + parent::tearDown(); + $submission = Repo::submission()->get($this->submissionId); + Repo::submission()->delete($submission); + } + protected function getAffectedTables(): array { - return array('event_log', 'event_log_settings', 'plugin_settings', 'publications', 'publication_settings'); + return ['event_log', 'event_log_settings', 'plugin_settings']; } private function createEndorsedPublication(): Publication { + $context = DAORegistry::getDAO('ServerDAO')->getById($this->contextId); + + $submission = new Submission(); + $submission->setData('contextId', $this->contextId); + $publication = new Publication(); $publication->setData('endorserName', $this->endorserName); - $publication->setData('submissionId', $this->submissionId); - $publicationId = DAORegistry::getDAO('PublicationDAO')->insertObject($publication); - $publication->setData('id', $publicationId); + $this->submissionId = Repo::submission()->add($submission, $publication, $context); + + $submission = Repo::submission()->get($this->submissionId); + $publication = $submission->getCurrentPublication(); return $publication; } @@ -97,14 +114,15 @@ private function getMockOrcidClient() private function createEventLog(string $date, string $message) { - $submissionEventLogDao = DAORegistry::getDAO('SubmissionEventLogDAO'); - $entry = $submissionEventLogDao->newDataObject(); - $entry->setData('assocId', $this->submissionId); - $entry->setData('assocType', ASSOC_TYPE_SUBMISSION); - $entry->setData('dateLogged', $date); - $entry->setData('message', $message); - - $submissionEventLogDao->insertObject($entry); + $eventLog = Repo::eventLog()->newDataObject([ + 'assocType' => Application::ASSOC_TYPE_SUBMISSION, + 'assocId' => $this->submissionId, + 'message' => $message, + 'isTranslated' => false, + 'dateLogged' => $date, + ]); + + Repo::eventLog()->add($eventLog); } public function testValidateEndorsementSending(): void @@ -128,14 +146,13 @@ public function testValidateEndorsementSending(): void public function testUpdateEndorserName(): void { - $publication = $this->createEndorsedPublication(); $mockOrcidClient = $this->getMockOrcidClient(); $this->endorsementService->setOrcidClient($mockOrcidClient); - $publication = $this->endorsementService->updateEndorserNameFromOrcid($publication, $this->endorserOrcid); + $this->publication = $this->endorsementService->updateEndorserNameFromOrcid($this->publication, $this->endorserOrcid); $expectedNewName = $this->endorserGivenNameOrcid . ' ' . $this->endorserFamilyNameOrcid; - $this->assertEquals($expectedNewName, $publication->getData('endorserName')); + $this->assertEquals($expectedNewName, $this->publication->getData('endorserName')); } public function testMessageWasAlreadyLoggedToday(): void From e8c03217d40525968da10bf0e1fdf8a2a582b949 Mon Sep 17 00:00:00 2001 From: Jhon Date: Mon, 26 Feb 2024 18:54:53 -0400 Subject: [PATCH 04/35] WIP: Adaptation of endorsement service class Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- classes/EndorsementService.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/classes/EndorsementService.php b/classes/EndorsementService.php index 204d4ac..02641cc 100644 --- a/classes/EndorsementService.php +++ b/classes/EndorsementService.php @@ -1,15 +1,20 @@ getData('submissionId'); if(!$needCheckMessageWasLoggedToday or !$this->messageWasAlreadyLoggedToday($submissionId, $validationResult)) { - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($submissionId); + $submission = Repo::submission()->get($submissionId); $this->plugin->writeOnActivityLog($submission, $validationResult); } } @@ -67,7 +72,7 @@ public function validateEndorsementSending($publication): string public function sendEndorsementToPlaudit($publication) { - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId')); + $submission = Repo::submission()->get($publication->getData('submissionId')); $this->plugin->writeOnActivityLog($submission, 'plugins.generic.plauditPreEndorsement.log.attemptSendingEndorsement', ['doi' => $publication->getData('pub-id::doi'), 'orcid' => $publication->getData('endorserOrcid')]); $plauditClient = new PlauditClient(); @@ -85,9 +90,9 @@ public function sendEndorsementToPlaudit($publication) $newEndorsementStatus = ENDORSEMENT_STATUS_COULDNT_COMPLETE; } - $publication->setData('endorsementStatus', $newEndorsementStatus); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + Repo::publication()->edit($publication, [ + 'endorsementStatus' => $newEndorsementStatus + ]); } public function updateEndorserNameFromOrcid($publication, $orcid) @@ -97,15 +102,16 @@ public function updateEndorserNameFromOrcid($publication, $orcid) $fullName = $this->orcidClient->getFullNameFromRecord($orcidRecord); $publication->setData('endorserName', $fullName); - DAORegistry::getDAO('PublicationDAO')->updateObject($publication); + Repo::publication()->edit($publication, []); return $publication; } public function messageWasAlreadyLoggedToday(int $submissionId, string $message): bool { - $submissionEventLogDao = DAORegistry::getDAO('SubmissionEventLogDAO'); - $submissionLogEntries = $submissionEventLogDao->getBySubmissionId($submissionId); + $submissionLogEntries = Repo::eventLog()->getCollector() + ->filterByAssoc(Application::ASSOC_TYPE_SUBMISSION, [$submissionId]) + ->getMany(); $today = Core::getCurrentDate(); foreach($submissionLogEntries->toArray() as $logEntry) { From 42b758fead02e3e198d2840421362586203e43a0 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 28 Feb 2024 12:15:31 -0400 Subject: [PATCH 05/35] Fixes plugin setting removing in test class Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- tests/EndorsementServiceTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/EndorsementServiceTest.php b/tests/EndorsementServiceTest.php index 10063bf..541e35c 100644 --- a/tests/EndorsementServiceTest.php +++ b/tests/EndorsementServiceTest.php @@ -38,11 +38,14 @@ public function tearDown(): void parent::tearDown(); $submission = Repo::submission()->get($this->submissionId); Repo::submission()->delete($submission); + + $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); + $pluginSettingsDao->deleteSetting($this->contextId, $this->plugin->getName(), 'plauditAPISecret'); } protected function getAffectedTables(): array { - return ['event_log', 'event_log_settings', 'plugin_settings']; + return ['event_log', 'event_log_settings']; } private function createEndorsedPublication(): Publication From 6be86b3436422ee80855f5330582354d985b004f Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 14:59:18 -0400 Subject: [PATCH 06/35] Endorsement service class passes in tests Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- classes/EndorsementService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/EndorsementService.php b/classes/EndorsementService.php index 02641cc..3f0c6c6 100644 --- a/classes/EndorsementService.php +++ b/classes/EndorsementService.php @@ -102,7 +102,8 @@ public function updateEndorserNameFromOrcid($publication, $orcid) $fullName = $this->orcidClient->getFullNameFromRecord($orcidRecord); $publication->setData('endorserName', $fullName); - Repo::publication()->edit($publication, []); + $publicationDao = Repo::publication()->dao; + $publicationDao->update($publication); return $publication; } From 1f05fb912e5f789b76c7a7fd55387aca7e1cbc5a Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 15:14:36 -0400 Subject: [PATCH 07/35] Adapts handler test class Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- tests/PlauditPreEndorsementHandlerTest.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/PlauditPreEndorsementHandlerTest.php b/tests/PlauditPreEndorsementHandlerTest.php index 399d8fa..e93e874 100644 --- a/tests/PlauditPreEndorsementHandlerTest.php +++ b/tests/PlauditPreEndorsementHandlerTest.php @@ -1,11 +1,9 @@ publication->setData('endorserEmail', $this->endorserEmail); $this->publication->setData('endorserName', $this->endorserName); $this->publication->setData('endorserEmailToken', $this->endorserEmailToken); - $this->publication->setData('endorsementStatus', ENDORSEMENT_STATUS_NOT_CONFIRMED); + $this->publication->setData('endorsementStatus', Endorsement::STATUS_NOT_CONFIRMED); return $this->publication; } @@ -53,19 +51,19 @@ private function verifyEndorserAuth($token, $error = null): string public function testEndorserAuthenticatesCorrectly(): void { $result = $this->verifyEndorserAuth($this->endorserEmailToken); - $this->assertEquals(AUTH_SUCCESS, $result); + $this->assertEquals(PlauditPreEndorsementHandler::AUTH_SUCCESS, $result); } public function testEndorserTokenIsDifferent(): void { $diffToken = md5(microtime() . 'email@email.com'); $result = $this->verifyEndorserAuth($diffToken); - $this->assertEquals(AUTH_INVALID_TOKEN, $result); + $this->assertEquals(PlauditPreEndorsementHandler::AUTH_INVALID_TOKEN, $result); } public function testEndorserAutheticationHasAccessDenied(): void { $result = $this->verifyEndorserAuth($this->endorserEmailToken, 'access_denied'); - $this->assertEquals(AUTH_ACCESS_DENIED, $result); + $this->assertEquals(PlauditPreEndorsementHandler::AUTH_ACCESS_DENIED, $result); } } From f7762d40cf7ff91c9572f1e2ff9cfe225ce4b79c Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 15:42:38 -0400 Subject: [PATCH 08/35] Finishes adapting of handler class Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 9 --- classes/OrcidClient.php | 9 +++ classes/PlauditPreEndorsementHandler.php | 81 ++++++++++++------------ 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index bfe80ad..ba83e16 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -17,15 +17,6 @@ use APP\core\Application; use PKP\plugins\Hook; -define('ENDORSEMENT_ORCID_URL', 'https://orcid.org/'); -define('ENDORSEMENT_ORCID_URL_SANDBOX', 'https://sandbox.orcid.org/'); -define('ENDORSEMENT_ORCID_API_URL_PUBLIC', 'https://pub.orcid.org/'); -define('ENDORSEMENT_ORCID_API_URL_PUBLIC_SANDBOX', 'https://pub.sandbox.orcid.org/'); -define('ENDORSEMENT_ORCID_API_URL_MEMBER', 'https://api.orcid.org/'); -define('ENDORSEMENT_ORCID_API_URL_MEMBER_SANDBOX', 'https://api.sandbox.orcid.org/'); -define('ENDORSEMENT_ORCID_API_SCOPE_PUBLIC', '/authenticate'); -define('ENDORSEMENT_ORCID_API_SCOPE_MEMBER', '/activities/update'); - class PlauditPreEndorsementPlugin extends GenericPlugin { public const HANDLER_PAGE = 'pre-endorsement-handler'; diff --git a/classes/OrcidClient.php b/classes/OrcidClient.php index a254e53..ce6cf3d 100644 --- a/classes/OrcidClient.php +++ b/classes/OrcidClient.php @@ -6,6 +6,15 @@ class OrcidClient { + public const ORCID_URL = 'https://orcid.org/'; + public const ORCID_URL_SANDBOX = 'https://sandbox.orcid.org/'; + public const ORCID_API_URL_PUBLIC = 'https://pub.orcid.org/'; + public const ORCID_API_URL_PUBLIC_SANDBOX = 'https://pub.sandbox.orcid.org/'; + public const ORCID_API_URL_MEMBER = 'https://api.orcid.org/'; + public const ORCID_API_URL_MEMBER_SANDBOX = 'https://api.sandbox.orcid.org/'; + public const ORCID_API_SCOPE_PUBLIC = '/authenticate'; + public const ORCID_API_SCOPE_MEMBER = '/activities/update'; + private $plugin; private $contextId; diff --git a/classes/PlauditPreEndorsementHandler.php b/classes/PlauditPreEndorsementHandler.php index 095c7ae..d554cd4 100644 --- a/classes/PlauditPreEndorsementHandler.php +++ b/classes/PlauditPreEndorsementHandler.php @@ -1,16 +1,23 @@ getUserVar('endorserName'); $endorserEmail = $request->getUserVar('endorserEmail'); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($submissionId); + $submission = Repo::submission()->get($submissionId); $publication = $submission->getCurrentPublication(); - $endorsementIsConfirmed = $publication->getData('endorsementStatus') == ENDORSEMENT_STATUS_CONFIRMED; + $endorsementIsConfirmed = $publication->getData('endorsementStatus') == Endorsement::STATUS_CONFIRMED; if ($endorsementIsConfirmed) { return http_response_code(400); } @@ -42,10 +49,10 @@ public function updateEndorser($args, $request) $endorserChanged = ($endorserEmail != $publication->getData('endorserEmail')); - $publication->setData('endorserName', $endorserName); - $publication->setData('endorserEmail', $endorserEmail); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + Repo::publication()->edit($publication, [ + 'endorserName' => $endorserName, + 'endorserEmail' => $endorserEmail + ]); $plugin->sendEmailToEndorser($publication, $endorserChanged); @@ -68,7 +75,7 @@ private function checkDataIsFromAnyAuthor($publication, $dataName, $dataValue): public function removeEndorsement($args, $request) { $submissionId = $request->getUserVar('submissionId'); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($submissionId); + $submission = Repo::submission()->get($submissionId); $publication = $submission->getCurrentPublication(); $endorsementFields = [ @@ -84,8 +91,7 @@ public function removeEndorsement($args, $request) $publication->unsetData($field); } - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + Repo::publication()->edit($publication, []); $plugin = PluginRegistry::getPlugin('generic', 'plauditpreendorsementplugin'); $plugin->writeOnActivityLog($submission, 'plugins.generic.plauditPreEndorsement.log.endorsementRemoved'); @@ -96,14 +102,14 @@ public function removeEndorsement($args, $request) public function sendEndorsementManually($args, $request) { $submissionId = $request->getUserVar('submissionId'); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($submissionId); + $submission = Repo::submission()->get($submissionId); $publication = $submission->getCurrentPublication(); $plugin = PluginRegistry::getPlugin('generic', 'plauditpreendorsementplugin'); $endorsementStatus = $publication->getData('endorsementStatus'); - $canSendEndorsementManually = $publication->getData('status') === STATUS_PUBLISHED + $canSendEndorsementManually = $publication->getData('status') == Submission::STATUS_PUBLISHED && !$plugin->userAccessingIsAuthor($submission) - && ($endorsementStatus == ENDORSEMENT_STATUS_CONFIRMED || $endorsementStatus == ENDORSEMENT_STATUS_COULDNT_COMPLETE); + && ($endorsementStatus == Endorsement::STATUS_CONFIRMED || $endorsementStatus == Endorsement::STATUS_COULDNT_COMPLETE); if($canSendEndorsementManually) { $endorsementService = new EndorsementService($request->getContext()->getId(), $plugin); @@ -116,18 +122,17 @@ public function sendEndorsementManually($args, $request) public function orcidVerify($args, $request) { - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publication = $publicationDao->getById($request->getUserVar('state')); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId')); + $publication = Repo::publication()->get($request->getUserVar('state')); + $submission = Repo::submission()->get($publication->getData('submissionId')); $plugin = PluginRegistry::getPlugin('generic', 'plauditpreendorsementplugin'); $contextId = $request->getContext()->getId(); $statusAuth = $this->getStatusAuthentication($publication, $request); - if ($statusAuth == AUTH_INVALID_TOKEN) { + if ($statusAuth == self::AUTH_INVALID_TOKEN) { $this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.invalidToken', ['errorType' => 'invalidToken']); return; - } elseif ($statusAuth == AUTH_ACCESS_DENIED) { + } elseif ($statusAuth == self::AUTH_ACCESS_DENIED) { $this->setAccessDeniedEndorsement($publication); $this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidAccessDenied', ['errorType' => 'denied']); return; @@ -137,14 +142,14 @@ public function orcidVerify($args, $request) $code = $request->getUserVar('code'); $orcidClient = new OrcidClient($plugin, $contextId); $orcid = $orcidClient->requestOrcid($code); - } catch (GuzzleHttp\Exception\RequestException $exception) { + } catch (\GuzzleHttp\Exception\RequestException $exception) { $this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidRequestError', ['errorType' => 'failure', 'orcidAPIError' => $exception->getMessage()]); return; } - $isSandBox = $plugin->getSetting($contextId, 'orcidAPIPath') == ENDORSEMENT_ORCID_API_URL_MEMBER_SANDBOX || - $plugin->getSetting($contextId, 'orcidAPIPath') == ENDORSEMENT_ORCID_API_URL_PUBLIC_SANDBOX; - $orcidUri = ($isSandBox ? ENDORSEMENT_ORCID_URL_SANDBOX : ENDORSEMENT_ORCID_URL) . $orcid; + $isSandBox = $plugin->getSetting($contextId, 'orcidAPIPath') == OrcidClient::ORCID_API_URL_MEMBER_SANDBOX || + $plugin->getSetting($contextId, 'orcidAPIPath') == OrcidClient::ORCID_API_URL_PUBLIC_SANDBOX; + $orcidUri = ($isSandBox ? OrcidClient::ORCID_URL_SANDBOX : OrcidClient::ORCID_URL) . $orcid; if (strlen($orcid) > 0) { if($this->checkDataIsFromAnyAuthor($publication, 'orcid', $orcidUri)) { @@ -158,7 +163,7 @@ public function orcidVerify($args, $request) $this->setConfirmedEndorsementPublication($publication, $orcidUri); $this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.endorsementConfirmed', ['orcid' => $orcidUri]); - if($publication->getData('status') === STATUS_PUBLISHED) { + if($publication->getData('status') == Submission::STATUS_PUBLISHED) { $endorsementService->sendEndorsement($publication); } } @@ -180,27 +185,25 @@ private function setConfirmedEndorsementPublication($publication, $orcidUri) { $publication->setData('endorserEmailToken', null); $publication->setData('endorserOrcid', $orcidUri); - $publication->setData('endorsementStatus', ENDORSEMENT_STATUS_CONFIRMED); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + $publication->setData('endorsementStatus', Endorsement::STATUS_CONFIRMED); + Repo::publication()->edit($publication, []); } private function setAccessDeniedEndorsement($publication) { $publication->setData('endorserEmailToken', null); - $publication->setData('endorsementStatus', ENDORSEMENT_STATUS_DENIED); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + $publication->setData('endorsementStatus', Endorsement::STATUS_DENIED); + Repo::publication()->edit($publication, []); } public function getStatusAuthentication($publication, $request) { if ($request->getUserVar('token') != $publication->getData('endorserEmailToken')) { - return AUTH_INVALID_TOKEN; + return self::AUTH_INVALID_TOKEN; } elseif ($request->getUserVar('error') == 'access_denied') { - return AUTH_ACCESS_DENIED; + return self::AUTH_ACCESS_DENIED; } else { - return AUTH_SUCCESS; + return self::AUTH_SUCCESS; } } } From 2f01b3181a745b7bee0cb2d77b43526ba6c003e2 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 15:48:22 -0400 Subject: [PATCH 09/35] Formats classes Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- classes/OrcidClient.php | 2 +- classes/PlauditPreEndorsementHandler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/OrcidClient.php b/classes/OrcidClient.php index ce6cf3d..ba81f62 100644 --- a/classes/OrcidClient.php +++ b/classes/OrcidClient.php @@ -14,7 +14,7 @@ class OrcidClient public const ORCID_API_URL_MEMBER_SANDBOX = 'https://api.sandbox.orcid.org/'; public const ORCID_API_SCOPE_PUBLIC = '/authenticate'; public const ORCID_API_SCOPE_MEMBER = '/activities/update'; - + private $plugin; private $contextId; diff --git a/classes/PlauditPreEndorsementHandler.php b/classes/PlauditPreEndorsementHandler.php index d554cd4..4044646 100644 --- a/classes/PlauditPreEndorsementHandler.php +++ b/classes/PlauditPreEndorsementHandler.php @@ -17,7 +17,7 @@ class PlauditPreEndorsementHandler extends Handler public const AUTH_SUCCESS = 'success'; public const AUTH_INVALID_TOKEN = 'invalid_token'; public const AUTH_ACCESS_DENIED = 'access_denied'; - + public function updateEndorser($args, $request) { $plugin = new PlauditPreEndorsementPlugin(); From 0e23b00606dfd06f08d398ac350dca1cf91d2bce Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 16:09:32 -0400 Subject: [PATCH 10/35] Plugin can already be enabled Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- .gitlab-ci.yml | 3 ++- PlauditPreEndorsementPlugin.php | 16 +++++++++------- cypress/tests/Test0_pluginSetup.cy.js | 13 +++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 cypress/tests/Test0_pluginSetup.cy.js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5522782..e6a606e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,5 @@ include: ref: main file: - 'templates/groups/pkp_plugin.yml' - - 'templates/groups/ops_3_4_plugins_unit_tests_model.yml' \ No newline at end of file + - 'templates/groups/ops_3_4_plugins_unit_tests_model.yml' + - 'templates/groups/ops_3_4_plugins_cypress_tests_model.yml' \ No newline at end of file diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index ba83e16..dac993c 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -3,7 +3,7 @@ /** * @file plugins/generic/plaudit/PlauditPreEndorsementPlugin.inc.php * - * Copyright (c) 2022 Lepidus Tecnologia + * Copyright (c) 2022 - 2024 Lepidus Tecnologia * Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt. * * @class PlauditPreEndorsementPlugin @@ -16,6 +16,10 @@ use PKP\plugins\GenericPlugin; use APP\core\Application; use PKP\plugins\Hook; +use PKP\linkAction\LinkAction; +use PKP\linkAction\request\AjaxModal; +use APP\plugins\generic\plauditPreEndorsement\classes\OrcidClient; +use APP\plugins\generic\plauditPreEndorsement\PlauditPreEndorsementSettingsForm; class PlauditPreEndorsementPlugin extends GenericPlugin { @@ -305,7 +309,6 @@ public function orcidIsGloballyConfigured() public function getActions($request, $actionArgs) { $router = $request->getRouter(); - import('lib.pkp.classes.linkAction.request.AjaxModal'); return array_merge( array( new LinkAction( @@ -329,14 +332,13 @@ public function manage($args, $request) $templateMgr = TemplateManager::getManager(); $templateMgr->registerPlugin('function', 'plugin_url', array($this, 'smartyPluginUrl')); $apiOptions = [ - ENDORSEMENT_ORCID_API_URL_PUBLIC => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.public', - ENDORSEMENT_ORCID_API_URL_PUBLIC_SANDBOX => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.publicSandbox', - ENDORSEMENT_ORCID_API_URL_MEMBER => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.member', - ENDORSEMENT_ORCID_API_URL_MEMBER_SANDBOX => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.memberSandbox' + OrcidClient::ORCID_API_URL_PUBLIC => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.public', + OrcidClient::ORCID_API_URL_PUBLIC_SANDBOX => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.publicSandbox', + OrcidClient::ORCID_API_URL_MEMBER => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.member', + OrcidClient::ORCID_API_URL_MEMBER_SANDBOX => 'plugins.generic.plauditPreEndorsement.settings.orcidAPIPath.memberSandbox' ]; $templateMgr->assign('orcidApiUrls', $apiOptions); - $this->import('PlauditPreEndorsementSettingsForm'); $form = new PlauditPreEndorsementSettingsForm($this, $contextId); if ($request->getUserVar('save')) { $form->readInputData(); diff --git a/cypress/tests/Test0_pluginSetup.cy.js b/cypress/tests/Test0_pluginSetup.cy.js new file mode 100644 index 0000000..d1c46fb --- /dev/null +++ b/cypress/tests/Test0_pluginSetup.cy.js @@ -0,0 +1,13 @@ +describe('Plaudit Pre-endorsement - Plugin setup', function () { + it('Enables Plaudit Pre-endorsement plugin', function () { + cy.login('dbarnes', null, 'publicknowledge'); + + cy.contains('a', 'Website').click(); + + cy.waitJQuery(); + cy.get('#plugins-button').click(); + + cy.get('input[id^=select-cell-plauditpreendorsementplugin]').check(); + cy.get('input[id^=select-cell-plauditpreendorsementplugin]').should('be.checked'); + }); +}); \ No newline at end of file From cafa9bb9722455ebc2fae7a50c90595254a0b4fe Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 18:25:06 -0400 Subject: [PATCH 11/35] Adds integration test for endorser fields at submission wizard Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- cypress/testlist.md | 9 +++ .../Test1_endorserFieldsSubmission.cy.js | 55 ++++++++++++++++++ cypress/tests/Test1_sendEndorserEmail.spec.js | 56 ------------------- 3 files changed, 64 insertions(+), 56 deletions(-) create mode 100644 cypress/testlist.md create mode 100644 cypress/tests/Test1_endorserFieldsSubmission.cy.js delete mode 100644 cypress/tests/Test1_sendEndorserEmail.spec.js diff --git a/cypress/testlist.md b/cypress/testlist.md new file mode 100644 index 0000000..ee6b7f9 --- /dev/null +++ b/cypress/testlist.md @@ -0,0 +1,9 @@ +- Fluxo de submissão + - Presença dos campos de inserção de nome e e-mail de endossador durante submissão + +- Fluxo de trabalho + - Exibição do contador de e-mails enviados ao endossador + - Exibição das mensagens no histórico de atividades da submissão + - Presença da _badge_ na aba do endosso + - Remoção do endosso + - Readição do endosso. Verificação que endosso não é de contribuidores da submissão \ No newline at end of file diff --git a/cypress/tests/Test1_endorserFieldsSubmission.cy.js b/cypress/tests/Test1_endorserFieldsSubmission.cy.js new file mode 100644 index 0000000..e607374 --- /dev/null +++ b/cypress/tests/Test1_endorserFieldsSubmission.cy.js @@ -0,0 +1,55 @@ +function beginSubmission(submissionData) { + cy.get('input[name="locale"][value="en"]').click(); + cy.setTinyMceContent('startSubmission-title-control', submissionData.title); + + cy.get('input[name="submissionRequirements"]').check(); + cy.get('input[name="privacyConsent"]').check(); + cy.contains('button', 'Begin Submission').click(); +} + +describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard", function() { + let submissionData; + let dummyPdf; + + before(function() { + Cypress.config('defaultCommandTimeout', 4000); + submissionData = { + title: "Killers of the Flower Moon", + abstract: 'A series of murders starts among native americans', + }; + dummyPdf = { + 'file': 'dummy.pdf', + 'fileName': 'dummy.pdf', + 'mimeType': 'application/pdf', + 'genre': 'Preprint Text' + }; + }); + + it("Author user submits endorsed submission", function() { + cy.login('ckwantes', null, 'publicknowledge'); + cy.get('div#myQueue a:contains("New Submission")').click(); + + beginSubmission(submissionData); + + cy.contains('h2', 'Endorsement'); + cy.contains('Do you have the endorsement of an experienced researcher in the field of knowledge of the manuscript?'); + cy.contains('If yes, please provide the name and e-mail address of the endorsing researcher. Endorsements can significantly speed up the moderation process.'); + cy.contains('The endorsement cannot be given by one of the authors of the manuscript.'); + + cy.get('input[name="endorserName"]').clear().type(endorserName, {delay: 0}); + cy.get('input[name="endorserEmail"]').clear().type(endorserEmail, {delay: 0}); + cy.contains('button', 'Continue').click(); + + cy.addSubmissionGalleys([dummyPdf]); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + + cy.contains('button', 'Submit').click(); + cy.get('.modal__panel:visible').within(() => { + cy.contains('button', 'Submit').click(); + }); + cy.waitJQuery(); + cy.contains('h1', 'Submission complete'); + }); +}); \ No newline at end of file diff --git a/cypress/tests/Test1_sendEndorserEmail.spec.js b/cypress/tests/Test1_sendEndorserEmail.spec.js deleted file mode 100644 index e7ff55c..0000000 --- a/cypress/tests/Test1_sendEndorserEmail.spec.js +++ /dev/null @@ -1,56 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; - -function submissionStep1() { - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test send e-mail to endorser", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); - cy.contains("Your submission has been uploaded and is ready to be sent."); - - cy.get('a:contains("3. Enter Metadata")').click(); - cy.wait(1000); - cy.get('input[name="endorserName"]').type("Queen Elizabeth", { delay: 0 }); - cy.get('input[name="endorserEmail"]').type("queen.elizabeth.2nd@gmail.com", { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); - cy.wait(1000); -} - -function submissionStep4() { - cy.get('#submitStep4Form > .formButtons > .submitFormButton').click(); - cy.get('.pkp_modal_confirmation > .footer > .ok').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Send e-mail to endorser during submission", function() { - it("Author user submits endorsed submission", function() { - cy.login('ckwantes', null, 'publicknowledge'); - - cy.get('div#myQueue a:contains("New Submission")').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - submissionStep4(); - }); - it("Check if e-mail has been sent to endorser", function() { - cy.visit('http://0.0.0.0:8025/'); - - cy.contains('Endorsement confirmation').first().click(); - cy.contains('Queen Elizabeth '); - }); -}); \ No newline at end of file From e055cb7d85a55d33482724cc037c24d28e173fe2 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 29 Feb 2024 18:54:17 -0400 Subject: [PATCH 12/35] Adds endorser form Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- classes/components/forms/EndorserForm.php | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 classes/components/forms/EndorserForm.php diff --git a/classes/components/forms/EndorserForm.php b/classes/components/forms/EndorserForm.php new file mode 100644 index 0000000..1503dac --- /dev/null +++ b/classes/components/forms/EndorserForm.php @@ -0,0 +1,28 @@ +action = $action; + + $this->addField(new FieldText('endorserName', [ + 'label' => __('plugins.generic.plauditPreEndorsement.endorserName'), + 'value' => $publication->getData('endorserName'), + ])); + + $this->addField(new FieldText('endorserEmail', [ + 'label' => __('plugins.generic.plauditPreEndorsement.endorserEmail'), + 'value' => $publication->getData('endorserEmail'), + ])); + } +} From f1640c7855528309699227eab7d84479bb418005 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 1 Mar 2024 11:36:45 -0400 Subject: [PATCH 13/35] Adds endorsement form on submission wizard Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 75 ++++++++++++++++--- .../{EndorserForm.php => EndorsementForm.php} | 4 +- .../Test1_endorserFieldsSubmission.cy.js | 5 +- 3 files changed, 70 insertions(+), 14 deletions(-) rename classes/components/forms/{EndorserForm.php => EndorsementForm.php} (90%) diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index dac993c..835e77c 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -18,7 +18,9 @@ use PKP\plugins\Hook; use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxModal; +use APP\pages\submission\SubmissionHandler; use APP\plugins\generic\plauditPreEndorsement\classes\OrcidClient; +use APP\plugins\generic\plauditPreEndorsement\classes\components\forms\EndorsementForm; use APP\plugins\generic\plauditPreEndorsement\PlauditPreEndorsementSettingsForm; class PlauditPreEndorsementPlugin extends GenericPlugin @@ -34,13 +36,14 @@ public function register($category, $path, $mainContextId = null) } if ($success && $this->getEnabled($mainContextId)) { + Hook::add('TemplateManager::display', [$this, 'modifySubmissionSteps']); + Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); // Hook::add('Templates::Submission::SubmissionMetadataForm::AdditionalMetadata', [$this, 'addEndorserFieldsToStep3']); // Hook::add('submissionsubmitstep3form::readuservars', [$this, 'allowStep3FormToReadOurFields']); // Hook::add('submissionsubmitstep3form::validate', [$this, 'validateEndorsement']); // Hook::add('submissionsubmitstep3form::execute', [$this, 'step3SaveEndorserEmail']); // Hook::add('submissionsubmitstep4form::execute', [$this, 'step4SendEmailToEndorser']); - // Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); // Hook::add('AcronPlugin::parseCronTab', [$this, 'addEndorsementTasksToCrontab']); @@ -49,6 +52,16 @@ public function register($category, $path, $mainContextId = null) return $success; } + public function getDisplayName() + { + return __('plugins.generic.plauditPreEndorsement.displayName'); + } + + public function getDescription() + { + return __('plugins.generic.plauditPreEndorsement.description'); + } + public function setupPlauditPreEndorsementHandler($hookName, $params) { $page = $params[0]; @@ -67,16 +80,6 @@ public function addEndorsementTasksToCrontab($hookName, $params) return false; } - public function getDisplayName() - { - return __('plugins.generic.plauditPreEndorsement.displayName'); - } - - public function getDescription() - { - return __('plugins.generic.plauditPreEndorsement.description'); - } - public function writeOnActivityLog($submission, $message, $messageParams = array()) { $request = Application::get()->getRequest(); @@ -88,6 +91,56 @@ public function inputIsEmail(string $input): bool return filter_var($input, FILTER_VALIDATE_EMAIL); } + public function modifySubmissionSteps($hookName, $params) + { + $request = Application::get()->getRequest(); + $context = $request->getContext(); + $templateMgr = $params[0]; + + if ($request->getRequestedPage() != 'submission' || $request->getRequestedOp() == 'saved') { + return false; + } + + $submission = $request + ->getRouter() + ->getHandler() + ->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION); + + if (!$submission || !$submission->getData('submissionProgress')) { + return false; + } + + $publication = $submission->getCurrentPublication(); + $publicationApiUrl = $request->getDispatcher()->url( + $request, + Application::ROUTE_API, + $request->getContext()->getPath(), + 'submissions/' . $submission->getId() . '/publications/' . $publication->getId() + ); + $endorsementForm = new EndorsementForm( + $publicationApiUrl, + $publication, + ); + + $steps = $templateMgr->getState('steps'); + $steps = array_map(function ($step) use ($endorsementForm) { + if ($step['id'] == 'details') { + $step['sections'][] = [ + 'id' => 'endorsement', + 'name' => __('plugins.generic.plauditPreEndorsement.endorsement'), + 'description' => __('plugins.generic.plauditPreEndorsement.endorsement.description'), + 'type' => SubmissionHandler::SECTION_TYPE_FORM, + 'form' => $endorsementForm->getConfig(), + ]; + } + return $step; + }, $steps); + + $templateMgr->setState(['steps' => $steps]); + + return false; + } + public function validateEndorsement($hookName, $params) { $form = & $params[0]; diff --git a/classes/components/forms/EndorserForm.php b/classes/components/forms/EndorsementForm.php similarity index 90% rename from classes/components/forms/EndorserForm.php rename to classes/components/forms/EndorsementForm.php index 1503dac..b33cb76 100644 --- a/classes/components/forms/EndorserForm.php +++ b/classes/components/forms/EndorsementForm.php @@ -6,9 +6,9 @@ use PKP\components\forms\FieldText; use APP\publication\Publication; -class EndorserForm extends FormComponent +class EndorsementForm extends FormComponent { - public $id = 'endorserForm'; + public $id = 'endorsementForm'; public $method = 'PUT'; public function __construct(string $action, Publication $publication) diff --git a/cypress/tests/Test1_endorserFieldsSubmission.cy.js b/cypress/tests/Test1_endorserFieldsSubmission.cy.js index e607374..dc1212c 100644 --- a/cypress/tests/Test1_endorserFieldsSubmission.cy.js +++ b/cypress/tests/Test1_endorserFieldsSubmission.cy.js @@ -10,6 +10,8 @@ function beginSubmission(submissionData) { describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard", function() { let submissionData; let dummyPdf; + let endorserName = 'Bong Joon-ho'; + let endorserEmail = 'bong.joon-ho@email.kr'; before(function() { Cypress.config('defaultCommandTimeout', 4000); @@ -30,7 +32,8 @@ describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard" cy.get('div#myQueue a:contains("New Submission")').click(); beginSubmission(submissionData); - + + cy.setTinyMceContent('titleAbstract-abstract-control-en', submissionData.abstract); cy.contains('h2', 'Endorsement'); cy.contains('Do you have the endorsement of an experienced researcher in the field of knowledge of the manuscript?'); cy.contains('If yes, please provide the name and e-mail address of the endorsing researcher. Endorsements can significantly speed up the moderation process.'); From d336a7704c0b5427a8d2ade181224e5a5749f651 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 1 Mar 2024 11:43:46 -0400 Subject: [PATCH 14/35] Removes code formerly responsible for adding fields to submission wizard Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 40 -------------------- classes/components/forms/EndorsementForm.php | 1 + templates/endorserFieldStep3.tpl | 13 ------- 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 templates/endorserFieldStep3.tpl diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index 835e77c..88ae46f 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -38,11 +38,8 @@ public function register($category, $path, $mainContextId = null) if ($success && $this->getEnabled($mainContextId)) { Hook::add('TemplateManager::display', [$this, 'modifySubmissionSteps']); Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); - // Hook::add('Templates::Submission::SubmissionMetadataForm::AdditionalMetadata', [$this, 'addEndorserFieldsToStep3']); - // Hook::add('submissionsubmitstep3form::readuservars', [$this, 'allowStep3FormToReadOurFields']); // Hook::add('submissionsubmitstep3form::validate', [$this, 'validateEndorsement']); - // Hook::add('submissionsubmitstep3form::execute', [$this, 'step3SaveEndorserEmail']); // Hook::add('submissionsubmitstep4form::execute', [$this, 'step4SendEmailToEndorser']); // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); @@ -167,43 +164,6 @@ public function validateEndorsement($hookName, $params) } } - public function addEndorserFieldsToStep3($hookName, $params) - { - $smarty = &$params[1]; - $output = &$params[2]; - - $submissionId = $smarty->smarty->get_template_vars('submissionId'); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($submissionId); - $publication = $submission->getCurrentPublication(); - - $smarty->assign('endorserName', $publication->getData('endorserName')); - $smarty->assign('endorserEmail', $publication->getData('endorserEmail')); - - $output .= $smarty->fetch($this->getTemplateResource('endorserFieldStep3.tpl')); - return false; - } - - public function allowStep3FormToReadOurFields($hookName, $params) - { - $formFields = &$params[1]; - $ourFields = ['endorserName', 'endorserEmail']; - - $formFields = array_merge($formFields, $ourFields); - } - - public function step3SaveEndorserEmail($hookName, $params) - { - $step3Form = $params[0]; - $publication = $step3Form->submission->getCurrentPublication(); - $endorserName = $step3Form->getData('endorserName'); - $endorserEmail = $step3Form->getData('endorserEmail'); - - $publication->setData('endorserName', $endorserName); - $publication->setData('endorserEmail', $endorserEmail); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); - } - public function step4SendEmailToEndorser($hookName, $params) { $step4Form = $params[0]; diff --git a/classes/components/forms/EndorsementForm.php b/classes/components/forms/EndorsementForm.php index b33cb76..8df7305 100644 --- a/classes/components/forms/EndorsementForm.php +++ b/classes/components/forms/EndorsementForm.php @@ -23,6 +23,7 @@ public function __construct(string $action, Publication $publication) $this->addField(new FieldText('endorserEmail', [ 'label' => __('plugins.generic.plauditPreEndorsement.endorserEmail'), 'value' => $publication->getData('endorserEmail'), + 'inputType' => 'email' ])); } } diff --git a/templates/endorserFieldStep3.tpl b/templates/endorserFieldStep3.tpl deleted file mode 100644 index f81b3a2..0000000 --- a/templates/endorserFieldStep3.tpl +++ /dev/null @@ -1,13 +0,0 @@ -{* - * Copyright (c) 2022 Lepidus Tecnologia - * Copyright (c) 2022 SciELO - * Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt - * - *} - - - -{fbvFormSection id="endorserSection" label="plugins.generic.plauditPreEndorsement.endorsement" description="plugins.generic.plauditPreEndorsement.endorsement.description"} - {fbvElement type="text" label="plugins.generic.plauditPreEndorsement.endorserName" name="endorserName" id="endorserName" value=$endorserName|escape size=$fbvStyles.size.MEDIUM} - {fbvElement type="email" label="plugins.generic.plauditPreEndorsement.endorserEmail" name="endorserEmail" id="endorserEmail" value=$endorserEmail|escape maxlength="90" size=$fbvStyles.size.MEDIUM} -{/fbvFormSection} \ No newline at end of file From 88d5cb706019455154dcaae6ba60dec08795b919 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 1 Mar 2024 14:32:02 -0400 Subject: [PATCH 15/35] Updates integration test to check for endorsement validation Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- cypress/support/commands.js | 7 +++ .../Test1_endorserFieldsSubmission.cy.js | 53 ++++++++++++++++--- 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 cypress/support/commands.js diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 0000000..d3c3c77 --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,7 @@ +Cypress.Commands.add('findSubmission', function(tab, title) { + cy.get('#' + tab + '-button').click(); + cy.get('.listPanel__itemSubtitle:visible:contains("' + title + '")').first() + .parent().parent().within(() => { + cy.get('.pkpButton:contains("View")').click(); + }); +}); \ No newline at end of file diff --git a/cypress/tests/Test1_endorserFieldsSubmission.cy.js b/cypress/tests/Test1_endorserFieldsSubmission.cy.js index dc1212c..17ddec2 100644 --- a/cypress/tests/Test1_endorserFieldsSubmission.cy.js +++ b/cypress/tests/Test1_endorserFieldsSubmission.cy.js @@ -1,3 +1,5 @@ +import '../support/commands.js'; + function beginSubmission(submissionData) { cy.get('input[name="locale"][value="en"]').click(); cy.setTinyMceContent('startSubmission-title-control', submissionData.title); @@ -10,8 +12,7 @@ function beginSubmission(submissionData) { describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard", function() { let submissionData; let dummyPdf; - let endorserName = 'Bong Joon-ho'; - let endorserEmail = 'bong.joon-ho@email.kr'; + let endorsers; before(function() { Cypress.config('defaultCommandTimeout', 4000); @@ -25,22 +26,36 @@ describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard" 'mimeType': 'application/pdf', 'genre': 'Preprint Text' }; + endorsers = { + invalidEmail: { + name: 'John Wayne', + email: 'john.wayne.email' + }, + isAuthor: { + name: 'Catherine Kwantes', + email: 'ckwantes@mailinator.com' + }, + correct: { + name: 'Bong Joon-ho', + email: 'bong.joon-ho@email.kr' + } + }; }); - it("Author user submits endorsed submission", function() { + it("Checks endorsement fields and validates endorser email", function() { cy.login('ckwantes', null, 'publicknowledge'); cy.get('div#myQueue a:contains("New Submission")').click(); beginSubmission(submissionData); - cy.setTinyMceContent('titleAbstract-abstract-control-en', submissionData.abstract); + cy.contains('h2', 'Endorsement'); cy.contains('Do you have the endorsement of an experienced researcher in the field of knowledge of the manuscript?'); cy.contains('If yes, please provide the name and e-mail address of the endorsing researcher. Endorsements can significantly speed up the moderation process.'); cy.contains('The endorsement cannot be given by one of the authors of the manuscript.'); - cy.get('input[name="endorserName"]').clear().type(endorserName, {delay: 0}); - cy.get('input[name="endorserEmail"]').clear().type(endorserEmail, {delay: 0}); + cy.get('input[name="endorserName"]').clear().type(endorsers.invalidEmail.name, {delay: 0}); + cy.get('input[name="endorserEmail"]').clear().type(endorsers.invalidEmail.email, {delay: 0}); cy.contains('button', 'Continue').click(); cy.addSubmissionGalleys([dummyPdf]); @@ -48,6 +63,32 @@ describe("Plaudit Pre-Endorsement Plugin - Endorser fields in submission wizard" cy.contains('button', 'Continue').click(); cy.contains('button', 'Continue').click(); + cy.contains('Please enter a valid endorser e-mail'); + }); + it("Validates endorser is not an author of the submission", function() { + cy.login('ckwantes', null, 'publicknowledge'); + cy.findSubmission('myQueue', submissionData.title); + + cy.get('input[name="endorserName"]').clear().type(endorsers.isAuthor.name, {delay: 0}); + cy.get('input[name="endorserEmail"]').clear().type(endorsers.isAuthor.email, {delay: 0}); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + + cy.contains('The endorsement cannot be given by any of the authors of the manuscript'); + }); + it("Finishes submission with correct endorsement", function() { + cy.login('ckwantes', null, 'publicknowledge'); + cy.findSubmission('myQueue', submissionData.title); + + cy.get('input[name="endorserName"]').clear().type(endorsers.correct.name, {delay: 0}); + cy.get('input[name="endorserEmail"]').clear().type(endorsers.correct.email, {delay: 0}); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Submit').click(); cy.get('.modal__panel:visible').within(() => { cy.contains('button', 'Submit').click(); From a38806fe9944fbf3a6c8a1906ba1ae8e71d42c62 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 1 Mar 2024 15:06:58 -0400 Subject: [PATCH 16/35] Validates endorsement fields during submission Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 46 +++++++++++++++++++-------------- templates/reviewEndorsement.tpl | 15 +++++++++++ 2 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 templates/reviewEndorsement.tpl diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index 88ae46f..bdc8265 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -38,8 +38,9 @@ public function register($category, $path, $mainContextId = null) if ($success && $this->getEnabled($mainContextId)) { Hook::add('TemplateManager::display', [$this, 'modifySubmissionSteps']); Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); + Hook::add('Submission::validateSubmit', [$this, 'validateEndorsement']); + Hook::add('Template::SubmissionWizard::Section::Review', [$this, 'modifyReviewSections']); - // Hook::add('submissionsubmitstep3form::validate', [$this, 'validateEndorsement']); // Hook::add('submissionsubmitstep4form::execute', [$this, 'step4SendEmailToEndorser']); // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); @@ -140,28 +141,35 @@ public function modifySubmissionSteps($hookName, $params) public function validateEndorsement($hookName, $params) { - $form = & $params[0]; - $form->readUserVars(array('endorserEmail')); - $publication = $form->submission->getCurrentPublication(); - $authors = $publication->getData('authors'); - - $endorserEmail = $form->getData('endorserEmail'); - - if(!empty($endorserEmail)) { - if(!$this->inputIsEmail($endorserEmail)) { - $form->addErrorField('endorsementEmailInvalid'); - $form->addError('endorsementEmailInvalid', __("plugins.generic.plauditPreEndorsement.endorsementEmailInvalid")); - return; - } + $errors = &$params[0]; + $submission = $params[1]; + $publication = $submission->getCurrentPublication(); + $endorserEmail = $publication->getData('endorserEmail'); - foreach($authors as $author) { - if($author->getData('email') == $endorserEmail) { - $form->addErrorField('endorsementFromAuthor'); - $form->addError('endorsementFromAuthor', __("plugins.generic.plauditPreEndorsement.endorsementFromAuthor")); - return; + if ($endorserEmail) { + if (!$this->inputIsEmail($endorserEmail)) { + $errors['endorsement'] = [__("plugins.generic.plauditPreEndorsement.endorsementEmailInvalid")]; + } else { + foreach ($publication->getData('authors') as $author) { + if($author->getData('email') == $endorserEmail) { + $errors['endorsement'] = [__("plugins.generic.plauditPreEndorsement.endorsementFromAuthor")]; + } } } } + + return false; + } + + public function modifyReviewSections($hookName, $params) + { + $step = $params[0]['step']; + $templateMgr = $params[1]; + $output = &$params[2]; + + if ($step == 'details') { + $output .= $templateMgr->fetch($this->getTemplateResource('reviewEndorsement.tpl')); + } } public function step4SendEmailToEndorser($hookName, $params) diff --git a/templates/reviewEndorsement.tpl b/templates/reviewEndorsement.tpl new file mode 100644 index 0000000..084c79a --- /dev/null +++ b/templates/reviewEndorsement.tpl @@ -0,0 +1,15 @@ +
+ +
\ No newline at end of file From 8ef887d4ffa3133f719610ffbcce7d6bb28f9c8c Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 1 Mar 2024 18:46:34 -0400 Subject: [PATCH 17/35] WIP: email sending in submission completion Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 80 ++++++++----------- .../OrcidRequestEndorserAuthorization.php | 23 ++++++ .../listeners/SendEmailToEndorser.php | 28 +++++++ .../tests/Test2_endorserEmailCount.spec.js | 74 ----------------- cypress/tests/Test2_workflowFeatures.cy.js | 31 +++++++ .../tests/Test3_writingOnActivityLog.spec.js | 59 -------------- cypress/tests/Test4_indicatorWorkflow.spec.js | 59 -------------- cypress/tests/Test5_removeEndorser.spec.js | 69 ---------------- .../tests/Test6_endorsementFromAuthor.spec.js | 64 --------------- emailTemplates.xml | 8 +- locale/en/emails.po | 13 +-- locale/es/emails.po | 13 +-- locale/pt_BR/emails.po | 13 +-- 13 files changed, 148 insertions(+), 386 deletions(-) create mode 100644 classes/mail/mailables/OrcidRequestEndorserAuthorization.php create mode 100644 classes/observers/listeners/SendEmailToEndorser.php delete mode 100644 cypress/tests/Test2_endorserEmailCount.spec.js create mode 100644 cypress/tests/Test2_workflowFeatures.cy.js delete mode 100644 cypress/tests/Test3_writingOnActivityLog.spec.js delete mode 100644 cypress/tests/Test4_indicatorWorkflow.spec.js delete mode 100644 cypress/tests/Test5_removeEndorser.spec.js delete mode 100644 cypress/tests/Test6_endorsementFromAuthor.spec.js diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index bdc8265..56f9420 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -19,9 +19,15 @@ use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxModal; use APP\pages\submission\SubmissionHandler; +use APP\facades\Repo; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Mail; use APP\plugins\generic\plauditPreEndorsement\classes\OrcidClient; +use APP\plugins\generic\plauditPreEndorsement\classes\Endorsement; use APP\plugins\generic\plauditPreEndorsement\classes\components\forms\EndorsementForm; use APP\plugins\generic\plauditPreEndorsement\PlauditPreEndorsementSettingsForm; +use APP\plugins\generic\plauditPreEndorsement\classes\mail\mailables\OrcidRequestEndorserAuthorization; +use APP\plugins\generic\plauditPreEndorsement\classes\observers\listeners\SendEmailToEndorser; class PlauditPreEndorsementPlugin extends GenericPlugin { @@ -36,12 +42,13 @@ public function register($category, $path, $mainContextId = null) } if ($success && $this->getEnabled($mainContextId)) { + Event::subscribe(new SendEmailToEndorser()); + Hook::add('TemplateManager::display', [$this, 'modifySubmissionSteps']); Hook::add('Schema::get::publication', [$this, 'addOurFieldsToPublicationSchema']); Hook::add('Submission::validateSubmit', [$this, 'validateEndorsement']); Hook::add('Template::SubmissionWizard::Section::Review', [$this, 'modifyReviewSections']); - // Hook::add('submissionsubmitstep4form::execute', [$this, 'step4SendEmailToEndorser']); // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); // Hook::add('AcronPlugin::parseCronTab', [$this, 'addEndorsementTasksToCrontab']); @@ -172,16 +179,6 @@ public function modifyReviewSections($hookName, $params) } } - public function step4SendEmailToEndorser($hookName, $params) - { - $step4Form = $params[0]; - $publication = $step4Form->submission->getCurrentPublication(); - - if (!empty($publication->getData('endorserEmail'))) { - $this->sendEmailToEndorser($publication); - } - } - public function addOurFieldsToPublicationSchema($hookName, $params) { $schema = &$params[0]; @@ -264,31 +261,32 @@ public function addEndorserFieldsToWorkflow($hookName, $params) public function sendEmailToEndorser($publication, $endorserChanged = false) { - $request = PKPApplication::get()->getRequest(); + $request = Application::get()->getRequest(); $context = $request->getContext(); $endorserName = $publication->getData('endorserName'); $endorserEmail = $publication->getData('endorserEmail'); if (!is_null($context) && !empty($endorserEmail)) { - $emailTemplate = 'ORCID_REQUEST_ENDORSER_AUTHORIZATION'; - $email = $this->getMailTemplate($emailTemplate, $context); - - $email->setFrom($context->getData('contactEmail'), $context->getData('contactName')); - $email->setRecipients([['name' => $endorserName, 'email' => $endorserEmail]]); + $submission = Repo::submission()->get($publication->getData('submissionId')); + $emailTemplate = Repo::emailTemplate()->getByKey( + $context->getId(), + 'ORCID_REQUEST_ENDORSER_AUTHORIZATION' + ); $endorserEmailToken = md5(microtime() . $endorserEmail); $oauthUrl = $this->buildOAuthUrl(['token' => $endorserEmailToken, 'state' => $publication->getId()]); - - $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); - $authorsUserGroups = $userGroupDao->getByContextId($context->getId())->toArray(); - $email->sendWithParams([ + $emailParams = [ 'orcidOauthUrl' => $oauthUrl, - 'contactEmail' => $context->getData('contactEmail'), 'endorserName' => htmlspecialchars($endorserName), - 'preprintTitle' => htmlspecialchars($publication->getLocalizedTitle()), - 'abstract' => $publication->getLocalizedData('abstract'), - 'authors' => htmlspecialchars($publication->getAuthorString($authorsUserGroups)) - ]); + ]; + + $email = new OrcidRequestEndorserAuthorization($context, $submission, $emailParams); + $email->from($context->getData('contactEmail'), $context->getData('contactName')); + $email->to([['name' => $endorserName, 'email' => $endorserEmail]]); + $email->subject($emailTemplate->getLocalizedData('subject')); + $email->body($emailTemplate->getLocalizedData('body')); + + Mail::send($email); if(is_null($publication->getData('endorserEmailCount')) || $endorserChanged) { $endorserEmailCount = 0; @@ -297,13 +295,11 @@ public function sendEmailToEndorser($publication, $endorserChanged = false) } $publication->setData('endorserEmailToken', $endorserEmailToken); - $publication->setData('endorsementStatus', ENDORSEMENT_STATUS_NOT_CONFIRMED); + $publication->setData('endorsementStatus', Endorsement::STATUS_NOT_CONFIRMED); $publication->setData('endorserEmailCount', $endorserEmailCount + 1); - $publicationDao = DAORegistry::getDAO('PublicationDAO'); - $publicationDao->updateObject($publication); + Repo::publication()->edit($publication, []); - $submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId')); - $this->writeOnActivityLog($submission, 'plugins.generic.plauditPreEndorsement.log.sentEmailEndorser', ['endorserName' => $endorserName, 'endorserEmail' => $endorserEmail]); + // $this->writeOnActivityLog($submission, 'plugins.generic.plauditPreEndorsement.log.sentEmailEndorser', ['endorserName' => $endorserName, 'endorserEmail' => $endorserEmail]); } } @@ -312,12 +308,6 @@ public function getInstallEmailTemplatesFile() return $this->getPluginPath() . '/emailTemplates.xml'; } - private function getMailTemplate($emailKey, $context = null) - { - import('lib.pkp.classes.mail.MailTemplate'); - return new MailTemplate($emailKey, null, $context, false); - } - public function orcidIsGloballyConfigured() { $apiUrl = Config::getVar('orcid', 'api_url'); @@ -377,18 +367,18 @@ public function manage($args, $request) public function buildOAuthUrl($redirectParams) { - $request = PKPApplication::get()->getRequest(); + $request = Application::get()->getRequest(); $contextId = $request->getContext()->getId(); if ($this->isMemberApiEnabled($contextId)) { - $scope = ENDORSEMENT_ORCID_API_SCOPE_MEMBER; + $scope = OrcidClient::ORCID_API_SCOPE_MEMBER; } else { - $scope = ENDORSEMENT_ORCID_API_SCOPE_PUBLIC; + $scope = OrcidClient::ORCID_API_SCOPE_PUBLIC; } $redirectUrl = $request->getDispatcher()->url( $request, - ROUTE_PAGE, + Application::ROUTE_PAGE, null, self::HANDLER_PAGE, 'orcidVerify', @@ -408,7 +398,7 @@ public function buildOAuthUrl($redirectParams) public function isMemberApiEnabled($contextId) { $apiUrl = $this->getSetting($contextId, 'orcidAPIPath'); - if ($apiUrl === ENDORSEMENT_ORCID_API_URL_MEMBER || $apiUrl === ENDORSEMENT_ORCID_API_URL_MEMBER_SANDBOX) { + if ($apiUrl == OrcidClient::ORCID_API_URL_MEMBER || $apiUrl === OrcidClient::ORCID_API_URL_MEMBER_SANDBOX) { return true; } else { return false; @@ -427,10 +417,10 @@ public function getOrcidUrl() $contextId = ($context == null) ? 0 : $context->getId(); $apiPath = $this->getSetting($contextId, 'orcidAPIPath'); - if ($apiPath == ENDORSEMENT_ORCID_API_URL_PUBLIC || $apiPath == ENDORSEMENT_ORCID_API_URL_MEMBER) { - return ENDORSEMENT_ORCID_URL; + if ($apiPath == OrcidClient::ORCID_API_URL_PUBLIC || $apiPath == OrcidClient::ORCID_API_URL_MEMBER) { + return OrcidClient::ORCID_URL; } else { - return ENDORSEMENT_ORCID_URL_SANDBOX; + return OrcidClient::ORCID_URL_SANDBOX; } } diff --git a/classes/mail/mailables/OrcidRequestEndorserAuthorization.php b/classes/mail/mailables/OrcidRequestEndorserAuthorization.php new file mode 100644 index 0000000..7fba5d5 --- /dev/null +++ b/classes/mail/mailables/OrcidRequestEndorserAuthorization.php @@ -0,0 +1,23 @@ +addData($variables); + } +} diff --git a/classes/observers/listeners/SendEmailToEndorser.php b/classes/observers/listeners/SendEmailToEndorser.php new file mode 100644 index 0000000..6851e6a --- /dev/null +++ b/classes/observers/listeners/SendEmailToEndorser.php @@ -0,0 +1,28 @@ +listen( + SubmissionSubmitted::class, + SendEmailToEndorser::class + ); + } + + public function handle(SubmissionSubmitted $event): void + { + $publication = $event->submission->getCurrentPublication(); + + if (!empty($publication->getData('endorserEmail'))) { + $plugin = PluginRegistry::getPlugin('generic', 'plauditpreendorsementplugin'); + $plugin->sendEmailToEndorser($publication); + } + } +} diff --git a/cypress/tests/Test2_endorserEmailCount.spec.js b/cypress/tests/Test2_endorserEmailCount.spec.js deleted file mode 100644 index d7b6615..0000000 --- a/cypress/tests/Test2_endorserEmailCount.spec.js +++ /dev/null @@ -1,74 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; - -function loginAuthorUser() { - cy.get('input[id=username]').clear(); - cy.get('input[id=username]').type(Cypress.env('OJSAuthorUsername'), { delay: 0 }); - cy.get('input[id=password]').type(Cypress.env('OJSAuthorPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); -} - -function submissionStep1() { - cy.get('#sectionId').select('1'); - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test send e-mail to endorser", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('input[name^="endorserName"]').type("Queen Elizabeth", { delay: 0 }); - cy.get('input[name^="endorserEmail"]').type("queen.elizabeth.2nd@gmail.com", { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep4() { - cy.get('#submitStep4Form > .formButtons > .submitFormButton').click(); - cy.get('.pkp_modal_confirmation > .footer > .ok').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Send e-mail to endorser during submission", function() { - it("Author user submits endorsed submission", function() { - cy.visit(submissionsPage); - loginAuthorUser(); - - cy.get('.pkpHeader__actions:visible > a.pkpButton').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - submissionStep4(); - }); - it("E-mail sendings counting message in submission workflow", function() { - cy.contains("Review this submission").click(); - cy.get("#publication-button").click(); - cy.contains("Pre-Endorsement").click(); - cy.contains("1 endorsement confirmation e-mail has been sent to the endorser"); - - cy.get("#plauditPreEndorsement").contains("Save").click(); - cy.reload(); - cy.get("#publication-button").click(); - cy.contains("Pre-Endorsement").click(); - cy.contains("2 endorsement confirmation e-mails have been sent to the endorser"); - }); - it("E-mail sendings count set to zero when endorser is changed", function() { - cy.get('input[name="endorserNameWorkflow"]').clear().type("Lady Diana", { delay: 0 }); - cy.get('input[name="endorserEmailWorkflow"]').clear().type("lady.diana@gmail.com", { delay: 0 }); - cy.get("#plauditPreEndorsement").contains("Save").click(); - cy.reload(); - cy.get("#publication-button").click(); - cy.contains("Pre-Endorsement").click(); - cy.contains("1 endorsement confirmation e-mail has been sent to the endorser"); - }); -}); \ No newline at end of file diff --git a/cypress/tests/Test2_workflowFeatures.cy.js b/cypress/tests/Test2_workflowFeatures.cy.js new file mode 100644 index 0000000..d648637 --- /dev/null +++ b/cypress/tests/Test2_workflowFeatures.cy.js @@ -0,0 +1,31 @@ +import '../support/commands.js'; + +describe("Plaudit Pre-Endorsement Plugin - Workflow features", function() { + let submissionTitle = "Killers of the Flower Moon"; + + it("E-mail sendings counting message in submission workflow", function() { + cy.login('ckwantes', null, 'publicknowledge'); + cy.findSubmission('myQueue', submissionTitle); + + cy.contains("Pre-Endorsement").click(); + cy.contains("1 endorsement confirmation e-mail has been sent to the endorser"); + + cy.get("#plauditPreEndorsement").contains("Save").click(); + cy.reload(); + cy.get("#publication-button").click(); + cy.contains("Pre-Endorsement").click(); + cy.contains("2 endorsement confirmation e-mails have been sent to the endorser"); + }); + it("E-mail sendings count set to zero when endorser is changed", function() { + cy.login('ckwantes', null, 'publicknowledge'); + cy.findSubmission('myQueue', submissionTitle); + + cy.get('input[name="endorserNameWorkflow"]').clear().type("Lady Diana", { delay: 0 }); + cy.get('input[name="endorserEmailWorkflow"]').clear().type("lady.diana@gmail.com", { delay: 0 }); + cy.get("#plauditPreEndorsement").contains("Save").click(); + cy.reload(); + cy.get("#publication-button").click(); + cy.contains("Pre-Endorsement").click(); + cy.contains("1 endorsement confirmation e-mail has been sent to the endorser"); + }); +}); \ No newline at end of file diff --git a/cypress/tests/Test3_writingOnActivityLog.spec.js b/cypress/tests/Test3_writingOnActivityLog.spec.js deleted file mode 100644 index 0811327..0000000 --- a/cypress/tests/Test3_writingOnActivityLog.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; - -function loginAdminUser() { - cy.get('input[id=username]').clear(); - cy.get('input[id=username]').type(Cypress.env('OJSAdminUsername'), { delay: 0 }); - cy.get('input[id=password]').type(Cypress.env('OJSAdminPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); -} - -function submissionStep1() { - cy.get('#sectionId').select('1'); - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test writing endorsement on Activity Log", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('input[name^="endorserName"]').type("Lívia Andrade", { delay: 0 }); - cy.get('input[name^="endorserEmail"]').type("livia@gmail.com", { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep4() { - cy.get('#submitStep4Form > .formButtons > .submitFormButton').click(); - cy.get('.pkp_modal_confirmation > .footer > .ok').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Check writing of messages on submission's Activity Log", function() { - it("Admin user submits endorsed submission", function() { - cy.visit(submissionsPage); - loginAdminUser(); - cy.contains("Submissions").click(); - - cy.get('.pkpHeader__actions:visible > a.pkpButton').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - submissionStep4(); - }); - it("Check messages in submission's Activity Log", function() { - cy.contains("Proceed to post").click(); - cy.get('.pkpWorkflow__header > .pkpHeader__actions').contains('Activity Log').click(); - cy.get(".pkp_modal_panel").contains("An endorsement confirmation e-mail has been sent to Lívia Andrade (livia@gmail.com)"); - }); -}); \ No newline at end of file diff --git a/cypress/tests/Test4_indicatorWorkflow.spec.js b/cypress/tests/Test4_indicatorWorkflow.spec.js deleted file mode 100644 index 05fc93d..0000000 --- a/cypress/tests/Test4_indicatorWorkflow.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; - -function loginAdminUser() { - cy.get('input[id=username]').clear(); - cy.get('input[id=username]').type(Cypress.env('OJSAdminUsername'), { delay: 0 }); - cy.get('input[id=password]').type(Cypress.env('OJSAdminPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); -} - -function submissionStep1() { - cy.get('#sectionId').select('1'); - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test writing endorsement on Activity Log", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('input[name^="endorserName"]').type("Lívia Andrade", { delay: 0 }); - cy.get('input[name^="endorserEmail"]').type("livia@gmail.com", { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep4() { - cy.get('#submitStep4Form > .formButtons > .submitFormButton').click(); - cy.get('.pkp_modal_confirmation > .footer > .ok').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Visual indicator at submission workflow", function() { - it("Admin user submits endorsed submission", function() { - cy.visit(submissionsPage); - loginAdminUser(); - cy.contains("Submissions").click(); - - cy.get('.pkpHeader__actions:visible > a.pkpButton').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - submissionStep4(); - }); - it("Checks presence of visual indicator", function() { - cy.contains("Proceed to post").click(); - cy.get("#publication-button").click(); - cy.get("#plauditPreEndorsement-button > .pkpBadge"); - }); -}); \ No newline at end of file diff --git a/cypress/tests/Test5_removeEndorser.spec.js b/cypress/tests/Test5_removeEndorser.spec.js deleted file mode 100644 index 57f0ac7..0000000 --- a/cypress/tests/Test5_removeEndorser.spec.js +++ /dev/null @@ -1,69 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; - -function loginAdminUser() { - cy.get('input[id=username]').clear(); - cy.get('input[id=username]').type(Cypress.env('OJSAdminUsername'), { delay: 0 }); - cy.get('input[id=password]').type(Cypress.env('OJSAdminPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); -} - -function submissionStep1() { - cy.get('#sectionId').select('1'); - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test writing endorsement on Activity Log", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('input[name^="endorserName"]').type("Lívia Andrade", { delay: 0 }); - cy.get('input[name^="endorserEmail"]').type("livia@gmail.com", { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); -} - -function submissionStep4() { - cy.get('#submitStep4Form > .formButtons > .submitFormButton').click(); - cy.get('.pkp_modal_confirmation > .footer > .ok').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Check remove endorser button", function() { - it("Author user submits endorsed submission", function() { - cy.visit(submissionsPage); - loginAdminUser(); - cy.contains("Submissions").click(); - - cy.get('.pkpHeader__actions:visible > a.pkpButton').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - submissionStep4(); - }); - it("Removes endorsement in submission workflow", function() { - cy.contains("Review this submission").click(); - cy.get("#publication-button").click(); - cy.contains("Pre-Endorsement").click(); - - cy.get("#plauditPreEndorsement").contains("Remove endorsement").click(); - cy.on('window:confirm', (str) => { - expect(str).to.equal("Do you want to remove the endorsement of this submission?"); - }); - cy.on('window:confirm', () => true); - - cy.reload(); - cy.get('input[name="endorserNameWorkflow"]').should('have.value', ''); - cy.get('input[name="endorserEmailWorkflow"]').should('have.value', ''); - }); -}); \ No newline at end of file diff --git a/cypress/tests/Test6_endorsementFromAuthor.spec.js b/cypress/tests/Test6_endorsementFromAuthor.spec.js deleted file mode 100644 index 8994598..0000000 --- a/cypress/tests/Test6_endorsementFromAuthor.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -const submissionsPage = Cypress.env('baseUrl') + 'index.php/publicknowledge/submissions'; -const endorserEmail = "joao.silva@lepidus.com.br"; - -function loginAdminUser() { - cy.get('input[id=username]').clear(); - cy.get('input[id=username]').type(Cypress.env('OJSAdminUsername'), { delay: 0 }); - cy.get('input[id=password]').type(Cypress.env('OJSAdminPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); -} - -function submissionStep1() { - cy.get('#sectionId').select('1'); - cy.get('#pkp_submissionChecklist > ul > li > label > input').check(); - cy.get('#privacyConsent').check(); - - cy.get('#submissionStep1 > .formButtons > .submitFormButton').click(); -} - -function submissionStep2() { - cy.get('#submitStep2Form > .formButtons > .submitFormButton').click(); -} - -function addContributor() { - cy.contains('Add Contributor').click(); - cy.wait(250); - cy.get('input[id^="givenName-en_US"]').type("João", {delay: 0}); - cy.get('input[id^="familyName-en_US"]').type("Silva", {delay: 0}); - cy.get('select[id=country]').select("Brasil"); - cy.get('input[id^="email"]').type(endorserEmail, {delay: 0}); - cy.get('label').contains("Author").click(); - cy.get('#editAuthor > .formButtons > .submitFormButton').click(); -} - -function submissionStep3() { - cy.get('input[name^="title"]').first().type("Submission test endorsement from author", { delay: 0 }); - cy.get('label').contains('Title').click(); - cy.get('textarea[id^="abstract-"').then((node) => { - cy.setTinyMceContent(node.attr("id"), "Example of abstract"); - }); - cy.get('.section > label:visible').first().click(); - - addContributor(); - - cy.get('ul[id^="en_US-keywords-"]').then(node => { - node.tagit('createTag', "Dummy keyword"); - }); - cy.get('input[name^="endorserName"]').type("João Silva", { delay: 0 }); - cy.get('input[name^="endorserEmail"]').type(endorserEmail, { delay: 0 }); - cy.get('#submitStep3Form > .formButtons > .submitFormButton').click(); -} - -describe("Plaudit Pre-Endorsement Plugin - Endorsement from author", function() { - it("Checks alert message for endorsement given by an author", function() { - cy.visit(submissionsPage); - loginAdminUser(); - cy.contains("Submissions").click(); - - cy.get('.pkpHeader__actions:visible > a.pkpButton').click(); - submissionStep1(); - submissionStep2(); - submissionStep3(); - cy.contains("The endorsement cannot be given by any of the authors of the manuscript"); - }); -}); \ No newline at end of file diff --git a/emailTemplates.xml b/emailTemplates.xml index f9a0d19..36b853d 100644 --- a/emailTemplates.xml +++ b/emailTemplates.xml @@ -9,5 +9,11 @@ * Email templates XML file. --> - + diff --git a/locale/en/emails.po b/locale/en/emails.po index ed5eff3..98b8e5f 100644 --- a/locale/en/emails.po +++ b/locale/en/emails.po @@ -11,6 +11,12 @@ msgstr "" "PO-Revision-Date: 2020-02-05T22:33:48+00:00\n" "Language: English\n" +msgid "emails.orcidRequestEndorserAuthorization.name" +msgstr "Request endorser ORCID authorization" + +msgid "emails.orcidRequestEndorserAuthorization.description" +msgstr "This email template is used to request ORCID record access from the endorser." + msgid "emails.orcidRequestEndorserAuthorization.subject" msgstr "Endorsement confirmation" @@ -18,7 +24,7 @@ msgid "emails.orcidRequestEndorserAuthorization.body" msgstr "" "Dear {$endorserName},
\n" "
\n" -"Your name has been nominated to endorse the manuscript \"{$preprintTitle}\", submitted to server {$contextName}.
\n" +"Your name has been nominated to endorse the manuscript \"{$submissionTitle}\", submitted to server {$contextName}.
\n" "
\n" "To confirm your endorsement of the manuscript, access the link to the official ORCID website placed below. Log in with your ORCID profile and authorize access following the instructions.
\n" "
\n" @@ -29,12 +35,9 @@ msgstr "" "After the manuscript is posted, your endorsement record will be sent to Plaudit, where it will be visible to the scientific community.
\n" "
\n" "Manuscript information
\n" -"Title: {$preprintTitle}
\n" +"Title: {$submissionTitle}
\n" "Authors: {$authors}
\n" "Abstract: {$abstract}
\n" "
\n" "If you have any questions, please contact us: {$contactEmail}
\n" "" - -msgid "emails.orcidRequestEndorserAuthorization.description" -msgstr "This email template is used to request ORCID record access from the endorser." diff --git a/locale/es/emails.po b/locale/es/emails.po index 067fc4b..1170b22 100644 --- a/locale/es/emails.po +++ b/locale/es/emails.po @@ -11,6 +11,12 @@ msgstr "" "PO-Revision-Date: 2020-02-05T22:33:48+00:00\n" "Language: Español\n" +msgid "emails.orcidRequestEndorserAuthorization.name" +msgstr "Solicita autorización ORCID al endosante" + +msgid "emails.orcidRequestEndorserAuthorization.description" +msgstr "Esta plantilla de correo electrónico se usa para solicitar el acceso al registro ORCID del endosador." + msgid "emails.orcidRequestEndorserAuthorization.subject" msgstr "Confirmación de endoso" @@ -18,7 +24,7 @@ msgid "emails.orcidRequestEndorserAuthorization.body" msgstr "" "Estimado(a) {$endorserName},
\n" "
\n" -"Se ha indicado su nombre para endosar el manuscrito \"{$preprintTitle}\", enviado al servidor {$contextName}.
\n" +"Se ha indicado su nombre para endosar el manuscrito \"{$submissionTitle}\", enviado al servidor {$contextName}.
\n" "
\n" "Para confirmar su endoso del manuscrito, acceda al enlace al sitio web oficial de ORCID que se encuentra a continuación. Inicia sesión con tu perfil ORCID y autoriza el acceso siguiendo las instrucciones.
\n" "
\n" @@ -29,12 +35,9 @@ msgstr "" "Después de que se publique el manuscrito, su registro de endoso se enviará a Plaudit, donde será visible para la comunidad científica..
\n" "
\n" "Información del manuscrito
\n" -"Título: {$preprintTitle}
\n" +"Título: {$submissionTitle}
\n" "Autores: {$authors}
\n" "Resumen: {$abstract}
\n" "
\n" "Si tiene alguna pregunta, por favor contáctenos: {$contactEmail}
\n" "" - -msgid "emails.orcidRequestEndorserAuthorization.description" -msgstr "Esta plantilla de correo electrónico se usa para solicitar el acceso al registro ORCID del endosador." diff --git a/locale/pt_BR/emails.po b/locale/pt_BR/emails.po index 15b74f1..429663b 100644 --- a/locale/pt_BR/emails.po +++ b/locale/pt_BR/emails.po @@ -11,6 +11,12 @@ msgstr "" "PO-Revision-Date: 2020-02-05T22:33:48+00:00\n" "Language: Português Brasileiro\n" +msgid "emails.orcidRequestEndorserAuthorization.name" +msgstr "Solicita autorização ORCID do endossador" + +msgid "emails.orcidRequestEndorserAuthorization.description" +msgstr "Este modelo de e-mail é usado para solicitar acesso ao registro ORCID do endossador." + msgid "emails.orcidRequestEndorserAuthorization.subject" msgstr "Confirmação de endosso" @@ -18,7 +24,7 @@ msgid "emails.orcidRequestEndorserAuthorization.body" msgstr "" "Prezado(a) {$endorserName},
\n" "
\n" -"O seu nome foi indicado para endossar o manuscrito \"{$preprintTitle}\", submetido ao servidor {$contextName}.
\n" +"O seu nome foi indicado para endossar o manuscrito \"{$submissionTitle}\", submetido ao servidor {$contextName}.
\n" "
\n" "Para confirmar o seu endosso ao manuscrito, acesse o link para o site oficial do ORCID colocado abaixo. Faça o login com seu perfil ORCID e autorize o acesso seguindo as instruções.
\n" "
\n" @@ -29,12 +35,9 @@ msgstr "" "Após a postagem do manuscrito, o registro do seu endosso será enviado à Plaudit, onde estará visível para a comunidade científica.
\n" "
\n" "Informações do manuscrito
\n" -"Título: {$preprintTitle}
\n" +"Título: {$submissionTitle}
\n" "Autores: {$authors}
\n" "Resumo: {$abstract}
\n" "
\n" "Caso tenha alguma dúvida, entre em contato conosco: {$contactEmail}
\n" "" - -msgid "emails.orcidRequestEndorserAuthorization.description" -msgstr "Este modelo de e-mail é usado para solicitar acesso ao registro ORCID do endossador." From 0bd2d873647fdfbfe2edb570ee298477cfdf3353 Mon Sep 17 00:00:00 2001 From: Jhon Date: Mon, 4 Mar 2024 11:37:26 -0400 Subject: [PATCH 18/35] Fix e-mail params Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- locale/en/emails.po | 2 +- locale/es/emails.po | 2 +- locale/pt_BR/emails.po | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/en/emails.po b/locale/en/emails.po index 98b8e5f..6ce437f 100644 --- a/locale/en/emails.po +++ b/locale/en/emails.po @@ -37,7 +37,7 @@ msgstr "" "Manuscript information
\n" "Title: {$submissionTitle}
\n" "Authors: {$authors}
\n" -"Abstract: {$abstract}
\n" +"Abstract: {$submissionAbstract}
\n" "
\n" "If you have any questions, please contact us: {$contactEmail}
\n" "" diff --git a/locale/es/emails.po b/locale/es/emails.po index 1170b22..5416c05 100644 --- a/locale/es/emails.po +++ b/locale/es/emails.po @@ -37,7 +37,7 @@ msgstr "" "Información del manuscrito
\n" "Título: {$submissionTitle}
\n" "Autores: {$authors}
\n" -"Resumen: {$abstract}
\n" +"Resumen: {$submissionAbstract}
\n" "
\n" "Si tiene alguna pregunta, por favor contáctenos: {$contactEmail}
\n" "" diff --git a/locale/pt_BR/emails.po b/locale/pt_BR/emails.po index 429663b..9511175 100644 --- a/locale/pt_BR/emails.po +++ b/locale/pt_BR/emails.po @@ -37,7 +37,7 @@ msgstr "" "Informações do manuscrito
\n" "Título: {$submissionTitle}
\n" "Autores: {$authors}
\n" -"Resumo: {$abstract}
\n" +"Resumo: {$submissionAbstract}
\n" "
\n" "Caso tenha alguma dúvida, entre em contato conosco: {$contactEmail}
\n" "" From 4c63e1817038fa10146d73cde70be8e755b84c18 Mon Sep 17 00:00:00 2001 From: Jhon Date: Mon, 4 Mar 2024 12:00:21 -0400 Subject: [PATCH 19/35] WIP: Exhibition of endorsement fields at workflow Issue: documentacao-e-tarefas/scielo#635 Signed-off-by: Jhon --- PlauditPreEndorsementPlugin.php | 42 ++++++++++++++--------------- templates/endorserFieldWorkflow.tpl | 6 ++--- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/PlauditPreEndorsementPlugin.php b/PlauditPreEndorsementPlugin.php index 56f9420..bb062b2 100644 --- a/PlauditPreEndorsementPlugin.php +++ b/PlauditPreEndorsementPlugin.php @@ -20,6 +20,7 @@ use PKP\linkAction\request\AjaxModal; use APP\pages\submission\SubmissionHandler; use APP\facades\Repo; +use PKP\security\Role; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Mail; use APP\plugins\generic\plauditPreEndorsement\classes\OrcidClient; @@ -49,8 +50,8 @@ public function register($category, $path, $mainContextId = null) Hook::add('Submission::validateSubmit', [$this, 'validateEndorsement']); Hook::add('Template::SubmissionWizard::Section::Review', [$this, 'modifyReviewSections']); - // Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); - // Hook::add('LoadHandler', [$this, 'setupPlauditPreEndorsementHandler']); + Hook::add('Template::Workflow::Publication', [$this, 'addEndorserFieldsToWorkflow']); + Hook::add('LoadHandler', [$this, 'setupPreEndorsementHandler']); // Hook::add('AcronPlugin::parseCronTab', [$this, 'addEndorsementTasksToCrontab']); } @@ -67,12 +68,11 @@ public function getDescription() return __('plugins.generic.plauditPreEndorsement.description'); } - public function setupPlauditPreEndorsementHandler($hookName, $params) + public function setupPreEndorsementHandler($hookName, $params) { $page = $params[0]; if ($this->getEnabled() && $page == self::HANDLER_PAGE) { - $this->import('classes/PlauditPreEndorsementHandler'); - define('HANDLER_CLASS', 'PlauditPreEndorsementHandler'); + define('HANDLER_CLASS', 'APP\plugins\generic\plauditPreEndorsement\classes\PlauditPreEndorsementHandler'); return true; } return false; @@ -205,11 +205,11 @@ public function addOurFieldsToPublicationSchema($hookName, $params) private function getEndorsementStatusSuffix($endorsementStatus): string { $mapStatusToSuffix = [ - ENDORSEMENT_STATUS_NOT_CONFIRMED => 'NotConfirmed', - ENDORSEMENT_STATUS_CONFIRMED => 'Confirmed', - ENDORSEMENT_STATUS_DENIED => 'Denied', - ENDORSEMENT_STATUS_COMPLETED => 'Completed', - ENDORSEMENT_STATUS_COULDNT_COMPLETE => 'CouldntComplete' + Endorsement::STATUS_NOT_CONFIRMED => 'NotConfirmed', + Endorsement::STATUS_CONFIRMED => 'Confirmed', + Endorsement::STATUS_DENIED => 'Denied', + Endorsement::STATUS_COMPLETED => 'Completed', + Endorsement::STATUS_COULDNT_COMPLETE => 'CouldntComplete' ]; return $mapStatusToSuffix[$endorsementStatus] ?? ""; @@ -220,18 +220,18 @@ public function addEndorserFieldsToWorkflow($hookName, $params) $smarty = &$params[1]; $output = &$params[2]; - $submission = $smarty->get_template_vars('submission'); + $submission = $smarty->getTemplateVars('submission'); $publication = $submission->getCurrentPublication(); - $request = PKPApplication::get()->getRequest(); - $updateEndorserUrl = $request->getDispatcher()->url($request, ROUTE_PAGE, null, self::HANDLER_PAGE, 'updateEndorser'); + $request = Application::get()->getRequest(); + $handlerUrl = $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, self::HANDLER_PAGE); $endorsementStatus = $publication->getData('endorsementStatus'); $endorsementStatusSuffix = $this->getEndorsementStatusSuffix($endorsementStatus); - $canEditEndorsement = (is_null($endorsementStatus) || $endorsementStatus == ENDORSEMENT_STATUS_NOT_CONFIRMED || $endorsementStatus == ENDORSEMENT_STATUS_DENIED); - $canSendEndorsementManually = $publication->getData('status') === STATUS_PUBLISHED + $canEditEndorsement = (is_null($endorsementStatus) || $endorsementStatus == Endorsement::STATUS_NOT_CONFIRMED || $endorsementStatus == Endorsement::STATUS_DENIED); + $canSendEndorsementManually = $publication->getData('status') == STATUS_PUBLISHED && !$this->userAccessingIsAuthor($submission) - && ($endorsementStatus == ENDORSEMENT_STATUS_CONFIRMED || $endorsementStatus == ENDORSEMENT_STATUS_COULDNT_COMPLETE); + && ($endorsementStatus == Endorsement::STATUS_CONFIRMED || $endorsementStatus == Endorsement::STATUS_COULDNT_COMPLETE); $canRemoveEndorsement = !is_null($endorsementStatus) && !$this->userAccessingIsAuthor($submission); $smarty->assign([ @@ -245,9 +245,7 @@ public function addEndorserFieldsToWorkflow($hookName, $params) 'canEditEndorsement' => $canEditEndorsement, 'canRemoveEndorsement' => $canRemoveEndorsement, 'canSendEndorsementManually' => $canSendEndorsementManually, - 'updateEndorserUrl' => $updateEndorserUrl, - 'removeEndorsementUrl' => $request->getDispatcher()->url($request, ROUTE_PAGE, null, self::HANDLER_PAGE, 'removeEndorsement'), - 'sendEndorsementManuallyUrl' => $request->getDispatcher()->url($request, ROUTE_PAGE, null, self::HANDLER_PAGE, 'sendEndorsementManually') + 'handlerUrl' => $handlerUrl, ]); $tabBadge = (is_null($endorsementStatus) ? 'badge="0"' : 'badge="1"'); @@ -431,13 +429,13 @@ public function userAccessingIsAuthor($submission): bool if ($currentUser) { $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); $stageAssignmentsResult = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId($submission->getId(), $currentUser->getId(), $submission->getData('stageId')); - $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); + while ($stageAssignment = $stageAssignmentsResult->next()) { - $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId(), $submission->getData('contextId')); + $userGroup = Repo::userGroup()->get($stageAssignment->getUserGroupId(), $submission->getData('contextId')); $currentUserAssignedRoles[] = (int) $userGroup->getRoleId(); } } - return $currentUserAssignedRoles[0] == ROLE_ID_AUTHOR; + return $currentUserAssignedRoles[0] == Role::ROLE_ID_AUTHOR; } } diff --git a/templates/endorserFieldWorkflow.tpl b/templates/endorserFieldWorkflow.tpl index e214630..9658cd4 100644 --- a/templates/endorserFieldWorkflow.tpl +++ b/templates/endorserFieldWorkflow.tpl @@ -72,7 +72,7 @@ async function requestUpdateEndorsement(e){ldelim} $.post( - "{$updateEndorserUrl}", + "{$handlerUrl}/updateEndorser", {ldelim} submissionId: {$submissionId}, endorserName: $('input[name=endorserNameWorkflow]').val(), @@ -99,7 +99,7 @@ async function requestSendEndorsementManually(e){ldelim} $.post( - "{$sendEndorsementManuallyUrl}", + "{$handlerUrl}/sendEndorsementManually", {ldelim} submissionId: {$submissionId} {rdelim}, @@ -117,7 +117,7 @@