Skip to content

Commit

Permalink
pkp#6998 Don't allow mixed type for assignedTo query param
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 18, 2024
1 parent 23cac6b commit 7144d53
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
9 changes: 4 additions & 5 deletions api/v1/_submissions/PKPBackendSubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ public function getMany(Request $illuminateRequest): JsonResponse
foreach ($queryParams as $param => $val) {
switch ($param) {
case 'assignedTo':
$val = array_map(intval(...), paramToArray($val));
if ($val == [\PKP\submission\Collector::UNASSIGNED]) {
$val = array_shift($val);
}
$collector->assignedTo($val);
$collector->assignedTo(array_map(intval(...), paramToArray($val)));
break;
}
}
Expand Down Expand Up @@ -581,6 +577,9 @@ protected function getSubmissionCollector(array $queryParams): Collector
case 'isIncomplete':
$collector->filterByIncomplete(true);
break;
case 'isUnassigned':
$collector->filterByisUnassigned(true);
break;
}
}

Expand Down
9 changes: 4 additions & 5 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,7 @@ protected function getSubmissionCollector(array $queryParams): Collector
break;

case 'assignedTo':
$val = array_map(intval(...), paramToArray($val));
if ($val == [\PKP\submission\Collector::UNASSIGNED]) {
$val = array_shift($val);
}
$collector->assignedTo($val);
$collector->assignedTo(array_map(intval(...), paramToArray($val)));
break;

case 'daysInactive':
Expand Down Expand Up @@ -519,6 +515,9 @@ protected function getSubmissionCollector(array $queryParams): Collector
case 'hasDois':
$collector->filterByHasDois((bool) $val, $context->getEnabledDoiTypes());
break;
case 'isUnassigned':
$collector->filterByisUnassigned(true);
break;
}
}

Expand Down
19 changes: 13 additions & 6 deletions classes/submission/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ abstract class Collector implements CollectorInterface, ViewsCount
public const ORDER_DIR_ASC = 'ASC';
public const ORDER_DIR_DESC = 'DESC';

public const UNASSIGNED = -1;

public DAO $dao;
public ?array $categoryIds = null;
public ?array $contextIds = null;
Expand All @@ -70,6 +68,7 @@ abstract class Collector implements CollectorInterface, ViewsCount
public ?array $doiStatuses = null;
public ?bool $hasDois = null;
public ?array $excludeIds = null;
public bool $isUnassigned = false;

/** @var array Which DOI types should be considered when checking if a submission has DOIs set */
public array $enabledDoiTypes = [];
Expand Down Expand Up @@ -186,6 +185,15 @@ public function filterByIncomplete(bool $isIncomplete): AppCollector
$this->isIncomplete = $isIncomplete;
return $this;
}
/**
* Limit results to unassigned submissions
*
*/
public function filterByisUnassigned(bool $isUnassigned): AppCollector
{
$this->isUnassigned = $isUnassigned;
return $this;
}

/**
* Limit results to submissions with overdue tasks
Expand Down Expand Up @@ -268,7 +276,6 @@ public function filterBySubmissionIds(?array $submissionIds): static
* Limit results to submissions assigned to these users
*
* @param int|array $assignedTo An array of user IDs
* or self::UNASSIGNED to get unassigned submissions
*/
public function assignedTo($assignedTo): AppCollector
{
Expand All @@ -279,7 +286,7 @@ public function assignedTo($assignedTo): AppCollector
/**
* Limit results to submissions currently being reviewed by this users
*
* @param int|array|null $isReviewedBy An array of user IDs or self::UNASSIGNED to get unassigned submissions
* @param int|array|null $isReviewedBy An array of user IDs
*/
public function isReviewedBy(int|array|null $isReviewedBy): AppCollector
{
Expand Down Expand Up @@ -536,7 +543,7 @@ public function getQueryBuilder(): Builder
->whereNotNull('sa.stage_assignment_id')
->orWhereNotNull('ra.review_id')
);
} elseif ($this->assignedTo === self::UNASSIGNED) {
} elseif ($this->isUnassigned) {
$sub = DB::table('stage_assignments')
->select(DB::raw('count(stage_assignments.stage_assignment_id)'))
->leftJoin('user_groups', 'stage_assignments.user_group_id', '=', 'user_groups.user_group_id')
Expand All @@ -556,7 +563,7 @@ public function getQueryBuilder(): Builder
$q->leftJoinSub(
fn (Builder $q) => $q
->from('review_assignments', 'ra')
->whereIn('ra.reviewer_id', $this->assignedTo == self::UNASSIGNED ? [] : (array) $this->assignedTo)
->whereIn('ra.reviewer_id', $this->isUnassigned ? [] : (array) $this->assignedTo)
->select(DB::raw('1 AS value'))
->limit(1),
'any_assignment',
Expand Down
4 changes: 2 additions & 2 deletions classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ protected function mapDashboardViews(Collection $types, Context $context, User $
[Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER],
Repo::submission()->getCollector()
->filterByContextIds([$context->getId()])
->assignedTo(SubmissionCollector::UNASSIGNED)
->filterByisUnassigned(true)
->filterByStatus([PKPSubmission::STATUS_QUEUED]),
null,
['assignedTo' => SubmissionCollector::UNASSIGNED, 'status' => [PKPSubmission::STATUS_QUEUED]]
['isUnassigned' => true, 'status' => [PKPSubmission::STATUS_QUEUED]]
);
case DashboardView::TYPE_SUBMISSION:
$collector = Repo::submission()->getCollector()
Expand Down
2 changes: 1 addition & 1 deletion pages/dashboard/DashboardHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function index($args, $request)
'apiUrl' => $apiUrl,
'getParams' => [
'status' => PKPSubmission::STATUS_QUEUED,
'assignedTo' => \PKP\submission\Collector::UNASSIGNED,
'isUnassigned' => true,
],
'lazyLoad' => true,
'includeIssuesFilter' => $includeIssuesFilter,
Expand Down

0 comments on commit 7144d53

Please sign in to comment.