Skip to content

Commit

Permalink
Add ACL and filter
Browse files Browse the repository at this point in the history
Signed-off-by: starfishfive <[email protected]>
  • Loading branch information
starfishfive committed May 17, 2024
1 parent 7d77241 commit 61bb89c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class ComponentQueryFilterBuilder {
this.filterCriteria = new ArrayList<>();
}

ComponentQueryFilterBuilder withFuzzyName(String name) {
params.put("name", name);
filterCriteria.add("(name.toLowerCase().matches(:name))");
return this;
}

ComponentQueryFilterBuilder withAuthor(string author) {
params.put("author", author);
filterCriteria.add("(author == :author)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ public PaginatedResult getComponents(final boolean includeMetrics) {
if (orderBy == null) {
query.setOrdering("name asc, version desc");
}

final var filterBuilder = new ProjectQueryFilterBuilder();

if (filter != null) {
query.setFilter("name.toLowerCase().matches(:name)");
final String filterString = ".*" + filter.toLowerCase() + ".*";
result = execute(query, filterString);
} else {
result = execute(query);
}
filterBuilder = filterBuilder.withFuzzyName(filterString);
}

final String queryFilter = filterBuilder.buildFilter();
final Map<String, Object> params = filterBuilder.getParams();

preprocessACLs(query, queryFilter, params, false);
result = execute(query, params);
if (includeMetrics) {
// Populate each Component object in the paginated result with transitive related
// data to minimize the number of round trips a client needs to make, process, and render.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public class ComponentResource extends AlpineResource {
@ApiResponse(code = 401, message = "Unauthorized"),
})
@PermissionRequired(Permissions.Constants.VIEW_PORTFOLIO)
public Response getComponents() {
public Response getComponents(
@ApiParam(value = "The optional author of the component to query on", required = false)
@QueryParam("author") String author) {
try (QueryManager qm = new QueryManager(getAlpineRequest())) {
final PaginatedResult result = qm.getComponents();
return Response.ok(result.getObjects()).header(TOTAL_COUNT_HEADER, result.getTotal()).build()
Expand Down

0 comments on commit 61bb89c

Please sign in to comment.