diff --git a/bookwyrm/middleware/__init__.py b/bookwyrm/middleware/__init__.py index 404ea9769..03843c5a3 100644 --- a/bookwyrm/middleware/__init__.py +++ b/bookwyrm/middleware/__init__.py @@ -1,3 +1,3 @@ """ look at all this nice middleware! """ -from timezone_middleware import TimezoneMiddleware -from ip_middleware import IPBlocklistMiddleware +from .timezone_middleware import TimezoneMiddleware +from .ip_middleware import IPBlocklistMiddleware diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index e8e1b696e..4228371f5 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -26,8 +26,8 @@ from .import_job import ImportJob, ImportItem from .site import SiteSettings, SiteInvite from .site import PasswordReset, InviteRequest -from .site import EmailBlocklist from .announcement import Announcement +from .antispam import EmailBlocklist, IPBlocklist cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass) activity_models = { diff --git a/bookwyrm/models/antispam.py b/bookwyrm/models/antispam.py new file mode 100644 index 000000000..7a85bbcf0 --- /dev/null +++ b/bookwyrm/models/antispam.py @@ -0,0 +1,35 @@ +""" Lets try NOT to sell viagra """ +from django.db import models + +from .user import User + + +class EmailBlocklist(models.Model): + """blocked email addresses""" + + created_date = models.DateTimeField(auto_now_add=True) + domain = models.CharField(max_length=255, unique=True) + is_active = models.BooleanField(default=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}") + + +class IPBlocklist(models.Model): + """blocked ip addresses""" + + created_date = models.DateTimeField(auto_now_add=True) + address = models.CharField(max_length=255, unique=True) + is_active = models.BooleanField(default=True) + + class Meta: + """default sorting""" + + ordering = ("-created_date",) diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 09732c2fc..ee69a507f 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -124,23 +124,6 @@ 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):