Skip to content

Commit 03a93f3

Browse files
committed
pkp/pkp-lib#10819 Unable to update OAuth scope for authenticated ORCIDs
1 parent 6118fe8 commit 03a93f3

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

config.TEMPLATE.inc.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@
162162
[cache]
163163

164164
; Default driver for Laravel-based caching. Currently supports opcache and file drivers.
165-
; By default, the opcache is used.
166-
; default = opcache
165+
; By default, the file is used.
166+
; default = file
167167

168168
; Path to store cache contents for file or opcode based caches.
169169
; path = cache/opcache

dbscripts/xml/upgrade.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124

125125
<upgrade minversion="3.4.0.0" maxversion="3.4.9.9">
126126
<migration class="APP\migration\upgrade\v3_4_0\I9813_QuickSubmitSubmissionProgressType"/>
127-
<migration class="PKP\migration\upgrade\v3_4_0\I9822_ChangeUsageStatsTemporaryTablesIndexes"/>
128127
</upgrade>
129128

130129
<upgrade minversion="3.1.0.0" maxversion="3.4.9.9">
@@ -163,6 +162,7 @@
163162
<migration class="PKP\migration\upgrade\v3_5_0\I7135_CreateAuthorAffiliationsTables"/>
164163
<migration class="PKP\migration\upgrade\v3_5_0\I7135_CreateNewRorRegistryCacheTables"/>
165164
<migration class="PKP\migration\upgrade\v3_5_0\I10759_AddReviewAssignmentSettings"/>
165+
<migration class="PKP\migration\upgrade\v3_5_0\I10819_OrcidOauthScopeMail"/>
166166
<note file="docs/release-notes/README-3.5.0" />
167167
</upgrade>
168168

jobs/orcid/DepositOrcidReview.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
use APP\orcid\OrcidReview;
2222
use Carbon\Carbon;
2323
use GuzzleHttp\Exception\ClientException;
24+
use Illuminate\Contracts\Queue\ShouldBeUnique;
2425
use PKP\config\Config;
2526
use PKP\jobs\BaseJob;
27+
use PKP\jobs\orcid\SendUpdateScopeMail;
28+
use PKP\orcid\enums\OrcidDepositType;
2629
use PKP\orcid\OrcidManager;
2730
use PKP\submission\reviewAssignment\ReviewAssignment;
2831

29-
class DepositOrcidReview extends BaseJob
32+
class DepositOrcidReview extends BaseJob implements ShouldBeUnique
3033
{
3134
public function __construct(
3235
private int $reviewAssignmentId
@@ -45,7 +48,7 @@ public function handle(): void
4548
}
4649

4750
if (!in_array($reviewAssignment->getStatus(), ReviewAssignment::REVIEW_COMPLETE_STATUSES)) {
48-
$this->fail('Review assignment was not completed.');
51+
return;
4952
}
5053

5154
$submission = Repo::submission()->get($reviewAssignment->getSubmissionId());
@@ -56,7 +59,7 @@ public function handle(): void
5659
$this->fail('Application is set to sandbox mode and will not interact with the ORCID service');
5760
}
5861

59-
if (OrcidManager::isEnabled($context)) {
62+
if (!OrcidManager::isEnabled($context)) {
6063
return;
6164
}
6265

@@ -71,6 +74,13 @@ public function handle(): void
7174
$reviewer = Repo::user()->get($reviewAssignment->getData('reviewerId'));
7275

7376
if ($reviewer->getOrcid() && $reviewer->getData('orcidAccessToken')) {
77+
// Check user scope, if public API, stop here and request member scope
78+
if ($reviewer->getData('orcidAccessScope') !== OrcidManager::ORCID_API_SCOPE_MEMBER) {
79+
// Request member scope and retry deposit
80+
dispatch(new SendUpdateScopeMail($reviewer, $context->getId(), $this->reviewAssignmentId, OrcidDepositType::REVIEW));
81+
return;
82+
}
83+
7484
$orcidAccessExpiresOn = Carbon::parse($reviewer->getData('orcidAccessExpiresOn'));
7585
if ($orcidAccessExpiresOn->isFuture()) {
7686
# Extract only the ORCID from the stored ORCID uri
@@ -121,12 +131,17 @@ public function handle(): void
121131
OrcidManager::logError("Unexpected status {$httpStatus} response, body: " . json_encode($responseHeaders));
122132
}
123133
} catch (ClientException $exception) {
124-
$reason = $exception->getResponse()->getBody();
134+
$reason = $exception->getResponse()->getBody()->getContents();
125135
OrcidManager::logError("Publication fail: {$reason}");
126136

127137
$this->fail($exception);
128138
}
129139
}
130140
}
131141
}
142+
143+
public function uniqueId(): string
144+
{
145+
return (string) $this->reviewAssignmentId;
146+
}
132147
}

registry/emailTemplates.xml

+1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@
8181
<email key="ORCID_REQUEST_AUTHOR_AUTHORIZATION" name="orcidProfile.orcidRequestAuthorAuthorization.name" subject="emails.orcidRequestAuthorAuthorization.subject" body="emails.orcidRequestAuthorAuthorization.body"/>
8282
<email key="USER_ROLE_ASSIGNMENT_INVITATION" name="mailable.userRoleAssignmentInvitationNotify.name" subject="emails.userRoleAssignmentInvitationNotify.subject" body="emails.userRoleAssignmentInvitationNotify.body"/>
8383
<email key="USER_ROLE_END" name="mailable.userRoleEndNotify.name" subject="emails.userRoleEndNotify.subject" body="emails.userRoleEndNotify.body"/>
84+
<email key="ORCID_REQUEST_UPDATE_SCOPE" name="orcid.orcidRequestUpdateScope.name" subject="emails.orcidRequestUpdateScope.subject" body="emails.orcidRequestUpdateScope.body"/>
8485
</emails>

0 commit comments

Comments
 (0)