Implemented project filtering. - #6873
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 106 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
8ae483d to
f3ca0f8
Compare
| <#-- @ftlvariable name="hasCursor" type="boolean" --> | ||
| <#-- @ftlvariable name="filterHasChildren" type="boolean" --> | ||
| <#-- @ftlvariable name="apiProjectAclCondition" type="String" --> | ||
| <#assign childProjectAclCondition = apiProjectAclCondition?replace('"PROJECT"."ID"', '"CHILD_PROJECT"."ID"')> |
There was a problem hiding this comment.
Access checks on child projects are redundant. ACL is inherited, so having access to the parent implies access to the children:
| <#if filterHasChildren> | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM "PROJECT" AS "CHILD_PROJECT" | ||
| WHERE "CHILD_PROJECT"."PARENT_PROJECT_ID" = "PROJECT"."ID" | ||
| AND (${childProjectAclCondition})) |
There was a problem hiding this comment.
Same as in ProjectDao, access checks on child projects are redundant.
filterHasChildren is also a filter specific to a single query, but PaginationSupport is shared code used by multiple queries. Domain-specific filters don't belong here.
| , ( | ||
| SELECT JSONB_STRIP_NULLS(JSONB_BUILD_OBJECT( | ||
| 'supplier', "SUPPLIER"::JSONB, | ||
| 'authors', "AUTHORS"::JSONB, | ||
| 'tools', "TOOLS"::JSONB | ||
| )) | ||
| FROM "PROJECT_METADATA" | ||
| WHERE "PROJECT_METADATA"."PROJECT_ID" = "PROJECT"."ID" | ||
| ) AS "metadataJson" |
There was a problem hiding this comment.
Selected but never used and not returned by the API.
| , "PROJECT"."CPE" | ||
| , "PROJECT"."DESCRIPTION" | ||
| , "PROJECT"."DIRECT_DEPENDENCIES" | ||
| , "PROJECT"."EXTERNAL_REFERENCES" |
There was a problem hiding this comment.
Selected but never used and not returned by the API.
| When portfolio access control is enabled and the caller does not have | ||
| access to the parent project, an empty result set is returned. | ||
|
|
||
| Used for tree-view navigation (lazy loading of one hierarchy level). |
There was a problem hiding this comment.
Nit: the API has no concept of tree-view navigation.
| is_active: | ||
| type: boolean |
| , ( | ||
| SELECT ARRAY_AGG("TEAM"."NAME") | ||
| FROM "TEAM" | ||
| INNER JOIN "PROJECT_ACCESS_TEAMS" | ||
| ON "PROJECT_ACCESS_TEAMS"."TEAM_ID" = "TEAM"."ID" | ||
| WHERE "PROJECT_ACCESS_TEAMS"."PROJECT_ID" = "PROJECT"."ID" | ||
| ) AS "teamNames" |
There was a problem hiding this comment.
This query is for the API v1 endpoint, but that one doesn't return teamNames.
| AND "PROJECT"."ID" > :lastId | ||
| </#if> | ||
| <#if sortByColumn?has_content> | ||
| ORDER BY "PROJECT"."${sortByColumn}" ${sortDirection!"ASC"}, "PROJECT"."ID" ASC |
There was a problem hiding this comment.
This breaks pagination when sortByColumn=LAST_RISKSCORE, because it doesn't work for collection projects. Earlier in the query there is a CASE statement that computes lastInheritedRiskScore in a way that takes collections into consideration. We thus need to sort by lastInheritedRiskScore.
| totalCount = getBoundedTotalCountWithProjectAcl( | ||
| "FROM \"PROJECT\" WHERE " + String.join(" AND ", whereConditions), | ||
| queryParams, | ||
| 500, | ||
| "\"PROJECT\".\"ID\"", | ||
| filterHasChildren); | ||
| effectiveSortBy = query.sortBy() != null | ||
| ? query.sortBy() | ||
| : ListAllProjectsQuery.SortBy.NAME; | ||
| effectiveSortDirection = query.sortDirection() != null | ||
| ? query.sortDirection() | ||
| : SortDirection.ASC; | ||
| } | ||
|
|
||
| final List<ListProjectsRow> rows = listAllProjects( | ||
| whereConditions, | ||
| queryParams, | ||
| query.limit() + 1, | ||
| query.includeMetrics(), | ||
| decodedPageToken != null | ||
| ? decodedPageToken.lastId() | ||
| : null, | ||
| effectiveSortBy, | ||
| effectiveSortDirection, | ||
| decodedPageToken != null, | ||
| filterHasChildren, | ||
| COLLECTION_METRICS_SUBQUERY, | ||
| LEAF_METRICS_SUBQUERY); |
There was a problem hiding this comment.
Use withJitDisabled like the other project listing queries:
17feb11 to
1db4366
Compare
Signed-off-by: ElenaStroebele <elena.stroebele@rohde-schwarz.com>
6b1404d to
16a1784
Compare
Signed-off-by: ElenaStroebele <elena.stroebele@rohde-schwarz.com>
16a1784 to
1711200
Compare
Description
Implemented project filtering for GET /api/v2/projects.
Adds a paginated list endpoint with query-based filters, sorting, optional metrics expansion, and ACL-aware results. Text filters are case-insensitive;
Frontend implementation: DependencyTrack/frontend#1721
Addressed Issue
#926
#2778
(#144)
Additional Details
Filter specification
Checklist
docs/adr/