Skip to content

Commit

Permalink
pkp#8887 Review assignment refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Oct 30, 2023
1 parent 2981c28 commit d7a0287
Show file tree
Hide file tree
Showing 56 changed files with 1,347 additions and 321 deletions.
39 changes: 33 additions & 6 deletions api/v1/_submissions/PKPBackendSubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function getGroupRoutes(): void
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_ASSISTANT,
Role::ROLE_ID_AUTHOR,
]),
]);

Expand All @@ -122,18 +123,25 @@ public function getGroupRoutes(): void
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_ASSISTANT,
Role::ROLE_ID_AUTHOR,
])
]);

Route::get('viewsCount', $this->assigned(...))
->name('_submission.viewsCount')
->name('_submission.getViewsCount')
->middleware([
self::roleAuthorizer([
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_ASSISTANT,
])
]);

Route::get('reviewAssignments', $this->assigned(...))
->name('_submission.getReviewAssignments')
->middleware([
Role::ROLE_ID_REVIEWER,
]);
}
}

Expand Down Expand Up @@ -185,10 +193,6 @@ public function getMany(Request $illuminateRequest): JsonResponse
}
$collector->assignedTo($val);
break;

case 'isIncomplete':
$collector->filterByIncomplete(true);
break;
}
}

Expand Down Expand Up @@ -304,6 +308,12 @@ public function reviews(SlimRequest $slimRequest, APIResponse $response, array $
case 'reviewsOverdue':
$collector->filterByOverdue(true);
break;
case 'revisionsRequested':
$collector->filterByRevisionsRequested(true);
break;
case 'revisionsSubmitted':
$collector->filterByRevisionsSubmitted(true);
break;
}
}

Expand All @@ -326,7 +336,7 @@ public function reviews(SlimRequest $slimRequest, APIResponse $response, array $
/**
* Get a number of the submissions for each view
*/
public function viewsCount(SlimRequest $slimRequest, APIResponse $response, array $args): APIResponse
public function getViewsCount(SlimRequest $slimRequest, APIResponse $response, array $args): APIResponse
{
$request = Application::get()->getRequest();
$context = $request->getContext();
Expand All @@ -340,6 +350,19 @@ public function viewsCount(SlimRequest $slimRequest, APIResponse $response, arra
return $response->withJson($dashboardViews->map(fn(DashboardView $view) => $view->getCount()), 200);
}

/**
* Get all reviewer's assignments
*/
public function getReviewAssignments(SlimRequest $slimRequest, APIResponse $response, array $args)
{
$request = Application::get()->getRequest();
$context = $request->getContext();
if (!$context) {
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}
$currentUser = $request->getUser();
}

/**
* Delete a submission
*/
Expand Down Expand Up @@ -436,6 +459,10 @@ protected function getSubmissionCollector(array $queryParams): Collector
case 'isOverdue':
$collector->filterByOverdue(true);
break;

case 'isIncomplete':
$collector->filterByIncomplete(true);
break;
}
}

Expand Down
12 changes: 7 additions & 5 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,13 @@ public function getPublications(Request $illuminateRequest): JsonResponse
->filterByContextIds([$submission->getData('contextId')])
->getMany();

$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var \PKP\submission\reviewAssignment\ReviewAssignmentDAO $reviewAssignmentDao */
$currentUserReviewAssignment = $reviewAssignmentDao->getLastReviewRoundReviewAssignmentByReviewer(
$submission->getId(),
$request->getUser()->getId()
);
$currentUserReviewAssignment = Repo::reviewAssignment()->getCollector()
->filterBySubmissionIds([$submission->getId()])
->filterByReviewerIds([$request->getUser()->getId()])
->filterByLastReviewRound(true)
->getMany()
->first();

$anonymize = $currentUserReviewAssignment && $currentUserReviewAssignment->getReviewMethod() === ReviewAssignment::SUBMISSION_REVIEW_METHOD_DOUBLEANONYMOUS;

