diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 96a4e3030..24e0c21e9 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -299,6 +299,12 @@ class ReportForm(CustomForm): fields = ["user", "reporter", "statuses", "note"] +class EmailBlocklistForm(CustomForm): + class Meta: + model = models.EmailBlocklist + fields = ["domain"] + + class ServerForm(CustomForm): class Meta: model = models.FederatedServer diff --git a/bookwyrm/migrations/0090_auto_20210908_2346.py b/bookwyrm/migrations/0090_auto_20210908_2346.py new file mode 100644 index 000000000..7c8708573 --- /dev/null +++ b/bookwyrm/migrations/0090_auto_20210908_2346.py @@ -0,0 +1,45 @@ +# Generated by Django 3.2.4 on 2021-09-08 23:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0089_user_show_suggested_users"), + ] + + operations = [ + migrations.AlterField( + model_name="connector", + name="deactivation_reason", + field=models.CharField( + blank=True, + choices=[ + ("pending", "Pending"), + ("self_deletion", "Self Deletion"), + ("moderator_suspension", "Moderator Suspension"), + ("moderator_deletion", "Moderator Deletion"), + ("domain_block", "Domain Block"), + ], + max_length=255, + null=True, + ), + ), + migrations.AlterField( + model_name="user", + name="deactivation_reason", + field=models.CharField( + blank=True, + choices=[ + ("pending", "Pending"), + ("self_deletion", "Self Deletion"), + ("moderator_suspension", "Moderator Suspension"), + ("moderator_deletion", "Moderator Deletion"), + ("domain_block", "Domain Block"), + ], + max_length=255, + null=True, + ), + ), + ] diff --git a/bookwyrm/migrations/0090_emailblocklist.py b/bookwyrm/migrations/0090_emailblocklist.py new file mode 100644 index 000000000..6934e51e9 --- /dev/null +++ b/bookwyrm/migrations/0090_emailblocklist.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.4 on 2021-09-08 22:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0089_user_show_suggested_users"), + ] + + operations = [ + migrations.CreateModel( + 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, unique=True)), + ], + options={ + "ordering": ("-created_date",), + }, + ), + ] diff --git a/bookwyrm/migrations/0091_merge_0090_auto_20210908_2346_0090_emailblocklist.py b/bookwyrm/migrations/0091_merge_0090_auto_20210908_2346_0090_emailblocklist.py new file mode 100644 index 000000000..7aae2c7a6 --- /dev/null +++ b/bookwyrm/migrations/0091_merge_0090_auto_20210908_2346_0090_emailblocklist.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.4 on 2021-09-09 00:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0090_auto_20210908_2346"), + ("bookwyrm", "0090_emailblocklist"), + ] + + operations = [] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 6f378e83c..e8e1b696e 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -24,7 +24,9 @@ from .federated_server import FederatedServer from .import_job import ImportJob, ImportItem -from .site import SiteSettings, SiteInvite, PasswordReset, InviteRequest +from .site import SiteSettings, SiteInvite +from .site import PasswordReset, InviteRequest +from .site import EmailBlocklist from .announcement import Announcement cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 5b55ea50f..f19ebfd9b 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -13,6 +13,7 @@ DeactivationReason = models.TextChoices( [ "pending", "self_deletion", + "moderator_suspension", "moderator_deletion", "domain_block", ], diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index ef3f7c3ca..d9289b148 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -123,6 +123,23 @@ class PasswordReset(models.Model): return "https://{}/password-reset/{}".format(DOMAIN, self.code) +class EmailBlocklist(models.Model): + """blocked email addresses""" + + created_date = models.DateTimeField(auto_now_add=True) + 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""" + return User.objects.filter(email__endswith=f"@{self.domain}") + + # pylint: disable=unused-argument @receiver(models.signals.post_save, sender=SiteSettings) def preview_image(instance, *args, **kwargs): 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/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/announcement_form.html b/bookwyrm/templates/settings/announcement_form.html index 8eb6acd52..ffdbfc2fd 100644 --- a/bookwyrm/templates/settings/announcement_form.html +++ b/bookwyrm/templates/settings/announcement_form.html @@ -13,21 +13,21 @@ {% csrf_token %}
- + {{ form.preview }} {% for error in form.preview.errors %}
{{ error | escape }}
{% endfor %}- + {{ form.content }} {% for error in form.content.errors %}
{{ error | escape }}
{% endfor %}- + {% for error in form.event_date.errors %}
{{ error | escape }}
@@ -37,7 +37,7 @@- + {% for error in form.start_date.errors %}
{{ error | escape }}
@@ -46,7 +46,7 @@- + {% for error in form.end_date.errors %}
{{ error | escape }}
@@ -55,7 +55,7 @@- + {{ form.active }} {% for error in form.active.errors %}
{{ error | escape }}
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/domain_form.html b/bookwyrm/templates/settings/domain_form.html new file mode 100644 index 000000000..0919791e9 --- /dev/null +++ b/bookwyrm/templates/settings/domain_form.html @@ -0,0 +1,30 @@ +{% extends 'components/inline_form.html' %} +{% load i18n %} + +{% block header %} +{% trans "Add domain" %} +{% endblock %} + +{% block form %} + +{% 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/email_blocklist.html b/bookwyrm/templates/settings/email_blocklist.html new file mode 100644 index 000000000..f9e793788 --- /dev/null +++ b/bookwyrm/templates/settings/email_blocklist.html @@ -0,0 +1,62 @@ +{% extends 'settings/layout.html' %} +{% load i18n %} +{% load humanize %} + +{% block title %}{% trans "Email Blocklist" %}{% endblock %} + +{% block header %}{% trans "Email Blocklist" %}{% endblock %} + +{% block edit-button %} +{% 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." %} +
+ ++ {% trans "Domain" as text %} + {% include 'snippets/table-sort-header.html' with field="server_name" sort=sort text=text %} + | ++ | + {% trans "Options" %} + | +
---|---|---|
{{ domain.domain }} | ++ + {% with user_count=domain.users.count %} + {% blocktrans trimmed count conter=user_count with display_count=user_count|intcomma %} + {{ display_count }} user + {% plural %} + {{ display_count }} users + {% endblocktrans %} + {% endwith %} + + | ++ + | +
{% trans "Send direct message" %}
- + {% else %} + + {% endif %} + + {% if user.local %} +