Skip to content

Commit

Permalink
#9453 Add a new API endpoint for the review round history
Browse files Browse the repository at this point in the history
  • Loading branch information
nibou230 authored and defstat committed May 1, 2024
1 parent b4f4e51 commit 81520ee
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 151 deletions.
165 changes: 165 additions & 0 deletions api/v1/reviews/PKPReviewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

/**
* @file api/v1/reviews/PKPReviewController.php
*
* Copyright (c) 2023 Simon Fraser University
* Copyright (c) 2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PKPReviewController
*
* @ingroup api_v1_reviews
*
* @brief Handle API requests for reviews operations.
*
*/

namespace PKP\API\v1\reviews;

use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\log\SubmissionEmailLogEntry;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\SubmissionAccessPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;

class PKPReviewController extends PKPBaseController
{
/**
* @copydoc \PKP\core\PKPBaseController::getHandlerPath()
*/
public function getHandlerPath(): string
{
return 'reviews';
}

/**
* @copydoc \PKP\core\PKPBaseController::getRouteGroupMiddleware()
* @throws \Exception
*/
public function getRouteGroupMiddleware(): array
{
return [
'has.user',
'has.context',
self::roleAuthorizer([
Role::ROLE_ID_SITE_ADMIN,
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_REVIEWER,
]),
];
}

/**
* @throws \Exception
*/
public function getGroupRoutes(): void
{
Route::get('history/{submissionId}/{reviewRoundId}', $this->getHistory(...))
->name('review.get.submission.round.history')
->whereNumber(['reviewRoundId', 'submissionId']);
}

/**
* @copydoc \PKP\core\PKPBaseController::authorize()
*/
public function authorize(PKPRequest $request, array &$args, array $roleAssignments): bool
{
$illuminateRequest = $args[0]; /** @var \Illuminate\Http\Request $illuminateRequest */
$actionName = static::getRouteActionName($illuminateRequest);

$this->addPolicy(new UserRolesRequiredPolicy($request), true);
$this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));

if ($actionName === 'getHistory') {
$this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments, 'submissionId', true));
}

return parent::authorize($request, $args, $roleAssignments);
}

/**
* Get reviewer's submission round history
* @throws \Exception
*/
public function getHistory(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();

// TODO: get the reviewer ID from the request or from the route?
$reviewerId = $request->getUser()->getId();
//$reviewerId = $illuminateRequest->route('reviewerId');
$submissionId = $illuminateRequest->route('submissionId');
$reviewRoundId = $illuminateRequest->route('reviewRoundId');

$reviewAssignment = Repo::reviewAssignment()->getCollector()
->filterByContextIds([$contextId])
->filterBySubmissionIds([$submissionId])
->filterByReviewerIds([$reviewerId])
->filterByReviewRoundIds([$reviewRoundId])
->getMany()
->first();

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

$submission = Repo::submission()->get($submissionId, $contextId);
$publicationTitle = $submission->getCurrentPublication()->getLocalizedTitle();

$declineEmail = null;
if (!$reviewAssignment->getDeclined()) {
$submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO');
$emailLogs = $submissionEmailLogDao->getBySenderId($submissionId, SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_DECLINE, $reviewerId)->toArray();
// TODO: look for the right email log with the right round number.
if ($emailLogs) {
$emailLog = $emailLogs[0];
$declineEmail = [
'subject' => $emailLog->getData('subject'),
'body' => $emailLog->getData('body'),
];
}
}

$reviewAssignmentProps = Repo::reviewAssignment()->getSchemaMap()->map($reviewAssignment);

This comment has been minimized.

Copy link
@asmecher

asmecher May 7, 2024

Member

@defstat, I think this is missing a second parameter ($submission); it appears to be necessary.

This comment has been minimized.

Copy link
@asmecher

asmecher May 7, 2024

Member

Actually, @Vitaliy-1, I think this is a missed change in 199ee9a.

This comment has been minimized.

Copy link
@asmecher

asmecher May 7, 2024

Member

(Fixed: de3b6b1)


$reviewAssignmentId = $reviewAssignment->getId();
$submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO');
$comments = $submissionCommentDao->getReviewerCommentsByReviewerId($submissionId, $reviewerId, $reviewAssignmentId, true)->toArray();
$privateComments = $submissionCommentDao->getReviewerCommentsByReviewerId($submissionId, $reviewerId, $reviewAssignmentId, false)->toArray();

// TODO: get the comments data...

$lastReviewAssignment = Repo::reviewAssignment()->getCollector()
->filterByContextIds([$contextId])
->filterBySubmissionIds([$submissionId])
->filterByReviewerIds([$reviewerId])
->filterByLastReviewRound(true)
->getMany()
->first();
$displayFiles = $lastReviewAssignment->getDeclined() != 1;

$reviewRoundHistoryProps = [
'publicationTitle' => $publicationTitle,
'declineEmail' => $declineEmail,
'reviewAssignment' => $reviewAssignmentProps,
'comments' => $comments,
'privateComments' => $privateComments,
'displayFiles' => $displayFiles,
];

return response()->json($reviewRoundHistoryProps, Response::HTTP_OK);
}
}
145 changes: 0 additions & 145 deletions controllers/review/ReviewRoundModalHandler.php

This file was deleted.

15 changes: 12 additions & 3 deletions locale/en/reviewer.po
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,24 @@ msgstr "Evaluation cycle {$reviewRoundNumber} : {$submissionTitle}"
msgid "reviewer.submission.reviewRound.info.history"
msgstr "Review history"

msgid "reviewer.submission.comments.authorAndEditor"
msgid "reviewer.submission.reviewRound.comments.authorAndEditor"
msgstr "Author and editor"

msgid "reviewer.submission.comments.editorOnly"
msgid "reviewer.submission.reviewRound.comments.editorOnly"
msgstr "Editor only"

msgid "reviewer.submission.comments.review"
msgid "reviewer.submission.reviewRound.comments.review"
msgstr "Review"

msgid "reviewer.submission.reviewRound.emailLog"
msgstr "Decline reason sent by email"

msgid "reviewer.submission.reviewRound.emailLog.defaultMessage"
msgstr "No reason given to the decline of the review invitation."

msgid "reviewer.submission.reviewRound.reviewDeclineDate"
msgstr "Declined Date"

msgid "reviewer.complete"
msgstr "Review Submitted"

Expand Down
15 changes: 12 additions & 3 deletions locale/fr_CA/reviewer.po
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,24 @@ msgstr "Évaluation cycle {$reviewRoundNumber} : {$submissionTitle}"
msgid "reviewer.submission.reviewRound.info.history"
msgstr "Historique d'évaluation"

msgid "reviewer.submission.comments.authorAndEditor"
msgid "reviewer.submission.reviewRound.comments.authorAndEditor"
msgstr "Pour l'auteur et la rédaction"

msgid "reviewer.submission.comments.editorOnly"
msgid "reviewer.submission.reviewRound.comments.editorOnly"
msgstr "Pour la rédaction seulement"

msgid "reviewer.submission.comments.review"
msgid "reviewer.submission.reviewRound.comments.review"
msgstr "Évaluation"

msgid "reviewer.submission.reviewRound.emailLog"
msgstr "Raison du refus envoyée par courriel"

msgid "reviewer.submission.reviewRound.emailLog.defaultMessage"
msgstr "Aucune raison fournie pour le refus de l'invitation à évaluer."

msgid "reviewer.submission.reviewRound.reviewDeclineDate"
msgstr "Date du refus"

msgid "reviewer.complete"
msgstr "Évaluation envoyée"

Expand Down

0 comments on commit 81520ee

Please sign in to comment.