mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-30 12:00:36 +00:00
Remove edit server mode
It just doesn't really make sense
This commit is contained in:
parent
c4bca42f64
commit
d076162aa6
7 changed files with 49 additions and 42 deletions
|
@ -3,13 +3,13 @@
|
|||
{% block title %}{% trans "Add server" %}{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{% if server %}{{ server.server_name }}{% else %}{% trans "Add server" %}{% endif %}
|
||||
{% trans "Add server" %}
|
||||
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to server list" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
<form method="POST" action="{% url 'settings-edit-federated-server' server.id %}">
|
||||
<form method="POST" action="{% url 'settings-add-federated-server' %}">
|
||||
{% csrf_token %}
|
||||
<div class="columns">
|
||||
<div class="column is-half">
|
||||
|
|
|
@ -11,14 +11,6 @@
|
|||
<a href="{% url 'settings-federation' %}" class="has-text-weight-normal help">{% trans "Back to server list" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit-button %}
|
||||
<a href="{% url 'settings-edit-federated-server' server.id %}">
|
||||
<span class="icon icon-pencil" title="{% trans 'Edit server' %}">
|
||||
<span class="is-sr-only">{% trans "Edit server" %}</span>
|
||||
</span>
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
<div class="columns">
|
||||
<section class="column is-half content">
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{% block header %}{% trans "Federated Servers" %}{% endblock %}
|
||||
|
||||
{% block edit-button %}
|
||||
<a href="{% url 'settings-edit-federated-server' %}">
|
||||
<a href="{% url 'settings-add-federated-server' %}">
|
||||
<span class="icon icon-plus" title="{% trans 'Add server' %}">
|
||||
<span class="is-sr-only">{% trans "Add server" %}</span>
|
||||
</span>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
""" test for app action functionality """
|
||||
from unittest.mock import patch
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm import forms, models, views
|
||||
|
||||
|
||||
class FederationViews(TestCase):
|
||||
|
@ -19,6 +20,16 @@ class FederationViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
local=False,
|
||||
remote_id="https://example.com/users/rat",
|
||||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_federation_page(self):
|
||||
|
@ -48,6 +59,9 @@ class FederationViews(TestCase):
|
|||
def test_server_page_post(self):
|
||||
""" block and unblock a server """
|
||||
server = models.FederatedServer.objects.create(server_name="hi.there.com")
|
||||
self.remote_user.federated_server = server
|
||||
self.remote_user.save()
|
||||
|
||||
self.assertEqual(server.status, "federated")
|
||||
|
||||
view = views.FederatedServer.as_view()
|
||||
|
@ -63,10 +77,10 @@ class FederationViews(TestCase):
|
|||
server.refresh_from_db()
|
||||
self.assertEqual(server.status, "federated")
|
||||
|
||||
def test_edit_view_get(self):
|
||||
def test_add_view_get(self):
|
||||
""" there are so many views, this just makes sure it LOADS """
|
||||
# create mode
|
||||
view = views.EditFederatedServer.as_view()
|
||||
view = views.AddFederatedServer.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
@ -76,9 +90,19 @@ class FederationViews(TestCase):
|
|||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
# edit mode
|
||||
server = models.FederatedServer.objects.create(server_name="hi.there.com")
|
||||
result = view(request, server=server.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
def test_add_view_post_create(self):
|
||||
""" create or edit a server """
|
||||
form = forms.ServerForm()
|
||||
form.data["server_name"] = "remote.server"
|
||||
form.data["software"] = "coolsoft"
|
||||
|
||||
view = views.AddFederatedServer.as_view()
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
||||
view(request, server=None)
|
||||
server = models.FederatedServer.objects.get()
|
||||
self.assertEqual(server.server_name, "remote.server")
|
||||
self.assertEqual(server.software, "coolsoft")
|
||||
self.assertEqual(server.status, "federated")
|
||||
|
|
|
@ -69,14 +69,9 @@ urlpatterns = [
|
|||
name="settings-federated-server",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/federation/edit/?$",
|
||||
views.EditFederatedServer.as_view(),
|
||||
name="settings-edit-federated-server",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/federation/edit/(?P<server>\d+)?$",
|
||||
views.EditFederatedServer.as_view(),
|
||||
name="settings-edit-federated-server",
|
||||
r"^settings/federation/add/?$",
|
||||
views.AddFederatedServer.as_view(),
|
||||
name="settings-add-federated-server",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/invites/?$", views.ManageInvites.as_view(), name="settings-invites"
|
||||
|
|
|
@ -5,7 +5,7 @@ from .block import Block, unblock
|
|||
from .books import Book, EditBook, ConfirmEditBook, Editions
|
||||
from .books import upload_cover, add_description, switch_edition, resolve_book
|
||||
from .directory import Directory
|
||||
from .federation import Federation, FederatedServer, EditFederatedServer
|
||||
from .federation import Federation, FederatedServer, AddFederatedServer
|
||||
from .feed import DirectMessage, Feed, Replies, Status
|
||||
from .follow import follow, unfollow
|
||||
from .follow import accept_follow_request, delete_follow_request
|
||||
|
|
|
@ -30,7 +30,8 @@ class Federation(View):
|
|||
|
||||
sort = request.GET.get("sort")
|
||||
sort_fields = ["created_date", "application_type", "server_name"]
|
||||
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
sort = "created_date"
|
||||
servers = servers.order_by(sort)
|
||||
|
||||
paginated = Paginator(servers, PAGE_LENGTH)
|
||||
|
@ -43,24 +44,19 @@ class Federation(View):
|
|||
return TemplateResponse(request, "settings/federation.html", data)
|
||||
|
||||
|
||||
class EditFederatedServer(View):
|
||||
class AddFederatedServer(View):
|
||||
""" manually add a server """
|
||||
|
||||
def get(self, request, server=None):
|
||||
def get(self, request):
|
||||
""" add server form """
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
data = {"form": forms.ServerForm(instance=server), "server": server}
|
||||
data = {"form": forms.ServerForm()}
|
||||
return TemplateResponse(request, "settings/edit_server.html", data)
|
||||
|
||||
def post(self, request, server=None):
|
||||
def post(self, request):
|
||||
""" add a server from the admin panel """
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
|
||||
form = forms.ServerForm(request.POST, instance=server)
|
||||
form = forms.ServerForm(request.POST)
|
||||
if not form.is_valid():
|
||||
data = {"form": form, "server": server}
|
||||
data = {"form": form}
|
||||
return TemplateResponse(request, "settings/edit_server.html", data)
|
||||
server = form.save()
|
||||
return redirect("settings-federated-server", server.id)
|
||||
|
|
Loading…
Reference in a new issue