From 4d1dfb83ed4784bf1205869b0af47dc2e223b993 Mon Sep 17 00:00:00 2001 From: Felix Edel Date: Thu, 8 Feb 2024 15:25:46 +0100 Subject: [PATCH 1/2] Make zubbi-web work with path-like role names Zubbi-scraper is now able to parse roles that are defined in a nested directory structure. Those roles have a path-like name, e.g. foo/bar. In order to show those roles properly in zubbi-web, we have to urlencode the role names in the URL for the details view and also escape the special characters ("/") in the Elasticsearch query string. The latter one was already done in other places, so this just aligns the details query with the "normal" search query. --- zubbi/models.py | 7 ++++++- zubbi/templates/search.html | 2 +- zubbi/views.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/zubbi/models.py b/zubbi/models.py index 9812eeb..7293a0a 100644 --- a/zubbi/models.py +++ b/zubbi/models.py @@ -15,6 +15,7 @@ import collections import logging import ssl +from urllib.parse import quote_plus import markupsafe from elasticsearch.exceptions import ElasticsearchException @@ -270,8 +271,9 @@ def search_query(self, query, fields_set, exact=False, extra_filter=None): def detail_query(self, block_name, repo, extra_filter=None): extra_filter = extra_filter or [] + query_string = block_name.translate(TRANSLATION_TABLE) detail_query = [ - Q("query_string", query=block_name, fields=["job_name", "role_name"]), + Q("query_string", query=query_string, fields=["job_name", "role_name"]), Q("match", repo=repo), ] return self.query("bool", filter=extra_filter, must=detail_query) @@ -336,6 +338,9 @@ def init_elasticsearch(app): app.add_template_test(role_type) app.add_template_test(job_type) app.add_template_filter(block_type) + # Jinja2 doesn't provide it's own filter equivalent for + # urllib.parse.quote_plus, so we add it by ourselves. + app.add_template_filter(quote_plus) def init_elasticsearch_con( diff --git a/zubbi/templates/search.html b/zubbi/templates/search.html index 46cbcb8..078c109 100644 --- a/zubbi/templates/search.html +++ b/zubbi/templates/search.html @@ -93,7 +93,7 @@
{{ match.repo }}

{% if match.description_rendered %}{{ match.description_rendered.split('\n')|first|striptags }}{% endif %}

- Show details + Show details {%- endfor %} diff --git a/zubbi/views.py b/zubbi/views.py index dfb0880..3ea14bd 100644 --- a/zubbi/views.py +++ b/zubbi/views.py @@ -17,6 +17,7 @@ import hmac import json import math +import urllib.parse from elasticsearch_dsl import Q from flask import ( @@ -159,7 +160,7 @@ def get(self): "zubbi.details", repo=block.repo, block_type=block_type(block), - name=block.name, + name=urllib.parse.quote_plus(block.name), ), code=303, ) @@ -199,6 +200,7 @@ def get(self, repo, block_type, name): abort(400, "Unknown block type '{}'".format(block_type)) extra_filter = Q("term", private=False) + name = urllib.parse.unquote_plus(name) search = BlockSearch(block_class=BlockClass).detail_query( name, repo, extra_filter ) From 6b55dc05e116121f04096d6de5ec44c6d133bf95 Mon Sep 17 00:00:00 2001 From: Felix Edel Date: Thu, 8 Feb 2024 16:11:41 +0100 Subject: [PATCH 2/2] Prepare changelog for release 2.7.0 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6f835..f700e89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2.7.0 + +### New Features +- Zubbi now searches the `roles` directory recursively for roles defined in a + subdirectory. + ## 2.6.2 ### Fixes