/** @var GenreDAO $genreDao */
Expand Down
40 changes: 17 additions & 23 deletions classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
use PKP\security\Role;
use PKP\security\Validation;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewAssignment\ReviewAssignmentDAO;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submission\reviewRound\ReviewRoundDAO;
use PKP\submission\SubmissionCommentDAO;
Expand Down Expand Up @@ -330,8 +329,12 @@ protected function loadData($request, $filter)
{
// Get the existing review assignments for this submission
$reviewRound = $this->getReviewRound();
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var ReviewAssignmentDAO $reviewAssignmentDao */
return $reviewAssignmentDao->getByReviewRoundId($reviewRound->getId());
return Repo::reviewAssignment()->getCollector()
->filterByReviewRoundIds([$reviewRound->getId()])
->getMany()
->keyBy(fn(ReviewAssignment $reviewAssignment, int $key) => $reviewAssignment->getId())
->sortKeys()
->toArray();
}


Expand Down Expand Up @@ -676,10 +679,8 @@ public function unconsiderReview($args, $request)
$submission = $this->getSubmission();
$user = $request->getUser();
$reviewAssignment = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REVIEW_ASSIGNMENT);
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var ReviewAssignmentDAO $reviewAssignmentDao */

$reviewAssignment->setConsidered(ReviewAssignment::REVIEW_ASSIGNMENT_UNCONSIDERED);
$reviewAssignmentDao->updateObject($reviewAssignment);
Repo::reviewAssignment()->edit($reviewAssignment, ['considered' => ReviewAssignment::REVIEW_ASSIGNMENT_UNCONSIDERED]);

