Skip to content

Commit cdc83ce

Browse files
authored
Merge pull request #107 from topcoder-platform/PM-5065_handle-approval-filter
PM-5065 - allow projectIds[] param for fetching challenges
2 parents c888d61 + 75983c3 commit cdc83ce

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

docs/swagger.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ paths:
189189
required: false
190190
type: integer
191191
minimum: 1
192+
- name: projectIds
193+
in: query
194+
description: Filter by multiple v5 project ids (array). Use repeated query params, e.g. projectIds[]=1&projectIds[]=2.
195+
required: false
196+
type: array
197+
items:
198+
type: integer
199+
minimum: 1
200+
collectionFormat: brackets
192201
- name: forumId
193202
in: query
194203
description: Filter by forum id, exact match.

src/services/ChallengeService.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,13 @@ async function searchChallenges(currentUser, criteria) {
13431343
}
13441344
});
13451345

1346+
// handle projectIds (array of project IDs, applied as IN filter)
1347+
if (Array.isArray(criteria.projectIds) && criteria.projectIds.length > 0) {
1348+
prismaFilter.where.AND.push({
1349+
projectId: { in: criteria.projectIds },
1350+
});
1351+
}
1352+
13461353
// handle status
13471354
if (!_.isNil(criteria.status)) {
13481355
prismaFilter.where.AND.push({
@@ -1649,6 +1656,18 @@ async function searchChallenges(currentUser, criteria) {
16491656
currentUser,
16501657
);
16511658
}
1659+
// When filtering by multiple project IDs, treat as having project manager access
1660+
// (the caller is expected to pass only project IDs the user has access to)
1661+
if (
1662+
!hasProjectManagerAccessForSearch &&
1663+
currentUser &&
1664+
!_hasAdminRole &&
1665+
!_isMachineToken &&
1666+
Array.isArray(criteria.projectIds) &&
1667+
criteria.projectIds.length > 0
1668+
) {
1669+
hasProjectManagerAccessForSearch = true;
1670+
}
16521671

16531672
let groupsToFilter = [];
16541673
let accessibleGroups = [];
@@ -2071,6 +2090,7 @@ searchChallenges.schema = {
20712090
tags: Joi.array().items(Joi.string()),
20722091
includeAllTags: Joi.boolean().default(true),
20732092
projectId: Joi.number().integer().positive(),
2093+
projectIds: Joi.array().items(Joi.number().integer().positive()),
20742094
forumId: Joi.number().integer(),
20752095
legacyId: Joi.number().integer().positive(),
20762096
status: Joi.string()

0 commit comments

Comments
 (0)