Skip to content

Commit

Permalink
pkp#10744 Increase opportunity for ORCID work/review deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 31, 2024
1 parent 4788455 commit c1d7493
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 17 deletions.
44 changes: 44 additions & 0 deletions api/v1/reviews/PKPReviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +42,7 @@
use PKP\security\authorization\SubmissionAccessPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewer\ReviewerAction;
use PKP\submission\SubmissionCommentDAO;
use PKP\submissionFile\SubmissionFile;
Expand Down Expand Up @@ -114,6 +116,17 @@ public function getGroupRoutes(): void
->name('review.export.getFile')
->whereNumber(['submissionId', 'fileId']);
});

Route::post('{submissionId}/{reviewAssignmentId}/sendToOrcid', $this->sendToOrcid(...))
->name('review.sendToOrcid')
->whereNumber(['reviewAssignmentId', 'submissionId'])
->middleware([
self::roleAuthorizer([
Role::ROLE_ID_SITE_ADMIN,
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
])
]);
}

/**
Expand Down Expand Up @@ -724,4 +737,35 @@ 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.403.unauthorized'),
], Response::HTTP_NOT_FOUND);
}

$reviewAssignment = Repo::reviewAssignment()->get($reviewId, $submission->getId());

if (!$reviewAssignment) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

if (!in_array($reviewAssignment->getStatus(), ReviewAssignment::REVIEW_COMPLETE_STATUSES)) {
(new SendReviewToOrcid($reviewAssignment->getId()))->execute();
}

return response()->json([], Response::HTTP_OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion classes/orcid/PKPOrcidWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
42 changes: 28 additions & 14 deletions classes/orcid/actions/PKPSendSubmissionToOrcid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}

Expand Down
10 changes: 9 additions & 1 deletion locale/en/submission.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2652,3 +2658,5 @@ msgstr "Select incomplete submissions to be deleted."

msgid "dashboard.submissions.incomplete.bulkDelete.button"
msgstr "Delete Incomplete Submissions"


4 changes: 4 additions & 0 deletions schemas/submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
"reviewMethod": {
"type": "string",
"readOnly": true
},
"reviewerHasOrcid": {
"type": "boolean",
"readOnly": true
}
}
}
Expand Down

0 comments on commit c1d7493

Please sign in to comment.