Skip to content

Commit

Permalink
Merge branch 'checkAuthorOrcids-582' into 'main'
Browse files Browse the repository at this point in the history
Utiliza ORCID para verificar se endosso não é de autor

See merge request softwares-pkp/plugins_ojs/pre-endorsement-plaudit!16
  • Loading branch information
JhonathanLepidus committed Aug 24, 2023
2 parents be1ad42 + 1ec313b commit fb10d35
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
21 changes: 13 additions & 8 deletions classes/PlauditPreEndorsementHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function updateEndorser($args, $request)
return;
}

if($this->checkEndorsementFromAuthor($publication, $endorserEmail)) {
if($this->checkDataIsFromAnyAuthor($publication, 'email', $endorserEmail)) {
http_response_code(400);
header('Content-Type: application/json');
echo json_encode(['errorMessage' => __('plugins.generic.plauditPreEndorsement.endorsementFromAuthor')]);
Expand All @@ -50,12 +50,12 @@ public function updateEndorser($args, $request)
return http_response_code(200);
}

private function checkEndorsementFromAuthor($publication, $endorserEmail): bool
private function checkDataIsFromAnyAuthor($publication, $dataName, $dataValue): bool
{
$authors = $publication->getData('authors');

foreach($authors as $author) {
if($author->getData('email') == $endorserEmail) {
if($author->getData($dataName) == $dataValue) {
return true;
}
}
Expand Down Expand Up @@ -121,19 +121,19 @@ public function orcidVerify($args, $request)

$statusAuth = $this->getStatusAuthentication($publication, $request);
if ($statusAuth == AUTH_INVALID_TOKEN) {
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.invalidToken', ['verifySuccess' => false, 'invalidToken' => true]);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.invalidToken', ['errorType' => 'invalidToken']);
return;
} elseif ($statusAuth == AUTH_ACCESS_DENIED) {
$this->setAccessDeniedEndorsement($publication);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidAccessDenied', ['verifySuccess' => false, 'denied' => true]);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidAccessDenied', ['errorType' => 'denied']);
return;
}

try {
$response = $this->requestOrcid($request, $plugin);
$responseJson = json_decode($response->getBody(), true);
} catch (GuzzleHttp\Exception\RequestException $exception) {
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidRequestError', ['orcidAPIError' => $exception->getMessage(), 'verifySuccess' => false]);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidRequestError', ['errorType' => 'failure', 'orcidAPIError' => $exception->getMessage()]);
return;
}

Expand All @@ -143,14 +143,19 @@ public function orcidVerify($args, $request)
$orcidUri = ($isSandBox ? ENDORSEMENT_ORCID_URL_SANDBOX : ENDORSEMENT_ORCID_URL) . $responseJson['orcid'];

if ($response->getStatusCode() == 200 && strlen($responseJson['orcid']) > 0) {
if($this->checkDataIsFromAnyAuthor($publication, 'orcid', $orcidUri)) {
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.endorserOrcidFromAuthor', ['errorType' => 'orcidFromAuthor']);
return;
}

$this->setConfirmedEndorsementPublication($publication, $orcidUri);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.endorsementConfirmed', ['verifySuccess' => true, 'orcid' => $orcidUri]);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.endorsementConfirmed', ['orcid' => $orcidUri]);

if($publication->getData('status') === STATUS_PUBLISHED) {
$plugin->sendEndorsementToPlaudit($publication);
}
} else {
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidRequestError', ['authFailure' => true, 'orcidAPIError' => $response->getReasonPhrase(), 'verifySuccess' => true]);
$this->logMessageAndDisplayTemplate($submission, $request, 'plugins.generic.plauditPreEndorsement.log.orcidRequestError', ['errorType' => 'authFailure', 'orcidAPIError' => $response->getReasonPhrase()]);
}
}

Expand Down
6 changes: 6 additions & 0 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ msgstr "You denied access to your ORCID record"
msgid "plugins.generic.plauditPreEndorsement.verify.authFailure"
msgstr "The ORCID authorization link has already been used or is invalid"

msgid "plugins.generic.plauditPreEndorsement.verify.orcidFromAuthor"
msgstr "The ORCID informed for the endorser cannot be the same as one of the authors of the submission"

msgid "plugins.generic.plauditPreEndorsement.failure.contact"
msgstr "Please contact the server manager with your name, ORCID iD, and details of your submission"

Expand All @@ -156,6 +159,9 @@ msgstr "The endorser denied access to its ORCID"
msgid "plugins.generic.plauditPreEndorsement.log.orcidRequestError"
msgstr "An error occurred during the endorser's ORCID requesting. The message returned was: {$orcidAPIError}"

