From 6f3b1b565f179deb0b43369321e300ea2fc257e0 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Fri, 27 Oct 2023 22:00:04 +1100
Subject: [PATCH] fixes to move layout and notifs
- make Move notifications less complicated
- moved users cannot do anything other than unmove or log out
- refactor translations for moved users
---
bookwyrm/models/__init__.py | 2 +-
bookwyrm/models/move.py | 23 ++-------
bookwyrm/models/notification.py | 18 +------
bookwyrm/templates/feed/layout.html | 17 -------
bookwyrm/templates/layout.html | 19 +++++---
bookwyrm/templates/moved.html | 48 +++++++++++++++++++
.../notifications/items/move_user.html | 8 +++-
bookwyrm/templates/preferences/move_user.html | 4 +-
8 files changed, 75 insertions(+), 64 deletions(-)
create mode 100644 bookwyrm/templates/moved.html
diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py
index 9edb89286..c455c751f 100644
--- a/bookwyrm/models/__init__.py
+++ b/bookwyrm/models/__init__.py
@@ -27,7 +27,7 @@ from .group import Group, GroupMember, GroupMemberInvitation
from .import_job import ImportJob, ImportItem
-from .move import MoveUser, MoveUserNotification
+from .move import MoveUser
from .site import SiteSettings, Theme, SiteInvite
from .site import PasswordReset, InviteRequest
diff --git a/bookwyrm/models/move.py b/bookwyrm/models/move.py
index ef7cad372..a5bf9d76d 100644
--- a/bookwyrm/models/move.py
+++ b/bookwyrm/models/move.py
@@ -6,6 +6,7 @@ from bookwyrm import activitypub
from .activitypub_mixin import ActivityMixin
from .base_model import BookWyrmModel
from . import fields
+from .notification import Notification
class Move(ActivityMixin, BookWyrmModel):
@@ -63,25 +64,9 @@ class MoveUser(Move):
for follower in self.user.followers.all():
if follower.local:
- MoveUserNotification.objects.create(user=follower, target=self.user)
+ Notification.notify(
+ follower, self.user, notification_type=Notification.MOVE
+ )
else:
raise PermissionDenied()
-
-
-class MoveUserNotification(models.Model):
- """notify followers that the user has moved"""
-
- created_date = models.DateTimeField(auto_now_add=True)
-
- user = models.ForeignKey(
- "User", on_delete=models.PROTECT, related_name="moved_user_notifications"
- ) # user we are notifying
-
- target = models.ForeignKey(
- "User", on_delete=models.PROTECT, related_name="moved_user_notification_target"
- ) # new account of user who moved
-
- def save(self, *args, **kwargs):
- """send notification"""
- super().save(*args, **kwargs)
diff --git a/bookwyrm/models/notification.py b/bookwyrm/models/notification.py
index 9026b23df..093c25c65 100644
--- a/bookwyrm/models/notification.py
+++ b/bookwyrm/models/notification.py
@@ -2,14 +2,7 @@
from django.db import models, transaction
from django.dispatch import receiver
from .base_model import BookWyrmModel
-from . import (
- Boost,
- Favorite,
- GroupMemberInvitation,
- ImportJob,
- LinkDomain,
- MoveUserNotification,
-)
+from . import Boost, Favorite, GroupMemberInvitation, ImportJob, LinkDomain
from . import ListItem, Report, Status, User, UserFollowRequest
@@ -336,12 +329,3 @@ def notify_user_on_follow(sender, instance, created, *args, **kwargs):
notification_type=Notification.FOLLOW,
read=False,
)
-
-
-@receiver(models.signals.post_save, sender=MoveUserNotification)
-# pylint: disable=unused-argument
-def notify_on_move(sender, instance, *args, **kwargs):
- """someone migrated their account"""
- Notification.notify(
- instance.user, instance.target, notification_type=Notification.MOVE
- )
diff --git a/bookwyrm/templates/feed/layout.html b/bookwyrm/templates/feed/layout.html
index 3a17e3e0b..1a2fb33c6 100644
--- a/bookwyrm/templates/feed/layout.html
+++ b/bookwyrm/templates/feed/layout.html
@@ -5,22 +5,6 @@
{% block title %}{% trans "Updates" %}{% endblock %}
{% block content %}
-{% if user.moved_to %}
-
-
-
- {% trans "You have have moved to" %}
- {% id_to_username user.moved_to %}
-
-
{% trans "You can undo this move to restore full functionality, but some followers may have already unfollowed this account." %}
-
-
-
-{% else %}
{% if user.is_authenticated %}
@@ -44,7 +28,6 @@
{% endif %}
-{% endif %}
{% endblock %}
diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html
index e6f8a6f84..9b726d4ca 100644
--- a/bookwyrm/templates/layout.html
+++ b/bookwyrm/templates/layout.html
@@ -30,10 +30,11 @@
+ {% if not request.user.moved_to %}
- {{ user.username }} {% trans "will be marked as moved and will not be discoverable or usable unless you undo the move." %}
+ {% blocktrans %}
+ {{ user }} will be marked as moved and will not be discoverable or usable unless you undo the move.
+ {% endblocktrans %}