Merge pull request #89 from cthulahoops/no_self_follow

No self follow
This commit is contained in:
Mouse Reeve 2020-03-14 19:38:36 -07:00 committed by GitHub
commit 67e7eaaf85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View file

@ -128,14 +128,15 @@ def handle_incoming_follow(activity):
to_follow = models.User.objects.get(actor=activity['object'])
# figure out who they are
user = get_or_create_remote_user(activity['actor'])
# TODO: allow users to manually approve requests
try:
request = models.UserFollowRequest.objects.create(
user_subject=user,
user_object=to_follow,
relationship_id=activity['id']
)
except django.db.utils.IntegrityError:
except django.db.utils.IntegrityError as err:
if err.__cause__.diag.constraint_name != 'userfollowrequest_unique':
raise
# Duplicate follow request. Not sure what the correct behaviour is, but
# just dropping it works for now. We should perhaps generate the
# Accept, but then do we need to match the activity id?

View file

@ -0,0 +1,26 @@
# Generated by Django 3.0.3 on 2020-03-14 21:52
from django.db import migrations, models
import django.db.models.expressions
class Migration(migrations.Migration):
dependencies = [
('fedireads', '0016_auto_20200313_1337'),
]
operations = [
migrations.AddConstraint(
model_name='userblocks',
constraint=models.CheckConstraint(check=models.Q(_negated=True, user_subject=django.db.models.expressions.F('user_object')), name='userblocks_no_self'),
),
migrations.AddConstraint(
model_name='userfollowrequest',
constraint=models.CheckConstraint(check=models.Q(_negated=True, user_subject=django.db.models.expressions.F('user_object')), name='userfollowrequest_no_self'),
),
migrations.AddConstraint(
model_name='userfollows',
constraint=models.CheckConstraint(check=models.Q(_negated=True, user_subject=django.db.models.expressions.F('user_object')), name='userfollows_no_self'),
),
]

View file

@ -95,6 +95,10 @@ class UserRelationship(FedireadsModel):
models.UniqueConstraint(
fields=['user_subject', 'user_object'],
name='%(class)s_unique'
),
models.CheckConstraint(
check=~models.Q(user_subject=models.F('user_object')),
name='%(class)s_no_self'
)
]

View file

@ -1,4 +1,5 @@
{% if request.user in user.follower_requests.all %}
{% if request.user == user %}
{% elif request.user in user.follower_requests.all %}
<div>
Follow request already sent.
</div>