Skip to content

Commit

Permalink
Improve permissions HTML table
Browse files Browse the repository at this point in the history
Sanitizes all characters for HTML.

Includes description.

Splits users and groups to separate columns.
  • Loading branch information
hluk committed Nov 20, 2023
1 parent 730ee76 commit 84d6948
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
8 changes: 7 additions & 1 deletion tests/test_api_v10.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def test_permissions_endpoint(client):
"maintainers": ["[email protected]"],
"_testcase_regex_pattern": "^kernel-qe",
"groups": ["devel", "qa"],
"users": ["alice@example.com"],
"users": ["alice", "bob"],
},
{
"name": "Greenwave Tests",
Expand Down Expand Up @@ -927,6 +927,12 @@ def test_permissions_endpoint(client):
assert f"<td>{config['PERMISSIONS'][0]['name']}</td>" not in r.text
assert f"<td>{config['PERMISSIONS'][1]['name']}</td>" in r.text

r = client.get('/api/v1.0/permissions?testcase=kernel-qe.test1&html=1')
assert r.status_code == 200
assert r.content_type.startswith('text/html')
assert "<ul><li>alice</li><li>bob</li></ul>" in r.text
assert "<ul><li>devel</li><li>qa</li></ul>" in r.text


def test_config_endpoint_superusers(client):
config = {
Expand Down
35 changes: 19 additions & 16 deletions waiverdb/templates/permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,31 @@
<th>Name</th>
<th>Maintainers</th>
<th>Testcases</th>
<th>Users/Groups</th>
<th>Groups</th>
<th>Users</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for p in permissions -%}
<tr>
<td>{{ p["name"] }}</td>
<td>{{ p["maintainers"] | map("urlize") | join(" ") | safe }}</td>
<td>{{ p["testcases"] | join("<br />") | replace('-', '&#8209;') | safe }}</td>
<td>
{% if p["groups"] | length > 0 -%}
<span class="font-weight-bold">Groups:</span><br />
{{ p["groups"] | join("<br />") | replace('-', '&#8209;') | safe }}
{% if p["users"] | length > 0 -%}
<br />
{%- endif %}
{%- endif %}
{% if p["users"] | length > 0 -%}
<span class="font-weight-bold">Users:</span><br />
{{ p["users"] | join("<br />") | replace('-', '&#8209;') | safe }}
{%- endif %}
</td>
<td><ul>
{%- for maintainer in p["maintainers"] %}<li>{{ maintainer | urlize }}</li>{% endfor -%}
</ul></td>
<td><ul>
{%- if p["_testcase_regex_pattern"] -%}
<li>{{ p["_testcase_regex_pattern"] }}</li>
{%- endif -%}
{%- for testcase in p["testcases"] %}<li>{{ testcase }}</li>{% endfor -%}
</ul></td>
<td><ul>
{%- for group in p["groups"] %}<li>{{ group }}</li>{% endfor -%}
</ul></td>
<td><ul>
{%- for user in p["users"] %}<li>{{ user }}</li>{% endfor -%}
</ul></td>
<td>{{ p["description"] }}</td>
</tr>
{%- endfor %}
</tbody>
Expand Down

0 comments on commit 84d6948

Please sign in to comment.