hide fields if authorization is enabled, but no auth supplied

This commit is contained in:
Evgenii Alekseev 2021-09-02 02:49:25 +03:00
parent 75269e8177
commit cb5756ea76
3 changed files with 28 additions and 12 deletions

View File

@ -8,6 +8,9 @@ database = /var/lib/pacman
repositories = core extra community multilib repositories = core extra community multilib
root = / root = /
[auth]
enabled = no
[build] [build]
archbuild_flags = archbuild_flags =
build_command = extra-x86_64-build build_command = extra-x86_64-build
@ -43,6 +46,5 @@ command = rsync --archive --compress --partial --delete
chunk_size = 8388608 chunk_size = 8388608
[web] [web]
auth = no
host = 127.0.0.1 host = 127.0.0.1
templates = /usr/share/ahriman templates = /usr/share/ahriman

View File

@ -12,9 +12,11 @@
<body> <body>
<div class="root"> <div class="root">
<h1>ahriman <h1>ahriman
<img src="https://img.shields.io/badge/version-{{ version }}-informational" alt="{{ version }}"> {% if authorized %}
<img src="https://img.shields.io/badge/architecture-{{ architecture }}-informational" alt="{{ architecture }}"> <img src="https://img.shields.io/badge/version-{{ version }}-informational" alt="{{ version }}">
<img src="https://img.shields.io/badge/service%20status-{{ service.status }}-{{ service.status_color }}" alt="{{ service.status }}" title="{{ service.timestamp }}"> <img src="https://img.shields.io/badge/architecture-{{ architecture }}-informational" alt="{{ architecture }}">
<img src="https://img.shields.io/badge/service%20status-{{ service.status }}-{{ service.status_color }}" alt="{{ service.status }}" title="{{ service.timestamp }}">
{% endif %}
</h1> </h1>
{% include "login-form.jinja2" %} {% include "login-form.jinja2" %}
@ -31,15 +33,21 @@
<th>status</th> <th>status</th>
</tr> </tr>
{% for package in packages %} {% if authorized %}
{% for package in packages %}
<tr class="package">
<td class="include-search"><a href="{{ package.web_url }}" title="{{ package.base }}">{{ package.base }}</a></td>
<td class="include-search">{{ package.packages|join("<br>"|safe) }}</td>
<td>{{ package.version }}</td>
<td>{{ package.timestamp }}</td>
<td class="status package-{{ package.status }}">{{ package.status }}</td>
</tr>
{% endfor %}
{% else %}
<tr class="package"> <tr class="package">
<td class="include-search"><a href="{{ package.web_url }}" title="{{ package.base }}">{{ package.base }}</a></td> <td colspan="100%">In order to see statuses you must login first</td>
<td class="include-search">{{ package.packages|join("<br>"|safe) }}</td>
<td>{{ package.version }}</td>
<td>{{ package.timestamp }}</td>
<td class="status package-{{ package.status }}">{{ package.status }}</td>
</tr> </tr>
{% endfor %} {% endif %}
</table> </table>
</section> </section>

View File

@ -34,6 +34,7 @@ class IndexView(BaseView):
It uses jinja2 templates for report generation, the following variables are allowed: It uses jinja2 templates for report generation, the following variables are allowed:
architecture - repository architecture, string, required architecture - repository architecture, string, required
authorized - alias for `not auth_enabled or auth_username is not None`
auth_enabled - whether authorization is enabled by configuration or not, boolean, required auth_enabled - whether authorization is enabled by configuration or not, boolean, required
auth_username - authorized user id if any, string. None means not authorized auth_username - authorized user id if any, string. None means not authorized
packages - sorted list of packages properties, required packages - sorted list of packages properties, required
@ -80,10 +81,15 @@ class IndexView(BaseView):
"timestamp": pretty_datetime(self.service.status.timestamp) "timestamp": pretty_datetime(self.service.status.timestamp)
} }
# auth block
auth_username = await authorized_userid(self.request)
authorized = not self.validator.enabled or auth_username is not None
return { return {
"architecture": self.service.architecture, "architecture": self.service.architecture,
"authorized": authorized,
"auth_enabled": self.validator.enabled, "auth_enabled": self.validator.enabled,
"auth_username": await authorized_userid(self.request), "auth_username": auth_username,
"packages": packages, "packages": packages,
"repository": self.service.repository.name, "repository": self.service.repository.name,
"service": service, "service": service,