// log the unconsider.
$eventLog = Repo::eventLog()->newDataObject([
Expand Down Expand Up @@ -718,39 +719,32 @@ public function reviewRead($args, $request)

// Rate the reviewer's performance on this assignment
$quality = $request->getUserVar('quality');
$newReviewData = [];
if ($quality) {
$reviewAssignment->setQuality((int) $quality);
$reviewAssignment->setDateRated(Core::getCurrentDate());
$newReviewData['quality'] = (int) $quality;
$newReviewData['dateRated'] = Core::getCurrentDate();
} else {
$reviewAssignment->setQuality(null);
$reviewAssignment->setDateRated(null);
$newReviewData['quality'] = $newReviewData['dateRated'] = null;
}

// Mark the latest read date of the review by the editor.
$user = $request->getUser();

// if the review assignment had been unconsidered, update the flag.
$reviewAssignment->setConsidered(
$reviewAssignment->getConsidered() === ReviewAssignment::REVIEW_ASSIGNMENT_NEW
? ReviewAssignment::REVIEW_ASSIGNMENT_CONSIDERED
: ReviewAssignment::REVIEW_ASSIGNMENT_RECONSIDERED
);
$newReviewData['considered'] = $reviewAssignment->getConsidered() === ReviewAssignment::REVIEW_ASSIGNMENT_NEW
? ReviewAssignment::REVIEW_ASSIGNMENT_CONSIDERED
: ReviewAssignment::REVIEW_ASSIGNMENT_RECONSIDERED;

if (!$reviewAssignment->getDateCompleted()) {
// Editor completes the review.
$reviewAssignment->setDateConfirmed(Core::getCurrentDate());
$reviewAssignment->setDateCompleted(Core::getCurrentDate());
$newReviewData['dateConfirmed'] = $newReviewData['dateCompleted'] = Core::getCurrentDate();
}

// Trigger an update of the review round status
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var ReviewAssignmentDAO $reviewAssignmentDao */
$reviewAssignmentDao->updateObject($reviewAssignment);
Repo::reviewAssignment()->edit($reviewAssignment, $newReviewData);

//if the review was read by an editor, log event
if ($reviewAssignment->isRead()) {
$submissionId = $reviewAssignment->getSubmissionId();
$submission = Repo::submission()->get($submissionId);

$user = $request->getUser();
$eventLog = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $submission->getId(),
Expand Down
1 change: 0 additions & 1 deletion classes/core/PKPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ public function getDAOMap()
'PluginSettingsDAO' => 'PKP\plugins\PluginSettingsDAO',
'PublicationDAO' => 'APP\publication\PublicationDAO',
'QueuedPaymentDAO' => 'PKP\payment\QueuedPaymentDAO',
'ReviewAssignmentDAO' => 'PKP\submission\reviewAssignment\ReviewAssignmentDAO',
'ReviewFilesDAO' => 'PKP\submission\ReviewFilesDAO',
'ReviewFormDAO' => 'PKP\reviewForm\ReviewFormDAO',
'ReviewFormElementDAO' => 'PKP\reviewForm\ReviewFormElementDAO',
Expand Down
6 changes: 4 additions & 2 deletions classes/decision/types/CancelReviewRound.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace PKP\decision\types;

use APP\decision\Decision;
use APP\facades\Repo;
use APP\submission\Submission;
use Illuminate\Validation\Validator;
use PKP\context\Context;
Expand Down Expand Up @@ -193,10 +194,11 @@ public function runAdditionalActions(Decision $decision, Submission $submission,
}

$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var \PKP\submission\reviewAssignment\ReviewAssignmentDAO $reviewAssignmentDao */
$reviewRoundId = $decision->getData('reviewRoundId');

$reviewAssignmentDao->deleteByReviewRoundId($reviewRoundId);
Repo::reviewAssignment()->deleteMany(
Repo::reviewAssignment()->getCollector()->filterByReviewRoundIds([$reviewRoundId])
);
$reviewRoundDao->deleteById($reviewRoundId);
}

Expand Down
13 changes: 8 additions & 5 deletions classes/decision/types/traits/InExternalReviewRound.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
use PKP\components\fileAttachers\ReviewFiles;
use PKP\components\fileAttachers\Upload;
use PKP\context\Context;
use PKP\db\DAORegistry;
use PKP\submission\reviewAssignment\ReviewAssignmentDAO;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submissionFile\SubmissionFile;

Expand Down Expand Up @@ -78,9 +77,13 @@ protected function getFileAttachers(Submission $submission, Context $context, ?R
];

if ($reviewRound) {
/** @var ReviewAssignmentDAO $reviewAssignmentDAO */
$reviewAssignmentDAO = DAORegistry::getDAO('ReviewAssignmentDAO');
$reviewAssignments = $reviewAssignmentDAO->getByReviewRoundId($reviewRound->getId());
$reviewAssignments = Repo::reviewAssignment()->getCollector()
->filterByReviewRoundIds([$reviewRound->getId()])
->getMany()
->keyBy(fn(ReviewAssignment $reviewAssignment, int $key) => $reviewAssignment->getId())
->sortKeys()
->toArray();

$reviewerFiles = [];
if (!empty($reviewAssignments)) {
$reviewerFiles = Repo::submissionFile()
Expand Down
17 changes: 8 additions & 9 deletions classes/decision/types/traits/NotifyReviewers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
use Illuminate\Validation\Validator;
use PKP\core\Core;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\log\event\PKPSubmissionEventLogEntry;
use PKP\mail\EmailData;
use PKP\mail\mailables\DecisionNotifyReviewer;
use PKP\mail\mailables\ReviewerUnassign;
use PKP\security\Validation;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewAssignment\ReviewAssignmentDAO;
use PKP\user\User;

trait NotifyReviewers
Expand All @@ -52,13 +49,15 @@ protected function sendReviewersEmail(DecisionNotifyReviewer|ReviewerUnassign $m

// Update the ReviewAssignment to indicate the reviewer has been acknowledged
if (is_a($mailable, DecisionNotifyReviewer::class)) {
/** @var ReviewAssignmentDAO $reviewAssignmentDao */
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
$reviewAssignment = $reviewAssignmentDao->getReviewAssignment($mailable->getDecision()->getData('reviewRoundId'), $recipient->getId());
$reviewAssignment = Repo::reviewAssignment()->getCollector()
->filterByReviewRoundIds([$mailable->getDecision()->getData('reviewRoundId')])
->filterByReviewerIds([$recipient->getId()])
->getMany()
->first();
if ($reviewAssignment) {
$reviewAssignment->setDateAcknowledged(Core::getCurrentDate());
$reviewAssignment->stampModified();
$reviewAssignmentDao->updateObject($reviewAssignment);
Repo::reviewAssignment()->edit($reviewAssignment, [
'dateAcknowledged' => Core::getCurrentDate(),
]);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions classes/decision/types/traits/WithReviewAssignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

namespace PKP\decision\types\traits;

use APP\facades\Repo;
use Exception;
use PKP\db\DAORegistry;
use PKP\decision\DecisionType;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submission\reviewAssignment\ReviewAssignmentDAO;

trait WithReviewAssignments
{
Expand All @@ -36,10 +35,12 @@ trait WithReviewAssignments
*/
protected function getReviewAssignments(int $submissionId, int $reviewRoundId, int $reviewAssignmentStatus): array
{
/** @var ReviewAssignmentDAO $reviewAssignmentDao */
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
$reviewAssignments = Repo::reviewAssignment()->getCollector()
->filterByReviewRoundIds([$reviewRoundId])
->filterBySubmissionIds([$submissionId])
->filterByStageId($this->getStageId())
->getMany();

$reviewAssignments = $reviewAssignmentDao->getBySubmissionId($submissionId, $reviewRoundId, $this->getStageId());
$assignments = [];

foreach ($reviewAssignments as $reviewAssignment) {
Expand Down
7 changes: 2 additions & 5 deletions classes/invitation/invitations/ReviewerAccessInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use APP\facades\Repo;
use Illuminate\Mail\Mailable;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\invitation\invitations\enums\InvitationStatus;
use PKP\mail\variables\ReviewAssignmentEmailVariable;
use PKP\security\Validation;
Expand All @@ -46,8 +45,7 @@ public function __construct(

parent::__construct($invitedUserId, null, $contextId, $reviewAssignmentId, $expiryDays);

$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var ReviewAssignmentDAO $reviewAssignmentDao */
$this->reviewAssignment = $reviewAssignmentDao->getById($reviewAssignmentId);
$this->reviewAssignment = Repo::reviewAssignment()->get($this->reviewAssignmentId);
}

public function getMailable(): ?Mailable
Expand Down Expand Up @@ -127,8 +125,7 @@ private function _validateAccessKey(): bool
return false;
}

$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var ReviewAssignmentDAO $reviewAssignmentDao */
$reviewAssignment = $reviewAssignmentDao->getById($reviewId);
$reviewAssignment = Repo::reviewAssignment()->get($reviewId);
if (!$reviewAssignment) {
return false;
} // e.g. deleted review assignment
Expand Down
6 changes: 2 additions & 4 deletions classes/log/event/EventLogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use APP\core\Application;
use APP\facades\Repo;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\submissionFile\SubmissionFile;
Expand Down Expand Up @@ -196,12 +195,11 @@ public function getTranslatedMessage($locale = null, $hideReviewerName = false)
$eventLog = clone $this;

if ($hideReviewerName) {
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /** @var \PKP\submission\reviewAssignment\ReviewAssignmentDAO $reviewAssignmentDao */
// Reviewer activity log entries (assigning, accepting, declining)
if ($eventLog->getData('reviewerName')) {
$anonymousAuthor = true;
if ($reviewAssignmentId = $eventLog->getData('reviewAssignmentId')) {
$reviewAssignment = $reviewAssignmentDao->getById($reviewAssignmentId);
$reviewAssignment = Repo::reviewAssignment()->get($reviewAssignmentId);
if ($reviewAssignment && !in_array($reviewAssignment->getReviewMethod(), [ReviewAssignment::SUBMISSION_REVIEW_METHOD_ANONYMOUS, ReviewAssignment::SUBMISSION_REVIEW_METHOD_DOUBLEANONYMOUS])) {
$anonymousAuthor = false;
}
Expand All @@ -218,7 +216,7 @@ public function getTranslatedMessage($locale = null, $hideReviewerName = false)
$anonymousAuthor = true;
$submissionFile = Repo::submissionFile()->get($submissionFileId);
if ($submissionFile && $submissionFile->getData('assocType') === Application::ASSOC_TYPE_REVIEW_ASSIGNMENT) {
$reviewAssignment = $reviewAssignmentDao->getById($submissionFile->getData('assocId'));
$reviewAssignment = Repo::reviewAssignment()->get($submissionFile->getData('assocId'));
if ($reviewAssignment && !in_array($reviewAssignment->getReviewMethod(), [ReviewAssignment::SUBMISSION_REVIEW_METHOD_ANONYMOUS, ReviewAssignment::SUBMISSION_REVIEW_METHOD_DOUBLEANONYMOUS])) {
$anonymousAuthor = false;
}
Expand Down
Loading

0 comments on commit d7a0287

Please sign in to comment.