forked from mirrors/bookwyrm
Reload instance data
This commit is contained in:
parent
c91b08303b
commit
81cfcff939
5 changed files with 37 additions and 8 deletions
|
@ -478,10 +478,13 @@ def set_remote_server(user_id):
|
||||||
get_remote_reviews.delay(user.outbox)
|
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"""
|
"""get info on a remote server"""
|
||||||
|
server = FederatedServer()
|
||||||
try:
|
try:
|
||||||
return FederatedServer.objects.get(server_name=domain)
|
server = FederatedServer.objects.get(server_name=domain)
|
||||||
|
if not refresh:
|
||||||
|
return server
|
||||||
except FederatedServer.DoesNotExist:
|
except FederatedServer.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -496,13 +499,15 @@ def get_or_create_remote_server(domain):
|
||||||
application_type = data.get("software", {}).get("name")
|
application_type = data.get("software", {}).get("name")
|
||||||
application_version = data.get("software", {}).get("version")
|
application_version = data.get("software", {}).get("version")
|
||||||
except ConnectorException:
|
except ConnectorException:
|
||||||
|
if server.id:
|
||||||
|
return server
|
||||||
application_type = application_version = None
|
application_type = application_version = None
|
||||||
|
|
||||||
server = FederatedServer.objects.create(
|
server.server_name = domain
|
||||||
server_name=domain,
|
server.application_type = application_type
|
||||||
application_type=application_type,
|
server.application_version = application_version
|
||||||
application_version=application_version,
|
|
||||||
)
|
server.save()
|
||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,13 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% 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 %}
|
{% block breadcrumbs %}
|
||||||
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -144,6 +144,11 @@ urlpatterns = [
|
||||||
views.unblock_server,
|
views.unblock_server,
|
||||||
name="settings-federated-server-unblock",
|
name="settings-federated-server-unblock",
|
||||||
),
|
),
|
||||||
|
re_path(
|
||||||
|
r"^settings/federation/(?P<server>\d+)/refresh/?$",
|
||||||
|
views.refresh_server,
|
||||||
|
name="settings-federated-server-refresh",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^settings/federation/add/?$",
|
r"^settings/federation/add/?$",
|
||||||
views.AddFederatedServer.as_view(),
|
views.AddFederatedServer.as_view(),
|
||||||
|
|
|
@ -6,7 +6,7 @@ from .admin.automod import AutoMod, automod_delete, run_automod
|
||||||
from .admin.dashboard import Dashboard
|
from .admin.dashboard import Dashboard
|
||||||
from .admin.federation import Federation, FederatedServer
|
from .admin.federation import Federation, FederatedServer
|
||||||
from .admin.federation import AddFederatedServer, ImportServerBlocklist
|
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.email_blocklist import EmailBlocklist
|
||||||
from .admin.ip_blocklist import IPBlocklist
|
from .admin.ip_blocklist import IPBlocklist
|
||||||
from .admin.invite import ManageInvites, Invite, InviteRequest
|
from .admin.invite import ManageInvites, Invite, InviteRequest
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
from bookwyrm.models.user import get_or_create_remote_server
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
|
@ -163,3 +164,14 @@ def unblock_server(request, server):
|
||||||
server = get_object_or_404(models.FederatedServer, id=server)
|
server = get_object_or_404(models.FederatedServer, id=server)
|
||||||
server.unblock()
|
server.unblock()
|
||||||
return redirect("settings-federated-server", server.id)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue