index.twig 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {% extends "layout.twig" %}
  2. {% set errorMessages = {
  3. 'self_demote': 'You cannot demote yourself — ask another admin.',
  4. 'last_admin': 'Cannot demote the last remaining admin.',
  5. 'not_found': 'User not found.',
  6. 'db_error': 'Could not save. Try again.',
  7. } %}
  8. {% set flashMessages = {
  9. 'promoted': 'Admin granted.',
  10. 'demoted': 'Admin revoked.',
  11. 'noop': 'Nothing changed.',
  12. } %}
  13. {% block content %}
  14. <section class="space-y-6">
  15. <div>
  16. <h1 class="text-2xl font-semibold tracking-tight">Users</h1>
  17. <p class="text-slate-600 text-sm mt-1 max-w-prose dark:text-slate-400">
  18. Everyone who has ever signed in. Toggle admin status here; you
  19. cannot demote yourself or the last admin. Users are never deleted
  20. — inactive accounts simply stop signing in.
  21. </p>
  22. </div>
  23. {% if error and errorMessages[error] is defined %}
  24. <div class="rounded-md border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800 dark:bg-red-900 dark:border-red-800 dark:text-red-200">
  25. {{ errorMessages[error] }}
  26. </div>
  27. {% endif %}
  28. {% if flash and flashMessages[flash] is defined %}
  29. <div class="rounded-md border border-green-200 bg-green-50 px-4 py-3 text-sm text-green-800 dark:bg-green-900 dark:border-green-800 dark:text-green-200">
  30. {{ flashMessages[flash] }}
  31. </div>
  32. {% endif %}
  33. <div class="rounded-lg border bg-white overflow-hidden dark:bg-slate-800 dark:border-slate-700">
  34. {% if users is empty %}
  35. <div class="p-8 text-center text-slate-500 text-sm dark:text-slate-400">No users yet.</div>
  36. {% else %}
  37. <table class="min-w-full text-sm">
  38. <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider dark:bg-slate-700 dark:text-slate-300">
  39. <tr>
  40. <th class="text-left px-4 py-2 font-semibold">Email</th>
  41. <th class="text-left px-4 py-2 font-semibold">Display name</th>
  42. <th class="text-left px-4 py-2 font-semibold">Last login (UTC)</th>
  43. <th class="text-left px-4 py-2 font-semibold">Admin</th>
  44. <th class="text-right px-4 py-2 font-semibold">&nbsp;</th>
  45. </tr>
  46. </thead>
  47. <tbody class="divide-y divide-slate-100 dark:divide-slate-700">
  48. {% for u in users %}
  49. {% set isSelf = u.id == currentUser.id %}
  50. <tr>
  51. <form method="post" action="/users/{{ u.id }}" hx-boost="true" hx-target="body" class="contents">
  52. <input type="hidden" name="_csrf" value="{{ csrfToken }}">
  53. <td class="px-4 py-2 font-mono text-xs">
  54. {{ u.email }}
  55. {% if isSelf %}
  56. <span class="ml-1 inline-block px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider bg-slate-100 text-slate-700 rounded dark:bg-slate-700 dark:text-slate-200">you</span>
  57. {% endif %}
  58. </td>
  59. <td class="px-4 py-2">{{ u.displayName }}</td>
  60. <td class="px-4 py-2 text-slate-500 font-mono text-xs dark:text-slate-400">
  61. {% if u.lastLoginAt is not null %}{{ u.lastLoginAt }}{% else %}<span class="text-slate-400 dark:text-slate-500">—</span>{% endif %}
  62. </td>
  63. <td class="px-4 py-2">
  64. <label class="inline-flex items-center gap-2">
  65. <input name="is_admin" type="checkbox" value="1"
  66. {{ u.isAdmin ? 'checked' : '' }}
  67. {% if isSelf and u.isAdmin %}disabled title="You cannot demote yourself"{% endif %}
  68. class="rounded border-slate-300 dark:border-slate-600">
  69. <span class="text-slate-600 dark:text-slate-400">admin</span>
  70. </label>
  71. </td>
  72. <td class="px-4 py-2 text-right">
  73. <button type="submit"
  74. class="rounded-md border border-slate-300 bg-white text-slate-700 px-3 py-1 text-sm hover:bg-slate-100 dark:bg-slate-800 dark:border-slate-600 dark:text-slate-200 dark:hover:bg-slate-700">
  75. Save
  76. </button>
  77. </td>
  78. </form>
  79. </tr>
  80. {% endfor %}
  81. </tbody>
  82. </table>
  83. {% endif %}
  84. </div>
  85. </section>
  86. {% endblock %}