From 4a4b7f6b0d2b1ed7796a47ce90da9e8a647985fe Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 31 Dec 2024 13:05:37 -0500 Subject: [PATCH] pkp/pkp-lib#10744 Increase opportunity for ORCID work/review deposits --- api/v1/reviews/PKPReviewController.php | 41 ++++++++++++++++++ .../users/reviewer/PKPReviewerGridHandler.php | 4 ++ classes/orcid/PKPOrcidWork.php | 4 +- .../actions/PKPSendSubmissionToOrcid.php | 42 ++++++++++++------- classes/submission/maps/Schema.php | 3 +- .../users/reviewer/form/ThankReviewerForm.php | 2 - locale/en/submission.po | 8 +++- schemas/submission.json | 4 ++ 8 files changed, 88 insertions(+), 20 deletions(-) diff --git a/api/v1/reviews/PKPReviewController.php b/api/v1/reviews/PKPReviewController.php index cc503e1e518..a7ad998ea65 100644 --- a/api/v1/reviews/PKPReviewController.php +++ b/api/v1/reviews/PKPReviewController.php @@ -19,6 +19,7 @@ use APP\core\Application; use APP\facades\Repo; +use APP\orcid\actions\SendReviewToOrcid; use APP\template\TemplateManager; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -114,6 +115,17 @@ public function getGroupRoutes(): void ->name('review.export.getFile') ->whereNumber(['submissionId', 'fileId']); }); + + Route::post('{submissionId}/{reviewAssignmentId}/sendToOrcid', $this->sendToOrcid(...)) + ->name('review.sendToOrcid') + ->whereNumber(['submissionId', 'reviewAssignmentId']) + ->middleware([ + self::roleAuthorizer([ + Role::ROLE_ID_SITE_ADMIN, + Role::ROLE_ID_MANAGER, + Role::ROLE_ID_SUB_EDITOR, + ]) + ]); } /** @@ -724,4 +736,33 @@ public function getExportedFile(Request $illuminateRequest): JsonResponse } return response()->json([], Response::HTTP_OK); } + + /** + * Deposits a review work to ORCID + */ + public function sendToOrcid(Request $illuminateRequest): JsonResponse + { + $request = $this->getRequest(); + $context = $request->getContext(); + $reviewId = $illuminateRequest->route('reviewAssignmentId'); + $submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION); + + if ($submission->getData('contextId') !== $context->getId()) { + return response()->json([ + 'error' => __('api.404.resourceNotFound'), + ], Response::HTTP_NOT_FOUND); + } + + $reviewAssignment = Repo::reviewAssignment()->get($reviewId, $submission->getId()); + + if (!$reviewAssignment) { + return response()->json([ + 'error' => __('api.404.resourceNotFound'), + ], Response::HTTP_NOT_FOUND); + } + + (new SendReviewToOrcid($reviewAssignment->getId()))->execute(); + + return response()->json([], Response::HTTP_OK); + } } diff --git a/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php b/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php index a703b7eccea..11c40e787d1 100644 --- a/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php +++ b/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php @@ -21,6 +21,7 @@ use APP\core\Request; use APP\facades\Repo; use APP\notification\NotificationManager; +use APP\orcid\actions\SendReviewToOrcid; use APP\submission\Submission; use APP\template\TemplateManager; use Illuminate\Support\Facades\Mail; @@ -777,6 +778,9 @@ public function reviewRead($args, $request) ->withType(Notification::NOTIFICATION_TYPE_REVIEW_ASSIGNMENT) ->delete(); + // Deposit review to ORCID + (new SendReviewToOrcid($reviewAssignment->getId()))->execute(); + $json = DAO::getDataChangedEvent($reviewAssignment->getId()); $json->setGlobalEvent('update:decisions'); return $json; diff --git a/classes/orcid/PKPOrcidWork.php b/classes/orcid/PKPOrcidWork.php index 6ac0f92e745..8646a4d21bb 100644 --- a/classes/orcid/PKPOrcidWork.php +++ b/classes/orcid/PKPOrcidWork.php @@ -65,7 +65,7 @@ private function build(): array $this->context->getPath(), 'article', 'view', - $submission->getId(), + [$submission->getId()], urlLocaleForPage: '', ); @@ -276,7 +276,7 @@ private function buildOrcidContributors(array $authors, Context $context, Public $orcid = basename(parse_url($author->getOrcid(), PHP_URL_PATH)); if ($author->getData('orcidSandbox')) { - $uri = ORCID_URL_SANDBOX . $orcid; + $uri = OrcidManager::ORCID_URL_SANDBOX . $orcid; $host = 'sandbox.orcid.org'; } else { $uri = $author->getOrcid(); diff --git a/classes/orcid/actions/PKPSendSubmissionToOrcid.php b/classes/orcid/actions/PKPSendSubmissionToOrcid.php index 48400cd8e4e..a3109aea98a 100644 --- a/classes/orcid/actions/PKPSendSubmissionToOrcid.php +++ b/classes/orcid/actions/PKPSendSubmissionToOrcid.php @@ -12,16 +12,17 @@ * @brief Compile and trigger deposits of submissions to ORCID. */ - namespace PKP\orcid\actions; use APP\facades\Repo; +use APP\orcid\actions\SendReviewToOrcid; use APP\publication\Publication; use Carbon\Carbon; use PKP\context\Context; use PKP\jobs\orcid\DepositOrcidSubmission; use PKP\orcid\OrcidManager; use PKP\orcid\PKPOrcidWork; +use PKP\submission\reviewAssignment\ReviewAssignment; abstract class PKPSendSubmissionToOrcid { @@ -65,26 +66,24 @@ public function execute(): void if (empty($authorsWithOrcid)) { OrcidManager::logInfo('No contributor with ORICD id or valid access token for submission ' . $this->publication->getData('submissionId')); - return; - } - - $orcidWork = $this->getOrcidWork($authors->toArray()); - OrcidManager::logInfo('Request body (without put-code): ' . json_encode($orcidWork->toArray())); + } else { + $orcidWork = $this->getOrcidWork($authors->toArray()); + OrcidManager::logInfo('Request body (without put-code): ' . json_encode($orcidWork->toArray())); - if ($orcidWork === null) { - return; - } - foreach ($authorsWithOrcid as $orcid => $author) { - dispatch(new DepositOrcidSubmission($author, $this->context, $orcidWork->toArray(), $orcid)); + if ($orcidWork === null) { + return; + } + foreach ($authorsWithOrcid as $orcid => $author) { + dispatch(new DepositOrcidSubmission($author, $this->context, $orcidWork->toArray(), $orcid)); + } } + $this->depositReviewsForSubmission(); } /** * Get app-specific ORCID work for sending to ORCID * - * @param array $authors - * @return PKPOrcidWork|null */ abstract protected function getOrcidWork(array $authors): ?PKPOrcidWork; @@ -93,7 +92,22 @@ abstract protected function getOrcidWork(array $authors): ?PKPOrcidWork; * Currently only possible for OJS and OPS. * FIXME: This method/check can be removed once functionality added to OMP. * - * @return bool */ abstract protected function canDepositSubmission(): bool; + + + /** + * Deposit reviews for the submission to ORCID. + */ + public function depositReviewsForSubmission(): void + { + $submissionId = $this->publication->getData('submissionId'); + OrcidManager::logInfo('Submitting reviews for submission ' . $submissionId); + + collect(Repo::reviewAssignment()->getCollector() + ->filterByContextIds([$this->context->getId()]) + ->filterBySubmissionIds([$submissionId]) + ->getMany()) + ->each(fn (ReviewAssignment $review) => (new SendReviewToOrcid($review->getId()))->execute()); + } } diff --git a/classes/submission/maps/Schema.php b/classes/submission/maps/Schema.php index 62391a55369..7a09d3a4113 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -455,7 +455,8 @@ protected function getPropertyReviewAssignments(Enumerable $reviewAssignments, b 'reviewerId' => $anonymizeReviews && $anonymizeReviews->contains($reviewAssignment->getId()) ? null : $reviewAssignment->getReviewerId(), 'reviewerFullName' => $anonymizeReviews && $anonymizeReviews->contains($reviewAssignment->getId()) ? '' : $reviewAssignment->getData('reviewerFullName'), 'reviewMethod' => $reviewAssignment->getData('reviewMethod'), - 'reviewerDisplayInitials' => $anonymizeReviews && $anonymizeReviews->contains($reviewAssignment->getId()) ? '' : Repo::user()->get($reviewAssignment->getReviewerId())->getDisplayInitials() + 'reviewerDisplayInitials' => $anonymizeReviews && $anonymizeReviews->contains($reviewAssignment->getId()) ? '' : Repo::user()->get($reviewAssignment->getReviewerId())->getDisplayInitials(), + 'reviewerHasOrcid' => !($anonymizeReviews && $anonymizeReviews->contains($reviewAssignment->getId())) && !!Repo::user()->get($reviewAssignment->getReviewerId())->getData('orcidIsVerified'), ]; } diff --git a/controllers/grid/users/reviewer/form/ThankReviewerForm.php b/controllers/grid/users/reviewer/form/ThankReviewerForm.php index ee937275080..f4bc5d74516 100644 --- a/controllers/grid/users/reviewer/form/ThankReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ThankReviewerForm.php @@ -125,8 +125,6 @@ public function execute(...$functionArgs) Hook::call('ThankReviewerForm::thankReviewer', [$submission, $reviewAssignment, $mailable]); - (new SendReviewToOrcid($reviewAssignment->getId()))->execute(); - if (!$this->getData('skipEmail')) { $mailable->setData(Locale::getLocale()); try { diff --git a/locale/en/submission.po b/locale/en/submission.po index 0f6c08cd09f..3bd38c49666 100644 --- a/locale/en/submission.po +++ b/locale/en/submission.po @@ -2581,8 +2581,14 @@ msgstr "View recommendation" msgid "dashboard.reviewAssignment.action.viewUnreadRecommendation" msgstr "View unread recommendation" +msgid "dashboard.reviewAssignment.action.sendReviewToOrcid" +msgstr "Send Review To ORCID" + +msgid "dashboard.reviewAssignment.action.sendReviewToOrcid.confirm" +msgstr "Send this review to the reviewer's ORCID?" + msgid "dashboard.declinedDuringStage" -msgstr "Declined during the {$stageName} stage. +msgstr "Declined during the {$stageName} stage." msgid "dashboard.recommendOnly.pendingRecommendations" msgstr "Recommending Editors are tasked to advise the next steps for this submission" diff --git a/schemas/submission.json b/schemas/submission.json index 0dfac389b9c..68145a18405 100644 --- a/schemas/submission.json +++ b/schemas/submission.json @@ -174,6 +174,10 @@ "reviewMethod": { "type": "string", "readOnly": true + }, + "reviewerHasOrcid": { + "type": "boolean", + "readOnly": true } } }