Skip to content

Commit

Permalink
fixup! Permissions as HTML page
Browse files Browse the repository at this point in the history
  • Loading branch information
mvalik committed Oct 11, 2023
1 parent 739b2d2 commit 488c00c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/test_api_v10.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,18 @@ def test_permissions_endpoint(client):
assert r.status_code == 200
assert r.json == config['PERMISSIONS'][0:1]

r = client.get('/api/v1.0/permissions?html=1')
assert r.status_code == 200
assert r.content_type == 'text/html'
assert f"<td>{config['PERMISSIONS'][0]['name']}</td>" in r.text
assert f"<td>{config['PERMISSIONS'][1]['name']}</td>" in r.text

r = client.get('/api/v1.0/permissions?testcase=greenwave-tests.test1&html=1')
assert r.status_code == 200
assert r.content_type == 'text/html'
assert f"<td>{config['PERMISSIONS'][0]['name']}</td>" not in r.text
assert f"<td>{config['PERMISSIONS'][1]['name']}</td>" in r.text


def test_config_endpoint_superusers(client):
config = {
Expand Down
23 changes: 16 additions & 7 deletions waiverdb/templates/permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,35 @@ <h1>
<img src="{{ url_for('favicon') }}" style="height: 64px" alt="Waiver DB" />
{{ self.title() }}
</h1>
<table class="table table-striped text-nowrap">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Maintainers</th>
<th>Testcases</th>
<th>User groups</th>
<th>Users/Groups</th>
</tr>
</thead>
<tbody>
{% for p in permissions %}
{% for p in permissions -%}
<tr>
<td>{{ p["name"] }}</td>
<td>{{ p["description"] }}</td>
<td>{{ p["maintainers"] | map("urlize") | join("<br />") | safe }}</td>
<td>{{ p["testcases"] | join("<br />") | safe }}</td>
<td>{{ p["groups"] | join("<br />") | safe }}</td>
<td>{{ p["maintainers"] | map("urlize") | safe | join("<br />") | safe }}</td>
<td>{{ p["testcases"] | map("replace('-', '&#8209;')") | join("<br />") | safe }}</td>
<td>
{% if p["groups"] | length > 0 -%}
<span class="font-weight-bold">Groups:</span><br />
{{ p["groups"] | map("replace('-', '&#8209;')") | join("<br />") | safe }}
{%- endif %}
{% if p["users"] | length > 0 -%}
<span class="font-weight-bold">Users:</span><br />
{{ p["users"] | map("replace('-', '&#8209;')") | join("<br />") | safe }}
{%- endif %}
</td>
</tr>
{% endfor %}
{%- endfor %}
</tbody>
</table>
</div>
Expand Down

0 comments on commit 488c00c

Please sign in to comment.