-
-
Notifications
You must be signed in to change notification settings - Fork 35
added changes to fix affected project search in vulnerabilities page #1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ | |
| package org.dependencytrack.resources.v1; | ||
|
|
||
| import alpine.persistence.PaginatedResult; | ||
| import alpine.resources.AlpineRequest; | ||
| import alpine.server.auth.PermissionRequired; | ||
| import alpine.server.filters.ResourceAccessRequired; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
| import io.swagger.v3.oas.annotations.headers.Header; | ||
| import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
|
|
@@ -260,7 +262,22 @@ public Response getVulnerabilityByVulnId( | |
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Operation( | ||
| summary = "Returns a list of all projects affected by a specific vulnerability", | ||
| description = "<p>Requires permission <strong>VIEW_PORTFOLIO</strong></p>" | ||
| description = """ | ||
| <p>Requires permission <strong>VIEW_PORTFOLIO</strong></p>\ | ||
| <p>Optional query parameters <code>searchText</code> or <code>filter</code> narrow the list; \ | ||
| both are provided by the Alpine request filter and match the same value.</p>""", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an implementation detail that doesn't belong in public API documentation. |
||
| parameters = { | ||
| @Parameter( | ||
| name = "searchText", | ||
| in = ParameterIn.QUERY, | ||
| description = "Optional case-insensitive substring match on project name." | ||
| ), | ||
| @Parameter( | ||
| name = "filter", | ||
| in = ParameterIn.QUERY, | ||
| description = "Optional filter (Alpine); same effect as <code>searchText</code> for this endpoint." | ||
| ) | ||
| } | ||
| ) | ||
| @PaginatedApi | ||
| @ApiResponses(value = { | ||
|
|
@@ -278,8 +295,16 @@ public Response getAffectedProject(@PathParam("source") String source, | |
| @PathParam("vuln") String vuln, | ||
| @Parameter(description = "Optionally excludes inactive projects from being returned", required = false) | ||
| @QueryParam("excludeInactive") boolean excludeInactive) { | ||
| final List<AffectedProjectListRow> affectedProjectRows = withJdbiHandle(getAlpineRequest(), handle -> | ||
| handle.attach(VulnerabilityDao.class).getAffectedProjects(source, vuln, excludeInactive ? true : null)); | ||
| final AlpineRequest alpineRequest = getAlpineRequest(); | ||
| final String affectedProjectsFilter; | ||
| if (alpineRequest == null) { | ||
|
Comment on lines
+298
to
+300
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| affectedProjectsFilter = null; | ||
| } else { | ||
| final String filter = alpineRequest.getFilter(); | ||
| affectedProjectsFilter = (filter == null || filter.isBlank()) ? null : filter; | ||
| } | ||
| final List<AffectedProjectListRow> affectedProjectRows = withJdbiHandle(alpineRequest, handle -> | ||
| handle.attach(VulnerabilityDao.class).getAffectedProjects(source, vuln, excludeInactive ? true : null, affectedProjectsFilter)); | ||
|
|
||
| final long totalCount = affectedProjectRows.isEmpty() ? 0 : affectedProjectRows.getFirst().totalCount(); | ||
| final List<AffectedProject> affectedProjects = affectedProjectRows.stream() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's commit to only
searchTextto avoid confusion. Also, when we explicitly mention it, we should also note what it searches (i.e. project name, case-insensitive, "contains" semantics).