Skip to content
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

Make zubbi-web work with path-like role names #109

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion zubbi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import collections
import logging
import ssl
from urllib.parse import quote_plus

import markupsafe
from elasticsearch.exceptions import ElasticsearchException
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion zubbi/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h5 class="card-title">
</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ match.repo }}</h6>
<p class="card-text">{% if match.description_rendered %}{{ match.description_rendered.split('\n')|first|striptags }}{% endif %}</p>
<a href="{{ url_for('zubbi.details', repo=match.repo, block_type=match|block_type, name=match.name) }}" class="btn btn-primary"><i class="fas fa-info-circle"></i> Show details</a>
<a href="{{ url_for('zubbi.details', repo=match.repo, block_type=match|block_type, name=match.name|quote_plus) }}" class="btn btn-primary"><i class="fas fa-info-circle"></i> Show details</a>
</div>
</div>
{%- endfor %}
Expand Down
4 changes: 3 additions & 1 deletion zubbi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import hmac
import json
import math
import urllib.parse

from elasticsearch_dsl import Q
from flask import (
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
)
Expand Down
Loading