From d2fda1e9748040234f472081bddced297d480648 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Sun, 11 Oct 2020 15:46:06 +0100 Subject: [PATCH] Only local accounts can receive Notifications. Closes issue #43. As part of this, remove the previously undiscovered ability to send Accepts for remote users! --- .../migrations/0025_auto_20201011_1439.py | 19 +++++++++++++++++++ kepi/trilby_api/models/notification.py | 2 +- kepi/trilby_api/receivers.py | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 kepi/trilby_api/migrations/0025_auto_20201011_1439.py diff --git a/kepi/trilby_api/migrations/0025_auto_20201011_1439.py b/kepi/trilby_api/migrations/0025_auto_20201011_1439.py new file mode 100644 index 0000000..50eeec5 --- /dev/null +++ b/kepi/trilby_api/migrations/0025_auto_20201011_1439.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.9 on 2020-10-11 14:39 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('trilby_api', '0024_localperson_featured'), + ] + + operations = [ + migrations.AlterField( + model_name='notification', + name='for_account', + field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='notifications_for', to='trilby_api.LocalPerson'), + ), + ] diff --git a/kepi/trilby_api/models/notification.py b/kepi/trilby_api/models/notification.py index a501d0d..9cdde36 100644 --- a/kepi/trilby_api/models/notification.py +++ b/kepi/trilby_api/models/notification.py @@ -40,7 +40,7 @@ class Notification(models.Model): ) for_account = models.ForeignKey( - 'Person', + 'LocalPerson', on_delete = models.DO_NOTHING, related_name = 'notifications_for', ) diff --git a/kepi/trilby_api/receivers.py b/kepi/trilby_api/receivers.py index 5845f84..7b1d9db 100644 --- a/kepi/trilby_api/receivers.py +++ b/kepi/trilby_api/receivers.py @@ -22,6 +22,10 @@ def on_follow(sender, **kwargs): follow = sender # rename to prevent confusion below + if not follow.following.is_local: + # we're only concerned with local accounts + return + notification = kepi_models.Notification( notification_type = kepi_models.Notification.FOLLOW, for_account = follow.following, @@ -62,6 +66,10 @@ def on_like(sender, **kwargs): like = sender # rename to prevent confusion below + if not like.liked.account.is_local: + # we're only concerned with local accounts + return + notification = kepi_models.Notification( notification_type = kepi_models.Notification.FAVOURITE, for_account = like.liked.account,