mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Merge pull request #1986 from bookwyrm-social/instance-refresh
Instance refresh
This commit is contained in:
commit
e1ea847441
8 changed files with 90 additions and 16 deletions
|
@ -479,10 +479,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
|
||||||
|
|
||||||
|
@ -497,13 +500,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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,19 @@
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% trans "Add instance" %}
|
{% trans "Add instance" %}
|
||||||
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to instance list" %}</a>
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'settings-federation' %}">{% trans "Federated Instances" %}</a></li>
|
||||||
|
<li class="is-active">
|
||||||
|
<a href="#" aria-current="page">
|
||||||
|
{% trans "Add instance" %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
@ -73,9 +85,13 @@
|
||||||
<label class="label" for="id_notes">
|
<label class="label" for="id_notes">
|
||||||
{% trans "Notes:" %}
|
{% trans "Notes:" %}
|
||||||
</label>
|
</label>
|
||||||
<textarea name="notes" cols="40" rows="5" class="textarea" id="id_notes">
|
<textarea
|
||||||
{{ form.notes.value|default:'' }}
|
name="notes"
|
||||||
</textarea>
|
cols="40"
|
||||||
|
rows="5"
|
||||||
|
class="textarea"
|
||||||
|
id="id_notes"
|
||||||
|
>{{ form.notes.value|default:'' }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="button is-primary">
|
<button type="submit" class="button is-primary">
|
||||||
|
|
|
@ -9,8 +9,26 @@
|
||||||
|
|
||||||
{% if server.status == "blocked" %}<span class="icon icon-x has-text-danger is-size-5" title="{% trans 'Blocked' %}"><span class="is-sr-only">{% trans "Blocked" %}</span></span>
|
{% if server.status == "blocked" %}<span class="icon icon-x has-text-danger is-size-5" title="{% trans 'Blocked' %}"><span class="is-sr-only">{% trans "Blocked" %}</span></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to list" %}</a>
|
{% 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>
|
||||||
|
<li><a href="{% url 'settings-federation' %}">{% trans "Federated Instances" %}</a></li>
|
||||||
|
<li class="is-active">
|
||||||
|
<a href="#" aria-current="page">
|
||||||
|
{{ server.server_name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
|
@ -4,7 +4,19 @@
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% trans "Import Blocklist" %}
|
{% trans "Import Blocklist" %}
|
||||||
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to instance list" %}</a>
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'settings-federation' %}">{% trans "Federated Instances" %}</a></li>
|
||||||
|
<li class="is-active">
|
||||||
|
<a href="#" aria-current="page">
|
||||||
|
{% trans "Import Blocklist" %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% url 'settings-federation' status='federated' as url %}
|
{% url 'settings-federation' status='federated' as url %}
|
||||||
<li {% if request.path in url %}class="is-active" aria-current="page"{% endif %}>
|
<li {% if request.path in url %}class="is-active" aria-current="page"{% endif %}>
|
||||||
<a href="{{ url }}">{% trans "Federated" %}</a>
|
<a href="{{ url }}">{% trans "Federated" %} ({{ federated_count }})</a>
|
||||||
</li>
|
</li>
|
||||||
{% url 'settings-federation' status='blocked' as url %}
|
{% url 'settings-federation' status='blocked' as url %}
|
||||||
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
|
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
|
||||||
<a href="{{ url }}">{% trans "Blocked" %}</a>
|
<a href="{{ url }}">{% trans "Blocked" %} ({{ blocked_count }})</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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
|
||||||
|
@ -37,6 +38,12 @@ class Federation(View):
|
||||||
page = paginated.get_page(request.GET.get("page"))
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
"federated_count": models.FederatedServer.objects.filter(
|
||||||
|
status="federated"
|
||||||
|
).count(),
|
||||||
|
"blocked_count": models.FederatedServer.objects.filter(
|
||||||
|
status="blocked"
|
||||||
|
).count(),
|
||||||
"servers": page,
|
"servers": page,
|
||||||
"page_range": paginated.get_elided_page_range(
|
"page_range": paginated.get_elided_page_range(
|
||||||
page.number, on_each_side=2, on_ends=1
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
@ -157,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