Skip to content

Commit 1bd63d3

Browse files
authored
Merge pull request #11314 from Vitaliy-1/stable-3_5_0-i11252-fix
#11252 Fix review assignment collector
2 parents 6db9b66 + d1ce8e9 commit 1bd63d3

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

api/v1/_submissions/PKPBackendSubmissionsController.php

-3
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ public function getReviewAssignments(Request $illuminateRequest): JsonResponse
391391
case 'published':
392392
$collector->filterByPublished(true);
393393
break;
394-
case 'allReviewRounds':
395-
$collector->filterByReviewerIds([$currentUser->getId()]);
396-
break;
397394
}
398395
}
399396

classes/security/authorization/internal/ReviewAssignmentAccessPolicy.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public function effect(): int
6969

7070
$reviewAssignment = Repo::reviewAssignment()->getCollector()
7171
->filterBySubmissionIds([$submission->getId()])
72-
->filterByReviewerIds([$user->getId()])
73-
->filterByLastReviewRound(true)
72+
->filterByReviewerIds([$user->getId()], true)
7473
->getMany()
7574
->first();
7675

classes/submission/reviewAssignment/Collector.php

+42-21
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,24 @@ public function orderBySubmissionId(string $direction = self::ORDER_DIR_ASC): st
282282
public function getQueryBuilder(): Builder
283283
{
284284
$q = DB::table($this->dao->table . ' as ra')
285-
// Aggregate the latest review round number for the given assignment
285+
// Aggregating data regarding latest review round and stage. For OMP the latest round isn't equal to the round with the highest number per submission
286286
->leftJoinSub(
287-
DB::table('review_rounds', 'rr')
288-
->select('rr.submission_id')
289-
->selectRaw('MAX(rr.round) as current_round')
290-
->selectRaw('MAX(rr.stage_id) as current_stage')
291-
->groupBy('rr.submission_id'),
292-
'agrr',
293-
fn (JoinClause $join) => $join->on('ra.submission_id', '=', 'agrr.submission_id')
294-
)
295-
->select(['ra.*']);
287+
DB::table('review_assignments as rr')
288+
->select(['rr.submission_id', 'rr.stage_id'])
289+
->selectRaw('MAX(rr.round) as latest_round')
290+
->groupBy('rr.submission_id', 'rr.stage_id')
291+
->leftJoinSub(
292+
DB::table('review_assignments as rs')
293+
->select('rs.submission_id')
294+
->selectRaw('MAX(rs.stage_id) as latest_stage')
295+
->groupBy('rs.submission_id'),
296+
'rsmax',
297+
fn (JoinClause $join) => $join->on('rr.submission_id', '=', 'rsmax.submission_id')
298+
)
299+
->whereColumn('rr.stage_id', 'rsmax.latest_stage'), // Take the highest round only from the latest stage
300+
'rrmax',
301+
fn (JoinClause $join) => $join->on('ra.submission_id', '=', 'rrmax.submission_id')
302+
);
296303

297304
$q->when(
298305
$this->contextIds !== null,
@@ -314,8 +321,8 @@ public function getQueryBuilder(): Builder
314321

315322
$q->when($this->isLastReviewRound || $this->isIncomplete, function (Builder $q) {
316323
$q
317-
->whereColumn('ra.round', '=', 'agrr.current_round') // assignments from the last review round only
318-
->whereColumn('ra.stage_id', '=', 'agrr.current_stage') // assignments for the current review stage only (for OMP)
324+
->whereColumn('ra.round', '=', 'rrmax.latest_round') // assignments from the last review round only
325+
->whereColumn('ra.stage_id', '=', 'rrmax.stage_id') // assignments for the current review stage only (for OMP)
319326
->when(
320327
$this->isIncomplete,
321328
fn (Builder $q) => $q
@@ -450,19 +457,33 @@ public function getQueryBuilder(): Builder
450457
->when(
451458
$this->isLastReviewRoundByReviewer,
452459
fn (Builder $q) => $q
453-
// Aggregate the latest review round number for the given assignment and reviewer
454460
->leftJoinSub(
461+
// Determine the last review round the reviewer has assignments in
455462
DB::table('review_assignments as ramax')
456-
->select(['ramax.submission_id', 'ramax.reviewer_id'])
463+
->select(['ramax.submission_id', 'ramax.reviewer_id', 'ramax.stage_id'])
457464
->selectRaw('MAX(ramax.round) as latest_round')
458-
->selectRaw('MAX(ramax.stage_id) as latest_stage')
459-
->whereIn('ramax.reviewer_id', $this->reviewerIds)
460-
->groupBy(['ramax.submission_id', 'ramax.reviewer_id']),
461-
'agrmax',
462-
fn (JoinClause $join) => $join->on('ra.submission_id', '=', 'agrmax.submission_id')
465+
->groupBy(['ramax.submission_id', 'ramax.reviewer_id', 'ramax.stage_id'])
466+
/*
467+
* Reviewers might have assignments in the Internal but not External review stage.
468+
* Must aggregate data regarding the last review stage the reviewer has assignments in
469+
*/
470+
->leftJoinSub(
471+
DB::table('review_assignments as rsmax')
472+
->select(['rsmax.submission_id', 'rsmax.reviewer_id'])
473+
->selectRaw('MAX(rsmax.stage_id) as latest_stage')
474+
->groupBy(['rsmax.submission_id', 'rsmax.reviewer_id'])
475+
->where('rsmax.reviewer_id', $this->reviewerIds),
476+
'rssmax',
477+
fn (JoinClause $join) => $join->on('ramax.submission_id', '=', 'rssmax.submission_id')
478+
)
479+
->whereColumn('ramax.reviewer_id', 'rssmax.reviewer_id') // Take only selected reviewers
480+
->whereColumn('ramax.stage_id', 'rssmax.latest_stage'), // Take only the current stage
481+
'raamax',
482+
fn (JoinClause $join) => $join->on('ra.submission_id', '=', 'raamax.submission_id')
463483
)
464-
->whereColumn('ra.round', 'agrmax.latest_round') // assignments from the last review round per reviewer only
465-
->whereColumn('ra.stage_id', 'agrmax.latest_stage') // assignments for the current review stage only (for OMP)
484+
->whereColumn('ra.reviewer_id', 'raamax.reviewer_id') // Finally fitler by reviewers
485+
->whereColumn('ra.stage_id', 'raamax.stage_id') // Finally filter by the latest review stage
486+
->whereColumn('ra.round', 'raamax.latest_round') // Finally filter by the latest review round
466487
)
467488
);
468489

0 commit comments

Comments
 (0)