Reload instance data

This commit is contained in:
Mouse Reeve 2022-02-28 13:09:43 -08:00
parent c91b08303b
commit 81cfcff939
5 changed files with 37 additions and 8 deletions

View file

@ -478,10 +478,13 @@ def set_remote_server(user_id):
get_remote_reviews.delay(user.outbox)
def get_or_create_remote_server(domain):
def get_or_create_remote_server(domain, refresh=False):
"""get info on a remote server"""
server = FederatedServer()
try:
return FederatedServer.objects.get(server_name=domain)
server = FederatedServer.objects.get(server_name=domain)
if not refresh:
return server
except FederatedServer.DoesNotExist:
pass
@ -496,13 +499,15 @@ def get_or_create_remote_server(domain):
application_type = data.get("software", {}).get("name")
application_version = data.get("software", {}).get("version")
except ConnectorException:
if server.id:
return server
application_type = application_version = None
server = FederatedServer.objects.create(
server_name=domain,
application_type=application_type,
application_version=application_version,
)
server.server_name = domain
server.application_type = application_type
server.application_version = application_version
server.save()
return server

View file

@ -11,6 +11,13 @@
{% endif %}
{% endblock %}
{% block edit-button %}
<form name="reload" method="POST" action="{% url 'settings-federated-server-refresh' server.id %}">
{% csrf_token %}
<button class="button" type="submit">{% trans "Refresh data" %}</button>
</form>
{% endblock %}
{% block breadcrumbs %}
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
<ul>

View file

@ -144,6 +144,11 @@ urlpatterns = [
views.unblock_server,
name="settings-federated-server-unblock",
),
re_path(
r"^settings/federation/(?P<server>\d+)/refresh/?$",
views.refresh_server,
name="settings-federated-server-refresh",
),
re_path(
r"^settings/federation/add/?$",
views.AddFederatedServer.as_view(),

View file

@ -6,7 +6,7 @@ from .admin.automod import AutoMod, automod_delete, run_automod
from .admin.dashboard import Dashboard
from .admin.federation import Federation, FederatedServer
from .admin.federation import AddFederatedServer, ImportServerBlocklist
from .admin.federation import block_server, unblock_server
from .admin.federation import block_server, unblock_server, refresh_server
from .admin.email_blocklist import EmailBlocklist
from .admin.ip_blocklist import IPBlocklist
from .admin.invite import ManageInvites, Invite, InviteRequest

View file

@ -11,6 +11,7 @@ from django.views.decorators.http import require_POST
from bookwyrm import forms, models
from bookwyrm.settings import PAGE_LENGTH
from bookwyrm.models.user import get_or_create_remote_server
# pylint: disable= no-self-use
@ -163,3 +164,14 @@ def unblock_server(request, server):
server = get_object_or_404(models.FederatedServer, id=server)
server.unblock()
return redirect("settings-federated-server", server.id)
@login_required
@require_POST
@permission_required("bookwyrm.control_federation", raise_exception=True)
# pylint: disable=unused-argument
def refresh_server(request, server):
"""unblock a server"""
server = get_object_or_404(models.FederatedServer, id=server)
get_or_create_remote_server(server.server_name, refresh=True)
return redirect("settings-federated-server", server.id)