mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Updates and tests outgoing reject
This commit is contained in:
parent
a567bd4e61
commit
75c695b3c6
4 changed files with 28 additions and 6 deletions
|
@ -134,7 +134,9 @@ def handle_follow(activity):
|
|||
except django.db.utils.IntegrityError as err:
|
||||
if err.__cause__.diag.constraint_name != 'userfollowrequest_unique':
|
||||
raise
|
||||
relationship = models.UserFollowRequest.objects.get(remote_id=activity['id'])
|
||||
relationship = models.UserFollowRequest.objects.get(
|
||||
remote_id=activity['id']
|
||||
)
|
||||
# send the accept normally for a duplicate request
|
||||
|
||||
if not to_follow.manually_approves_followers:
|
||||
|
@ -194,7 +196,7 @@ def handle_follow_reject(activity):
|
|||
user_object=rejecter
|
||||
)
|
||||
request.delete()
|
||||
#raises models.UserFollowRequest.DoesNotExist:
|
||||
#raises models.UserFollowRequest.DoesNotExist
|
||||
|
||||
|
||||
@app.task
|
||||
|
|
|
@ -93,10 +93,12 @@ def handle_accept(follow_request):
|
|||
broadcast(to_follow, activity, privacy='direct', direct_recipients=[user])
|
||||
|
||||
|
||||
def handle_reject(user, to_follow, relationship):
|
||||
def handle_reject(follow_request):
|
||||
''' a local user who managed follows rejects a follow request '''
|
||||
activity = relationship.to_reject_activity(user)
|
||||
relationship.delete()
|
||||
user = follow_request.user_subject
|
||||
to_follow = follow_request.user_object
|
||||
activity = follow_request.to_reject_activity()
|
||||
follow_request.delete()
|
||||
broadcast(to_follow, activity, privacy='direct', direct_recipients=[user])
|
||||
|
||||
|
||||
|
|
|
@ -52,3 +52,21 @@ class Following(TestCase):
|
|||
)
|
||||
# follow relationship should exist
|
||||
self.assertEqual(self.remote_user.followers.first(), self.local_user)
|
||||
|
||||
|
||||
def test_handle_reject(self):
|
||||
rel = models.UserFollowRequest.objects.create(
|
||||
user_subject=self.local_user,
|
||||
user_object=self.remote_user
|
||||
)
|
||||
rel_id = rel.id
|
||||
|
||||
outgoing.handle_reject(rel)
|
||||
# request should be deleted
|
||||
self.assertEqual(
|
||||
models.UserFollowRequest.objects.filter(id=rel_id).count(), 0
|
||||
)
|
||||
# follow relationship should not exist
|
||||
self.assertEqual(
|
||||
models.UserFollows.objects.filter(id=rel_id).count(), 0
|
||||
)
|
||||
|
|
|
@ -495,7 +495,7 @@ def delete_follow_request(request):
|
|||
except models.UserFollowRequest.DoesNotExist:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
outgoing.handle_reject(requester, request.user, follow_request)
|
||||
outgoing.handle_reject(follow_request)
|
||||
return redirect('/user/%s' % request.user.localname)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue