nixie-ci/nixie-server/templates/settings/api_keys.html.tera
Marcel Müller 06b0973d45 Separate revoked API keys from still active ones
Signed-off-by: Marcel Müller <neikos@neikos.email>
2026-01-31 10:07:55 +01:00

98 lines
5.4 KiB
Text

{% extends "base.html.tera" %}
{% import "inputs.html.tera" as inputs %}
{% block title %}
API Keys - {{ current_user.username }}
{% endblock title %}
{% block content %}
<div class="flex flex-col md:flex-row grow">
<div class="basis-1/4 p-4 m-4 space-y-4">
{% include "settings/sidebar.html.tera" %}
</div>
<div class="basis-3/4 p-4">
<h1 class="font-bold text-3xl">API Keys</h1>
<form action="/settings/new_api_key" method="POST" class="space-y-4">
{{ inputs::text_input(label="Name", name="name", id="name", type="text") }}
{{ inputs::text_input(label="Expiration Date", name="expiration_date", id="expiration_date", type="date", value=one_year_date)}}
<div class="flex flex-col">
<button type="submit" class="bg-blue-500 p-2 rounded-lg text-white">
Create API Key
</button>
</div>
</form>
<hr class="my-4 w-1/2 border-0 bg-zinc-300 h-0.5 mx-auto">
<h2 class="font-bold text-2xl my-4">Current API Tokens</h2>
<table class="border-collapse border-spacing-2 border border-zinc-400 w-full">
<thead class="bg-orange-50">
<tr>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Name</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Active</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Expiration Date</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Actions</th>
</tr>
</thead>
<tbody>
{% for api_key in api_keys | filter(attribute="revoked", value=false) %}
<tr>
<td class="border border-zinc-200 p-2">{{ api_key.name}}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="align-middle">No Longer Active</span><span class="inline-block align-middle size-6 ml-2 bg-zinc-500 rounded-lg"></span>
{% else %}
<span class="align-middle">Currently Active</span><span class="inline-block align-middle size-6 ml-2 bg-green-500 rounded-lg"></span>
{% endif %}
</td>
<td class="border border-zinc-200 p-2 text-center">{{ api_key.expiration_date }}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="text-zinc-700">A revoked API Key cannot be revived</span>
{% else %}
<form action="/settings/revoke_api_key" method="POST">
<input type="hidden" name="api_key_id" value="{{ api_key.id }}">
<button type="submit" class="px-4 py-2 inline-block border border-red-700 bg-red-600 text-white rounded pointer-link">
Revoke API Key
</button>
</form>
{% endif %}
</td>
</tr>
{% else %}
<tr>
<td colspan="4" class="border border-zinc-200 p-6 text-center">No active API Keys</td>
</tr>
{% endfor %}
{% for api_key in api_keys | filter(attribute="revoked", value=true) %}
<tr class="{% if loop.first %}border-t-zinc-400 border-t-4{% endif %}">
<td class="border border-zinc-200 p-2">{{ api_key.name}}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="align-middle">No Longer Active</span><span class="inline-block align-middle size-6 ml-2 bg-zinc-500 rounded-lg"></span>
{% else %}
<span class="align-middle">Currently Active</span><span class="inline-block align-middle size-6 ml-2 bg-green-500 rounded-lg"></span>
{% endif %}
</td>
<td class="border border-zinc-200 p-2 text-center">{{ api_key.expiration_date }}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="text-zinc-700">A revoked API Key cannot be revived</span>
{% else %}
<form action="/settings/revoke_api_key" method="POST">
<input type="hidden" name="api_key_id" value="{{ api_key.id }}">
<button type="submit" class="px-4 py-2 inline-block border border-red-700 bg-red-600 text-white rounded pointer-link">
Revoke API Key
</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
<tbody>
</table>
</div>
</div>
{% endblock content %}