1
0

index.twig 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. 'self_tombstone': 'You cannot tombstone yourself — ask another admin.',
  6. 'bad_action': 'Unrecognised action.',
  7. 'not_found': 'User not found.',
  8. 'db_error': 'Could not save. Try again.',
  9. } %}
  10. {% set flashMessages = {
  11. 'promoted': 'Admin granted.',
  12. 'demoted': 'Admin revoked.',
  13. 'tombstoned': 'User marked as former — name and email are now hidden in the UI. Audit trail keeps the original values.',
  14. 'restored': 'User restored.',
  15. 'noop': 'Nothing changed.',
  16. } %}
  17. {% block content %}
  18. <section class="space-y-6">
  19. <div>
  20. <h1 class="text-2xl font-semibold tracking-tight">Users</h1>
  21. <p class="text-slate-600 text-sm mt-1 max-w-prose dark:text-slate-400">
  22. Everyone who has ever signed in. Toggle admin status here; you
  23. cannot demote yourself or the last admin. Users are never deleted
  24. — to honour a privacy / right-to-be-forgotten request, mark a
  25. user as <em>former</em>: the live UI hides their name and email
  26. (the audit log keeps the original values verbatim).
  27. </p>
  28. </div>
  29. {% if error and errorMessages[error] is defined %}
  30. <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">
  31. {{ errorMessages[error] }}
  32. </div>
  33. {% endif %}
  34. {% if flash and flashMessages[flash] is defined %}
  35. <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">
  36. {{ flashMessages[flash] }}
  37. </div>
  38. {% endif %}
  39. <div class="rounded-lg border bg-white overflow-hidden dark:bg-slate-800 dark:border-slate-700">
  40. {% if users is empty %}
  41. <div class="p-8 text-center text-slate-500 text-sm dark:text-slate-400">No users yet.</div>
  42. {% else %}
  43. <table class="min-w-full text-sm">
  44. <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider dark:bg-slate-700 dark:text-slate-300">
  45. <tr>
  46. <th class="text-left px-4 py-2 font-semibold">Email</th>
  47. <th class="text-left px-4 py-2 font-semibold">Display name</th>
  48. <th class="text-left px-4 py-2 font-semibold">Last login (UTC)</th>
  49. <th class="text-left px-4 py-2 font-semibold">Admin</th>
  50. <th class="text-right px-4 py-2 font-semibold">&nbsp;</th>
  51. </tr>
  52. </thead>
  53. <tbody class="divide-y divide-slate-100 dark:divide-slate-700">
  54. {% for u in users %}
  55. {% set isSelf = u.id == currentUser.id %}
  56. {% set isTombstoned = u.isTombstoned %}
  57. {% if isTombstoned %}
  58. <tr class="bg-slate-50 dark:bg-slate-900/40">
  59. <td class="px-4 py-2 font-mono text-xs italic text-slate-500 dark:text-slate-400">
  60. {{ u.publicEmail }}
  61. <span class="ml-1 inline-block px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider bg-amber-100 text-amber-800 rounded dark:bg-amber-900 dark:text-amber-200">former</span>
  62. </td>
  63. <td class="px-4 py-2 italic text-slate-500 dark:text-slate-400">{{ u.publicDisplayName }}</td>
  64. <td class="px-4 py-2 text-slate-500 font-mono text-xs dark:text-slate-400">
  65. {% if u.lastLoginAt is not null %}{{ u.lastLoginAt }}{% else %}<span class="text-slate-400 dark:text-slate-500">—</span>{% endif %}
  66. </td>
  67. <td class="px-4 py-2 text-slate-400 dark:text-slate-500">—</td>
  68. <td class="px-4 py-2 text-right">
  69. <form method="post" action="/users/{{ u.id }}/tombstone" hx-boost="true" hx-target="body">
  70. <input type="hidden" name="_csrf" value="{{ csrfToken }}">
  71. <input type="hidden" name="action" value="restore">
  72. <button type="submit"
  73. 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">
  74. Restore
  75. </button>
  76. </form>
  77. </td>
  78. </tr>
  79. {% else %}
  80. <tr>
  81. <form method="post" action="/users/{{ u.id }}" hx-boost="true" hx-target="body" class="contents">
  82. <input type="hidden" name="_csrf" value="{{ csrfToken }}">
  83. <td class="px-4 py-2 font-mono text-xs">
  84. {{ u.email }}
  85. {% if isSelf %}
  86. <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>
  87. {% endif %}
  88. </td>
  89. <td class="px-4 py-2">{{ u.displayName }}</td>
  90. <td class="px-4 py-2 text-slate-500 font-mono text-xs dark:text-slate-400">
  91. {% if u.lastLoginAt is not null %}{{ u.lastLoginAt }}{% else %}<span class="text-slate-400 dark:text-slate-500">—</span>{% endif %}
  92. </td>
  93. <td class="px-4 py-2">
  94. <label class="inline-flex items-center gap-2">
  95. <input name="is_admin" type="checkbox" value="1"
  96. {{ u.isAdmin ? 'checked' : '' }}
  97. {% if isSelf and u.isAdmin %}disabled title="You cannot demote yourself"{% endif %}
  98. class="rounded border-slate-300 dark:border-slate-600">
  99. <span class="text-slate-600 dark:text-slate-400">admin</span>
  100. </label>
  101. </td>
  102. <td class="px-4 py-2 text-right">
  103. <button type="submit"
  104. 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">
  105. Save
  106. </button>
  107. </td>
  108. </form>
  109. </tr>
  110. {% if not isSelf %}
  111. <tr>
  112. <td colspan="5" class="px-4 pb-2 pt-0 text-right">
  113. <form method="post" action="/users/{{ u.id }}/tombstone" hx-boost="true" hx-target="body">
  114. <input type="hidden" name="_csrf" value="{{ csrfToken }}">
  115. <input type="hidden" name="action" value="tombstone">
  116. <button type="submit"
  117. class="text-xs text-amber-700 hover:underline dark:text-amber-300">
  118. Mark as former user
  119. </button>
  120. </form>
  121. </td>
  122. </tr>
  123. {% endif %}
  124. {% endif %}
  125. {% endfor %}
  126. </tbody>
  127. </table>
  128. {% endif %}
  129. </div>
  130. </section>
  131. {% endblock %}