diff --git a/snikket_web/admin.py b/snikket_web/admin.py index 5cbc53d..057d7aa 100644 --- a/snikket_web/admin.py +++ b/snikket_web/admin.py @@ -86,6 +86,14 @@ class EditUserForm(BaseForm): _l("Update user"), ) + action_restore = wtforms.SubmitField( + _l("Restore account"), + ) + + action_enable = wtforms.SubmitField( + _l("Unlock account"), + ) + action_create_reset = wtforms.SubmitField( _l("Create password reset link"), ) @@ -112,6 +120,32 @@ async def edit_user(localpart: str) -> typing.Union[werkzeug.Response, str]: ".user_password_reset_link", id_=reset_link.id_, )) + elif form.action_restore.data or form.action_enable.data: + await client.enable_user_account(localpart) + try: + if form.action_restore.data: + await flash( + _("User account restored"), + "success", + ) + else: + await flash( + _("User account unlocked"), + "success", + ) + return redirect(url_for(".users")) + except aiohttp.ClientResponseError as exc: + if form.action_restore.data: + await flash( + _("Could not restore user account"), + "alert", + ) + else: + await flash( + _("Could not unlock user account"), + "alert", + ) + return redirect(url_for(".edit_user", localpart=localpart)) await client.update_user( localpart, diff --git a/snikket_web/templates/admin_edit_user.html b/snikket_web/templates/admin_edit_user.html index 7e601a4..18e30b8 100644 --- a/snikket_web/templates/admin_edit_user.html +++ b/snikket_web/templates/admin_edit_user.html @@ -19,12 +19,33 @@ {% block content %}

{% trans user_name=target_user.localpart %}Edit user {{ user_name }}{% endtrans %}

{{ form.csrf_token }}
+ {% if target_user.deletion_request %} +
+
{% trans %}This user account is pending deletion{% endtrans %}
+

{% trans date=target_user.deletion_request.deleted_at | format_datetime %}The owner of the account sent a deletion request on {{ date }} using their app.{% endtrans %} +

{% trans time=(target_user.deletion_request.pending_until - now())|format_timedelta %}The account has been locked, and will be automatically deleted permanently in {{ time }}.{% endtrans %}

+ +

{% trans %}If this was a mistake, you can cancel the deletion and restore the account.{% endtrans %}

+ + {%- call form_button("restore_from_trash", form.action_restore, class="secondary") %}{% endcall %} +
+ {% elif not target_user.enabled %} +
+
{% trans %}This user account is locked{% endtrans %}
+

{% trans %}The user will not be able to log in to their account until it is unlocked again.{% endtrans %}

+ + {%- call form_button("lock_open", form.action_enable, class="secondary") %}{% endcall %} +
+ {% endif %} +

{% trans %}Edit user{% endtrans %}

+
{{ form.localpart.label }} {{ form.localpart(readonly="readonly") }}

{% trans %}The login name cannot be changed.{% endtrans %}

+
{{ form.display_name.label }} {{ form.display_name }}