msgid "plugins.generic.plauditPreEndorsement.log.endorserOrcidFromAuthor"
msgstr "The endorsement has not been confirmed, as the ORCID provided is from one of the authors"

msgid "plugins.generic.plauditPreEndorsement.log.endorsementConfirmed"
msgstr "The endorsement has been confirmed by the endorser and its ORCID has been stored in the submission"

Expand Down
6 changes: 6 additions & 0 deletions locale/es_ES/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ msgstr "Ha denegado el acceso a su registro ORCID"
msgid "plugins.generic.plauditPreEndorsement.verify.authFailure"
msgstr "El enlace de autorización ORCID ya se ha utilizado o no es válido"

msgid "plugins.generic.plauditPreEndorsement.verify.orcidFromAuthor"
msgstr "El ORCID proporcionado para el endosante no debe ser el mismo que el de uno de los autores del envío"

msgid "plugins.generic.plauditPreEndorsement.failure.contact"
msgstr "Comuníquese con el administrador del servidor con su nombre, ORCID ID y detalles de envío"

Expand All @@ -156,6 +159,9 @@ msgstr "El endosante ha denegado el acceso a su ORCID"
msgid "plugins.generic.plauditPreEndorsement.log.orcidRequestError"
msgstr "Se ha producido un error al solicitar el ORCID del endosante. El mensaje devuelto fue: {$orcidAPIError}"

msgid "plugins.generic.plauditPreEndorsement.log.endorserOrcidFromAuthor"
msgstr "El endoso no ha sido confirmado, ya que el ORCID facilitado es el de uno de los autores"

msgid "plugins.generic.plauditPreEndorsement.log.endorsementConfirmed"
msgstr "El endoso ha sido confirmado por el endosante y su ORCID se ha guardado en el envío"

Expand Down
6 changes: 6 additions & 0 deletions locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ msgstr "Você negou acesso ao seu registro ORCID"
msgid "plugins.generic.plauditPreEndorsement.verify.authFailure"
msgstr "O link de autorização ORCID já foi utilizado ou é inválido"

msgid "plugins.generic.plauditPreEndorsement.verify.orcidFromAuthor"
msgstr "O ORCID informado para o(a) endossador(a) não pode ser o mesmo de um dos autores da submissão"

msgid "plugins.generic.plauditPreEndorsement.failure.contact"
msgstr "Por favor, entre em contato com o administrador do servidor, informando seu nome, ORCID ID e detalhes da submissão"

Expand All @@ -156,6 +159,9 @@ msgstr "O(A) endossador(a) negou acesso ao seu ORCID"
msgid "plugins.generic.plauditPreEndorsement.log.orcidRequestError"
msgstr "Ocorreu um erro durante a requisição do ORCID do(a) endossador(a). A mensagem retornada foi: {$orcidAPIError}"

msgid "plugins.generic.plauditPreEndorsement.log.endorserOrcidFromAuthor"
msgstr "O endosso não foi confirmado, pois o ORCID informado é de um dos autores"

msgid "plugins.generic.plauditPreEndorsement.log.endorsementConfirmed"
msgstr "O endosso foi confirmado pelo(a) endossador(a) e seu ORCID foi salvo na submissão"

Expand Down
14 changes: 3 additions & 11 deletions templates/orcidVerify.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{translate key="plugins.generic.plauditPreEndorsement.verify.title"}
</h2>
<div class="description">
{if $verifySuccess}
{if not isset($errorType)}
<p>
<span class="orcid"><a href="{$orcid|escape}" target="_blank">{$orcid|escape}</a></span>
</p>
Expand All @@ -23,19 +23,11 @@
</div>
{else}
<div class="orcid-failure">
{if $orcidAPIError}
{if isset($orcidAPIError)}
{$orcidAPIError}
{/if}

{if $denied}
{translate key="plugins.generic.plauditPreEndorsement.verify.denied"}
{elseif $invalidToken}
{translate key="plugins.generic.plauditPreEndorsement.verify.invalidToken"}
{elseif $authFailure}
{translate key="plugins.generic.plauditPreEndorsement.verify.authFailure"}
{else}
{translate key="plugins.generic.plauditPreEndorsement.verify.failure"}
{/if}
{translate key="plugins.generic.plauditPreEndorsement.verify.{$errorType}"}
</div>
{translate key="plugins.generic.plauditPreEndorsement.failure.contact"}
{/if}
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<application>plauditPreEndorsement</application>
<type>plugins.generic</type>
<lazy-load>0</lazy-load>
<release>1.2.0.0</release>
<date>2023-08-23</date>
<release>1.2.1.0</release>
<date>2023-08-24</date>
<class>PlauditPreEndorsementPlugin</class>
</version>

0 comments on commit fb10d35

Please sign in to comment.