edit.twig 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {% extends 'layout.twig' %}
  2. {% block title %}{{ consumer.name }} — Consumer — IRDB{% endblock %}
  3. {% block content %}
  4. <div class="mx-auto max-w-3xl">
  5. <a href="/app/consumers" class="text-sm text-slate-500 hover:underline dark:text-slate-400">← Back to consumers</a>
  6. <h1 class="mt-3 text-2xl font-semibold tracking-tight font-mono">{{ consumer.name }}</h1>
  7. <form method="post" action="/app/consumers/{{ consumer.id }}" class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900">
  8. <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
  9. <div class="grid grid-cols-1 gap-3 md:grid-cols-2 text-sm">
  10. <div>
  11. <label for="c-name" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Name</label>
  12. <input type="text" id="c-name" name="name" value="{{ consumer.name }}" {% if not can_write %}readonly{% endif %}
  13. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono dark:border-slate-700 dark:bg-slate-950">
  14. </div>
  15. <div>
  16. <label for="c-policy" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Policy</label>
  17. <select id="c-policy" name="policy_id" {% if not can_write %}disabled{% endif %}
  18. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  19. {% for p in policies %}
  20. <option value="{{ p.id }}" {% if consumer.policy_id == p.id %}selected{% endif %}>{{ p.name }}</option>
  21. {% endfor %}
  22. </select>
  23. </div>
  24. <div class="md:col-span-2">
  25. <label for="c-desc" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Description</label>
  26. <input type="text" id="c-desc" name="description" value="{{ consumer.description|default('') }}" {% if not can_write %}readonly{% endif %}
  27. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  28. </div>
  29. <div class="md:col-span-2">
  30. <label class="flex items-center gap-2 text-xs text-slate-600 dark:text-slate-400">
  31. <input type="checkbox" name="is_active" value="1" {% if consumer.is_active %}checked{% endif %} {% if not can_write %}disabled{% endif %}>
  32. active
  33. </label>
  34. </div>
  35. <div class="md:col-span-2">
  36. {# Hidden 0 sent first so an unchecked box still posts a value; PHP's parser keeps the last occurrence. #}
  37. <input type="hidden" name="audit_enabled" value="0">
  38. <label class="flex items-start gap-2 text-xs text-slate-600 dark:text-slate-400">
  39. <input type="checkbox" name="audit_enabled" value="1" class="mt-0.5"
  40. {% if consumer.audit_enabled %}checked{% endif %} {% if not can_write %}disabled{% endif %}>
  41. <span>
  42. <span class="font-medium text-slate-700 dark:text-slate-200">Audit log: write a <code>blocklist.requested</code> entry per pull</span>
  43. <span class="block text-[0.7rem] text-slate-500 dark:text-slate-400">Off silences this consumer even when the global toggle is on (Settings → Audit toggles).</span>
  44. </span>
  45. </label>
  46. </div>
  47. </div>
  48. {% if can_write %}
  49. <div class="mt-4 flex justify-end">
  50. <button type="submit" class="rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-500">Save</button>
  51. </div>
  52. {% endif %}
  53. </form>
  54. <section class="mt-8 overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
  55. <header class="flex items-center justify-between gap-3 border-b border-slate-200 px-5 py-3 dark:border-slate-800">
  56. <div>
  57. <h2 class="text-sm font-semibold tracking-tight">Last activity</h2>
  58. <p class="text-xs text-slate-500 dark:text-slate-400">10 most recent audit entries for this consumer.</p>
  59. </div>
  60. <a href="/app/audit?entity_type=consumer&amp;entity_id={{ consumer.id }}" class="whitespace-nowrap text-xs font-medium text-indigo-600 hover:underline dark:text-indigo-400">View all in audit log →</a>
  61. </header>
  62. {% if audit_items|default([])|length > 0 %}
  63. <div x-data="{ open: null }">
  64. <table class="w-full text-sm">
  65. <thead class="border-b border-slate-200 bg-slate-50 text-left text-xs uppercase tracking-wider text-slate-500 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-400">
  66. <tr>
  67. <th class="px-5 py-2 font-medium">When</th>
  68. <th class="px-5 py-2 font-medium">Actor</th>
  69. <th class="px-5 py-2 font-medium">Action</th>
  70. <th class="px-5 py-2 text-right font-medium">Payload</th>
  71. </tr>
  72. </thead>
  73. <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
  74. {% for ev in audit_items %}
  75. <tr>
  76. <td class="px-5 py-2 align-top"><time class="irdb-dt font-mono text-xs text-slate-600 dark:text-slate-300" datetime="{{ ev.occurred_at }}" title="{{ ev.occurred_at }}">{{ ev.occurred_at }}</time></td>
  77. <td class="px-5 py-2 align-top text-xs">
  78. <span class="rounded bg-slate-100 px-1.5 py-0.5 font-mono uppercase tracking-tight text-slate-700 dark:bg-slate-800 dark:text-slate-300">{{ ev.actor_kind }}</span>
  79. {% if ev.actor_id %}<span class="ml-1 font-mono text-slate-500">#{{ ev.actor_id }}</span>{% endif %}
  80. </td>
  81. <td class="px-5 py-2 align-top">
  82. <span class="inline-block rounded bg-cyan-100 px-2 py-0.5 font-mono text-[0.7rem] uppercase tracking-tight text-cyan-900 dark:bg-cyan-900 dark:text-cyan-100">{{ ev.action }}</span>
  83. </td>
  84. <td class="px-5 py-2 align-top text-right">
  85. {% if ev.details %}
  86. <button type="button" x-on:click="open = (open === {{ ev.id }} ? null : {{ ev.id }})" class="rounded border border-slate-300 px-2 py-0.5 text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">View</button>
  87. {% else %}
  88. <span class="text-xs text-slate-400">—</span>
  89. {% endif %}
  90. </td>
  91. </tr>
  92. {% if ev.details %}
  93. <tr x-show="open === {{ ev.id }}" x-cloak>
  94. <td colspan="4" class="bg-slate-50 px-5 py-3 dark:bg-slate-950">
  95. {% if ev.details.changes is defined and ev.details.changes is iterable and ev.details.changes|length > 0 %}
  96. <div class="mb-2 text-[0.7rem] font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">Changes</div>
  97. <table class="w-full text-xs">
  98. <thead class="text-left text-[0.7rem] uppercase text-slate-500 dark:text-slate-400">
  99. <tr>
  100. <th class="px-2 py-1 font-medium">Field</th>
  101. <th class="px-2 py-1 font-medium">Before</th>
  102. <th class="px-2 py-1 font-medium">After</th>
  103. </tr>
  104. </thead>
  105. <tbody class="divide-y divide-slate-200 bg-white dark:divide-slate-800 dark:bg-slate-900">
  106. {% for field, change in ev.details.changes %}
  107. <tr>
  108. <td class="px-2 py-1 font-mono text-slate-700 dark:text-slate-200">{{ field }}</td>
  109. <td class="px-2 py-1 align-top">
  110. {% if change.from is null %}
  111. <span class="text-slate-400">∅</span>
  112. {% elseif change.from is iterable %}
  113. <pre class="overflow-x-auto rounded bg-rose-50 px-2 py-1 font-mono text-[0.7rem] text-rose-900 dark:bg-rose-950 dark:text-rose-200">{{ change.from|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  114. {% else %}
  115. <span class="rounded bg-rose-50 px-1.5 py-0.5 font-mono text-rose-900 dark:bg-rose-950 dark:text-rose-200">{{ change.from }}</span>
  116. {% endif %}
  117. </td>
  118. <td class="px-2 py-1 align-top">
  119. {% if change.to is null %}
  120. <span class="text-slate-400">∅</span>
  121. {% elseif change.to is iterable %}
  122. <pre class="overflow-x-auto rounded bg-emerald-50 px-2 py-1 font-mono text-[0.7rem] text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200">{{ change.to|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  123. {% else %}
  124. <span class="rounded bg-emerald-50 px-1.5 py-0.5 font-mono text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200">{{ change.to }}</span>
  125. {% endif %}
  126. </td>
  127. </tr>
  128. {% endfor %}
  129. </tbody>
  130. </table>
  131. {% else %}
  132. <pre class="overflow-x-auto rounded bg-white p-3 text-xs dark:bg-slate-900">{{ ev.details|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  133. {% endif %}
  134. </td>
  135. </tr>
  136. {% endif %}
  137. {% endfor %}
  138. </tbody>
  139. </table>
  140. </div>
  141. {% else %}
  142. <p class="px-5 py-6 text-center text-sm text-slate-400">No activity yet.</p>
  143. {% endif %}
  144. </section>
  145. </div>
  146. {% endblock %}