From 84fcc358fa3c11be63967e9fa8729eae89b14e7e Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Wed, 8 Sep 2021 14:05:08 -0700
Subject: [PATCH 01/18] Renames layout file
---
bookwyrm/templates/settings/announcement.html | 2 +-
bookwyrm/templates/settings/announcements.html | 2 +-
bookwyrm/templates/settings/edit_server.html | 2 +-
bookwyrm/templates/settings/federated_server.html | 2 +-
bookwyrm/templates/settings/federation.html | 2 +-
bookwyrm/templates/settings/{admin_layout.html => layout.html} | 0
bookwyrm/templates/settings/manage_invite_requests.html | 2 +-
bookwyrm/templates/settings/manage_invites.html | 2 +-
bookwyrm/templates/settings/server_blocklist.html | 2 +-
bookwyrm/templates/settings/site.html | 2 +-
10 files changed, 9 insertions(+), 9 deletions(-)
rename bookwyrm/templates/settings/{admin_layout.html => layout.html} (100%)
diff --git a/bookwyrm/templates/settings/announcement.html b/bookwyrm/templates/settings/announcement.html
index c0e5dec88..b3375bb50 100644
--- a/bookwyrm/templates/settings/announcement.html
+++ b/bookwyrm/templates/settings/announcement.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}{% load humanize %}
{% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %}
diff --git a/bookwyrm/templates/settings/announcements.html b/bookwyrm/templates/settings/announcements.html
index 18e765317..aba412473 100644
--- a/bookwyrm/templates/settings/announcements.html
+++ b/bookwyrm/templates/settings/announcements.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}{% load humanize %}
{% block title %}{% trans "Announcements" %}{% endblock %}
diff --git a/bookwyrm/templates/settings/edit_server.html b/bookwyrm/templates/settings/edit_server.html
index 55346a526..452316e43 100644
--- a/bookwyrm/templates/settings/edit_server.html
+++ b/bookwyrm/templates/settings/edit_server.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block title %}{% trans "Add instance" %}{% endblock %}
diff --git a/bookwyrm/templates/settings/federated_server.html b/bookwyrm/templates/settings/federated_server.html
index c47dd285c..140a0af75 100644
--- a/bookwyrm/templates/settings/federated_server.html
+++ b/bookwyrm/templates/settings/federated_server.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% load markdown %}
diff --git a/bookwyrm/templates/settings/federation.html b/bookwyrm/templates/settings/federation.html
index e0a9ba73a..ed122e0b2 100644
--- a/bookwyrm/templates/settings/federation.html
+++ b/bookwyrm/templates/settings/federation.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block title %}{% trans "Federated Instances" %}{% endblock %}
diff --git a/bookwyrm/templates/settings/admin_layout.html b/bookwyrm/templates/settings/layout.html
similarity index 100%
rename from bookwyrm/templates/settings/admin_layout.html
rename to bookwyrm/templates/settings/layout.html
diff --git a/bookwyrm/templates/settings/manage_invite_requests.html b/bookwyrm/templates/settings/manage_invite_requests.html
index 5b7315f98..e0cfd6469 100644
--- a/bookwyrm/templates/settings/manage_invite_requests.html
+++ b/bookwyrm/templates/settings/manage_invite_requests.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% load humanize %}
{% block header %}{% trans "Invite Requests" %}{% endblock %}
diff --git a/bookwyrm/templates/settings/manage_invites.html b/bookwyrm/templates/settings/manage_invites.html
index 6efaefcf2..95b8bdf00 100644
--- a/bookwyrm/templates/settings/manage_invites.html
+++ b/bookwyrm/templates/settings/manage_invites.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block header %}{% trans "Invites" %}{% endblock %}
{% load humanize %}
diff --git a/bookwyrm/templates/settings/server_blocklist.html b/bookwyrm/templates/settings/server_blocklist.html
index 49334982f..926ab5f4a 100644
--- a/bookwyrm/templates/settings/server_blocklist.html
+++ b/bookwyrm/templates/settings/server_blocklist.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block title %}{% trans "Add instance" %}{% endblock %}
diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html
index 05b504a97..354e49e81 100644
--- a/bookwyrm/templates/settings/site.html
+++ b/bookwyrm/templates/settings/site.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block title %}{% trans "Site Settings" %}{% endblock %}
From fd0cf49b408cea033ebe86c78d97cf63bbadd668 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Wed, 8 Sep 2021 14:32:11 -0700
Subject: [PATCH 02/18] Adds html and view for email blocklist
---
bookwyrm/templates/moderation/report.html | 2 +-
bookwyrm/templates/moderation/reports.html | 2 +-
.../templates/settings/email_blocklist.html | 40 +++++++++++++++++++
bookwyrm/templates/settings/layout.html | 19 ++++++---
bookwyrm/templates/user_admin/user.html | 2 +-
bookwyrm/templates/user_admin/user_admin.html | 2 +-
bookwyrm/urls.py | 1 +
bookwyrm/views/__init__.py | 1 +
bookwyrm/views/email_blocklist.py | 19 +++++++++
9 files changed, 78 insertions(+), 10 deletions(-)
create mode 100644 bookwyrm/templates/settings/email_blocklist.html
create mode 100644 bookwyrm/views/email_blocklist.py
diff --git a/bookwyrm/templates/moderation/report.html b/bookwyrm/templates/moderation/report.html
index db03850f8..d0e4026a7 100644
--- a/bookwyrm/templates/moderation/report.html
+++ b/bookwyrm/templates/moderation/report.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% load humanize %}
diff --git a/bookwyrm/templates/moderation/reports.html b/bookwyrm/templates/moderation/reports.html
index 95a276af4..c83f626fa 100644
--- a/bookwyrm/templates/moderation/reports.html
+++ b/bookwyrm/templates/moderation/reports.html
@@ -1,4 +1,4 @@
-{% extends 'settings/admin_layout.html' %}
+{% extends 'settings/layout.html' %}
{% load i18n %}
{% block title %}
diff --git a/bookwyrm/templates/settings/email_blocklist.html b/bookwyrm/templates/settings/email_blocklist.html
new file mode 100644
index 000000000..62561f747
--- /dev/null
+++ b/bookwyrm/templates/settings/email_blocklist.html
@@ -0,0 +1,40 @@
+{% extends 'settings/layout.html' %}
+{% load i18n %}
+{% block title %}{% trans "Email Blocklist" %}{% endblock %}
+
+{% block header %}{% trans "Email Blocklist" %}{% endblock %}
+
+{% block edit-button %}
+
+
+ {% trans "Add domain" %}
+
+{% endblock %}
+
+{% block panel %}
+
+
+ {% url 'settings-federation' as url %}
+
+ {% trans "Domain" as text %}
+ {% include 'snippets/table-sort-header.html' with field="server_name" sort=sort text=text %}
+
+
+ {% trans "Options" %}
+
+
+
+ gmail.com
+
+ {% trans "Delete" as button_text %}
+
+
+ {{ button_text }}
+
+
+
+
+
+{% include 'snippets/pagination.html' with page=servers path=request.path %}
+{% endblock %}
+
diff --git a/bookwyrm/templates/settings/layout.html b/bookwyrm/templates/settings/layout.html
index 6d6516476..119f52bfa 100644
--- a/bookwyrm/templates/settings/layout.html
+++ b/bookwyrm/templates/settings/layout.html
@@ -32,12 +32,6 @@
{% url 'settings-invites' as alt_url %}
{% trans "Invites" %}
- {% if perms.bookwyrm.moderate_user %}
-
- {% url 'settings-reports' as url %}
- {% trans "Reports" %}
-
- {% endif %}
{% if perms.bookwyrm.control_federation %}
{% url 'settings-federation' as url %}
@@ -46,6 +40,19 @@
{% endif %}
{% endif %}
+ {% if perms.bookwyrm.moderate_user %}
+
+
+ {% endif %}
{% if perms.bookwyrm.edit_instance_settings %}
- Content:
+ {% trans "Content:" %}
{{ form.content }}
{% for error in form.content.errors %}
{{ error | escape }}
{% endfor %}
- Event date:
+ {% trans "Event date:" %}
{% for error in form.event_date.errors %}
{{ error | escape }}
@@ -37,7 +37,7 @@
- Start date:
+ {% trans "Start date:" %}
{% for error in form.start_date.errors %}
{{ error | escape }}
@@ -46,7 +46,7 @@
- End date:
+ {% trans "End date:" %}
{% for error in form.end_date.errors %}
{{ error | escape }}
@@ -55,7 +55,7 @@
- Active:
+ {% trans "Active:" %}
{{ form.active }}
{% for error in form.active.errors %}
{{ error | escape }}
diff --git a/bookwyrm/templates/settings/domain_form.html b/bookwyrm/templates/settings/domain_form.html
new file mode 100644
index 000000000..e40a0d542
--- /dev/null
+++ b/bookwyrm/templates/settings/domain_form.html
@@ -0,0 +1,25 @@
+{% extends 'components/inline_form.html' %}
+{% load i18n %}
+
+{% block header %}
+{% trans "Add domain" %}
+{% endblock %}
+
+{% block form %}
+
+{% endblock %}
diff --git a/bookwyrm/templates/settings/email_blocklist.html b/bookwyrm/templates/settings/email_blocklist.html
index 62561f747..54779854a 100644
--- a/bookwyrm/templates/settings/email_blocklist.html
+++ b/bookwyrm/templates/settings/email_blocklist.html
@@ -5,13 +5,18 @@
{% block header %}{% trans "Email Blocklist" %}{% endblock %}
{% block edit-button %}
-
-
- {% trans "Add domain" %}
+{% trans "Add domain" as button_text %}
+{% include 'snippets/toggle/open_button.html' with controls_text="add_domain" icon_with_text="plus" text=button_text focus="add_domain_header" %}
{% endblock %}
{% block panel %}
+{% include 'settings/domain_form.html' with controls_text="add_domain" class="block" %}
+
+
+ {% trans "When someone tries to register with an email from this domain, no account will be created. The registration process will appear to have worked." %}
+
+
{% url 'settings-federation' as url %}
@@ -23,8 +28,9 @@
{% trans "Options" %}
+ {% for domain in domains %}
- gmail.com
+ {{ domain.domain }}
{% trans "Delete" as button_text %}
@@ -33,6 +39,7 @@
+ {% endfor %}
{% include 'snippets/pagination.html' with page=servers path=request.path %}
diff --git a/bookwyrm/views/email_blocklist.py b/bookwyrm/views/email_blocklist.py
index 734f81366..156b86277 100644
--- a/bookwyrm/views/email_blocklist.py
+++ b/bookwyrm/views/email_blocklist.py
@@ -4,6 +4,8 @@ from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
+from bookwyrm import forms, models
+
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
@method_decorator(
@@ -15,5 +17,8 @@ class EmailBlocklist(View):
def get(self, request):
"""view and compose blocks"""
- data = {}
+ data = {
+ "domains": models.EmailBlocklist.objects.order_by("-created_date").all(),
+ "form": forms.EmailBlocklistForm(),
+ }
return TemplateResponse(request, "settings/email_blocklist.html", data)
From 8717d8a675409d11e38723509a24ca28f3599374 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Wed, 8 Sep 2021 15:30:18 -0700
Subject: [PATCH 06/18] Create new email domain block entries
---
bookwyrm/migrations/0090_emailblocklist.py | 23 ++++++++-----------
bookwyrm/models/site.py | 9 ++++++--
bookwyrm/templates/settings/domain_form.html | 17 +++++++++-----
.../templates/settings/email_blocklist.html | 20 ++++++++++++++--
bookwyrm/views/email_blocklist.py | 14 +++++++++++
5 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/bookwyrm/migrations/0090_emailblocklist.py b/bookwyrm/migrations/0090_emailblocklist.py
index 57e27989a..2592e329e 100644
--- a/bookwyrm/migrations/0090_emailblocklist.py
+++ b/bookwyrm/migrations/0090_emailblocklist.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.2.4 on 2021-09-08 21:37
+# Generated by Django 3.2.4 on 2021-09-08 22:21
from django.db import migrations, models
@@ -6,24 +6,19 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
- ("bookwyrm", "0089_user_show_suggested_users"),
+ ('bookwyrm', '0089_user_show_suggested_users'),
]
operations = [
migrations.CreateModel(
- name="EmailBlocklist",
+ name='EmailBlocklist',
fields=[
- (
- "id",
- models.AutoField(
- auto_created=True,
- primary_key=True,
- serialize=False,
- verbose_name="ID",
- ),
- ),
- ("created_date", models.DateTimeField(auto_now_add=True)),
- ("domain", models.CharField(max_length=255)),
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('created_date', models.DateTimeField(auto_now_add=True)),
+ ('domain', models.CharField(max_length=255, unique=True)),
],
+ options={
+ 'ordering': ('-created_date',),
+ },
),
]
diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py
index e3a657cc7..d9289b148 100644
--- a/bookwyrm/models/site.py
+++ b/bookwyrm/models/site.py
@@ -127,12 +127,17 @@ class EmailBlocklist(models.Model):
"""blocked email addresses"""
created_date = models.DateTimeField(auto_now_add=True)
- domain = models.CharField(max_length=255)
+ domain = models.CharField(max_length=255, unique=True)
+
+ class Meta:
+ """default sorting"""
+
+ ordering = ("-created_date",)
@property
def users(self):
"""find the users associated with this address"""
- User.objects.filter(email__endswith=f"@{self.domain}")
+ return User.objects.filter(email__endswith=f"@{self.domain}")
# pylint: disable=unused-argument
diff --git a/bookwyrm/templates/settings/domain_form.html b/bookwyrm/templates/settings/domain_form.html
index e40a0d542..0919791e9 100644
--- a/bookwyrm/templates/settings/domain_form.html
+++ b/bookwyrm/templates/settings/domain_form.html
@@ -8,13 +8,18 @@
{% block form %}