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