Makes blocking it's own view

This commit is contained in:
Mouse Reeve 2021-04-10 10:37:28 -07:00
parent 81bc25b012
commit 2741aa55be
3 changed files with 20 additions and 13 deletions

View file

@ -27,3 +27,14 @@ class FederatedServer(BookWyrmModel):
""" block a server """
self.status = "blocked"
self.save()
# deactivate all associated users
self.user_set.update(is_active=False)
def unblock(self):
""" unblock a server """
self.status = "federated"
self.save()
# TODO: only reactivate users as appropriate
self.user_set.update(is_active=True)

View file

@ -77,16 +77,20 @@
<section class="block content">
<h2 class="title is-4">{% trans "Actions" %}</h2>
{% if server.status != 'blocked' %}
<form class="block" method="post" action="{% url 'settings-federated-server' server.id %}">
{% csrf_token %}
{% if server.status != 'blocked' %}
<button class="button is-danger">{% trans "Block" %}</button>
<p class="help">{% trans "All users from this instance will be deactivated." %}</p>
{% else %}
</form>
{% else %}
{% comment %}
<form class="block" method="post" action="{% url 'settings-federated-server-unblock' server.id %}">
<button class="button">{% trans "Un-block" %}</button>
<p class="help">{% trans "All users from this instance will be re-activated." %}</p>
{% endif %}
</form>
{% endcomment %}
{% endif %}
</section>
{% endblock %}

View file

@ -87,15 +87,7 @@ class FederatedServer(View):
return TemplateResponse(request, "settings/federated_server.html", data)
def post(self, request, server): # pylint: disable=unused-argument
""" (un)block a server """
""" block a server """
server = get_object_or_404(models.FederatedServer, id=server)
server.status = "blocked" if server.status == "federated" else "federated"
server.save()
# TODO: there needs to be differentiation between types of deactivated users
if server.status == "blocked":
server.user_set.update(is_active=False)
else:
server.user_set.update(is_active=True)
server.block()
return redirect("settings-federated-server", server.id)