~sircmpwn/sr.ht-dev

meta.sr.ht: Show PGP key expiration on keys page v1 PROPOSED

Conrad Hoffmann: 1
 Show PGP key expiration on keys page

 2 files changed, 13 insertions(+), 1 deletions(-)
#881698 running alpine.yml
#881699 running archlinux.yml
#881700 running debian.yml
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/36783/mbox | git am -3
Learn more about email & git

[PATCH meta.sr.ht] Show PGP key expiration on keys page Export this patch

---
NOTE: to avoid some confusion, the contrib/key-expiration program should
have run successfully to the end at least once - otherwise keys that do
in fact expire might show as not expiring.

 metasrht/blueprints/keys.py  | 6 +++++-
 metasrht/templates/keys.html | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/metasrht/blueprints/keys.py b/metasrht/blueprints/keys.py
index e7d056c..2025f60 100644
--- a/metasrht/blueprints/keys.py
+++ b/metasrht/blueprints/keys.py
@@ -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.now())

@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.now(),
                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.now(),
                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.now(),
                tried_to_delete_key_in_use=True), 400
    resp = exec_gql("meta.sr.ht", """
    mutation DeletePGPKey($key: Int!) {
diff --git a/metasrht/templates/keys.html b/metasrht/templates/keys.html
index 75c9cb8..95adcd9 100644
--- a/metasrht/templates/keys.html
+++ b/metasrht/templates/keys.html
@@ -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()}}
-- 
2.38.1