{% extends "admin/base_site.html" %} {% load i18n %} {% block extrastyle %}{{ block.super }} {% endblock %} {% block breadcrumbs %} {% endblock %} {% block content %}

{% trans "Block or unblock any subject — a user, IP, or session. Pick a scope, enter the value, and optionally set a TTL in seconds (leave it blank for a permanent block). Blocks take effect on the subject's next request." %}

{# ── Create / lift a block ────────────────────────────────────────── #}
{% if editing_subject %}

{% trans 'Edit block' %}

{% blocktrans %}Adjust {{ editing_subject }} and re-block to overwrite it{% endblocktrans %} {% else %}

{% trans 'New block' %}

{% trans 'Restrict a subject from accessing the app' %} {% endif %}
{% csrf_token %} {{ form.non_field_errors }}
{{ form.scope_type }} {{ form.scope_type.errors }}
{{ form.scope_value }} {{ form.scope_value.errors }}

{% trans 'User id, IP address, or session key.' %}

{{ form.ttl }} {{ form.ttl.errors }}

{{ form.ttl.help_text }}

{{ form.reason }} {{ form.reason.errors }}

{% trans 'Recorded with the block for the audit trail.' %}

{% trans 'Advanced overrides' %}
{{ form.status_code }} {{ form.status_code.errors }}

{{ form.status_code.help_text }}

{{ form.message }} {{ form.message.errors }}

{% trans 'Body returned to the blocked subject.' %}

{% trans '“Unblock” lifts an existing block for the same scope and value.' %}
{# ── Active blocks ────────────────────────────────────────────────── #}

{% trans 'Active blocks' %}

{{ active_blocks|length }}
{% if active_blocks %}
{% for entry in active_blocks %} {% endfor %}
{% trans 'Scope' %} {% trans 'Subject' %} {% trans 'Reason' %} {% trans 'Rule' %} {% trans 'Duration' %}
{{ entry.scope.scope_type }} {{ entry.scope.scope_value }} {{ entry.reason|default:'—' }} {% if entry.rule_name %}{{ entry.rule_name }}{% else %}{% endif %} {% if entry.expires_at %} {% trans 'Temporary' %} {% trans 'expires' %} {{ entry.expires_at|date:"M j, Y, g:i a" }} {% else %} {% trans 'Permanent' %} {% if entry.created_at %}{% trans 'since' %} {{ entry.created_at|date:"M j, Y" }}{% endif %} {% endif %}
{% csrf_token %}

{% trans "Durable (permanent) blocks, backed by the database. Temporary (Redis-only) blocks are listed separately below." %}

{% else %}

{% trans 'No active permanent blocks.' %}

{% trans 'Subjects you block permanently will appear here.' %}

{% endif %}
{# ── Active temp blocks ───────────────────────────────────────────── #}

{% trans 'Active temp blocks' %}

{{ temp_blocks|length }}
{% if temp_blocks_error %}

{% trans "Couldn’t read temporary blocks — the Redis backend is unavailable. Permanent blocks above are unaffected." %}

{% elif temp_blocks %}
{% for row in temp_blocks %} {% endfor %}
{% trans 'Scope' %} {% trans 'Subject' %} {% trans 'Reason' %} {% trans 'Rule' %} {% trans 'Expires' %}
{{ row.entry.scope.scope_type }} {{ row.entry.scope.scope_value }} {{ row.entry.reason|default:'—' }} {% if row.entry.rule_name %}{{ row.entry.rule_name }}{% else %}{% endif %} {% trans 'Temporary' %} {% if row.entry.expires_at %}{% trans 'expires' %} {{ row.entry.expires_at|date:"M j, Y, g:i a" }}{% endif %}
{# Edit: prefill the block form (GET) so it can be adjusted + re-blocked (overwrite). #}
{% if row.remaining_ttl %}{% endif %} {% if row.entry.status_code %}{% endif %}
{% csrf_token %}

{% trans "Temporary blocks live in Redis and auto-expire at the time shown. Edit prefills the form so you can change the TTL or reason and re-block to overwrite; Unblock lifts it immediately." %}

{% else %}

{% trans 'No active temp blocks.' %}

{% trans 'Rule-driven and TTL blocks will appear here until they expire.' %}

{% endif %}
{% endblock %}