Show PGP key expiration on keys page

This commit is contained in:
Conrad Hoffmann 2023-01-26 11:48:33 +01:00 committed by Drew DeVault
parent bfa55bb19c
commit 226c332127
2 changed files with 13 additions and 1 deletions

View File

@ -1,3 +1,4 @@
from datetime import datetime
from flask import Blueprint, render_template, request, redirect
from srht.graphql import exec_gql
from srht.oauth import current_user, loginrequired
@ -8,7 +9,7 @@ keys = Blueprint('keys', __name__)
@keys.route("/keys")
@loginrequired
def keys_GET():
return render_template("keys.html")
return render_template("keys.html", now=datetime.utcnow())
@keys.route("/keys/ssh-keys", methods=["POST"])
@loginrequired
@ -26,6 +27,7 @@ def ssh_keys_POST():
if not err.field or err.field == "key":
err.field = "ssh-key"
return render_template("keys.html",
now=datetime.utcnow(),
ssh_key=valid.source.get("ssh-key", ""),
**valid.kwargs), 400
return redirect("/keys")
@ -56,6 +58,7 @@ def pgp_keys_POST():
if not err.field or err.field == "key":
err.field = "pgp-key"
return render_template("keys.html",
now=datetime.utcnow(),
pgp_key=valid.source.get("pgp-key", ""),
**valid.kwargs), 400
return redirect("/keys")
@ -66,6 +69,7 @@ def pgp_keys_delete(key_id):
# TODO: Move this logic into GQL
if key_id == current_user.pgp_key_id:
return render_template("keys.html",
now=datetime.utcnow(),
tried_to_delete_key_in_use=True), 400
resp = exec_gql("meta.sr.ht", """
mutation DeletePGPKey($key: Int!) {

View File

@ -75,6 +75,7 @@
<tr>
<th>Fingerprint</th>
<th>Authorized</th>
<th>Expiration</th>
<th></th>
</tr>
</thead>
@ -83,6 +84,13 @@
<tr>
<td>{{key.fingerprint_hex}}</td>
<td>{{key.created|date}}</td>
{% if not key.expiration %}
<td>Does not expire</td>
{% elif key.expiration > now %}
<td>{{key.expiration|date}}</td>
{% else %}
<td><span class="text-danger">Expired {{key.expiration|date}}</span></td>
{% endif %}
<td style="width: 6rem">
<form method="POST" action="/keys/delete-pgp/{{key.id}}">
{{csrf_token()}}