List of pending follow requests with accept/delete buttons on own profile.

This commit is contained in:
Adam Kelly 2020-03-13 14:34:40 +00:00
parent 1693473fd2
commit 05f5315b98
3 changed files with 57 additions and 0 deletions

View file

@ -20,6 +20,27 @@
</div>
{% endif %}
</div>
{% if is_self and user.follower_requests.all %}
<div>
<h2>Follow Requests</h2>
{% for requester in user.follower_requests.all %}
<div>
{% include 'snippets/username.html' with user=requester show_full=True %}
<form action="/accept_follow_request/" method="POST">
{% csrf_token %}
<input type=hidden name="user" value="{{ requester.username }}">
<input type=submit value="Accept">
</form>
<form action="/delete_follow_request/" method="POST">
{% csrf_token %}
<input type=hidden name="user" value="{{ requester.username }}">
<input type=submit value="Delete">
</form>
</div>
{% endfor %}
</div>
{% endif %}
<div>
<h2>Followers</h2>
{% for follower in user.followers.all %}

View file

@ -62,4 +62,8 @@ urlpatterns = [
re_path(r'^edit_profile/?$', actions.edit_profile),
re_path(r'^clear-notifications/?$', actions.clear_notifications),
re_path(r'^accept_follow_request/?$', actions.accept_follow_request),
re_path(r'^delete_follow_request/?$', actions.delete_follow_request),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View file

@ -163,3 +163,35 @@ def clear_notifications(request):
request.user.notification_set.filter(read=True).delete()
return redirect('/notifications')
@login_required
def accept_follow_request(request):
username = request.POST['user']
try:
requester = get_user_from_username(username)
except models.User.DoesNotExist:
return HttpResponseBadRequest()
follow_request = models.UserFollowRequest.objects.get(user_subject=requester, user_object=request.user)
# We don't keep a full copy of the follow request, but a minimal copy is good enough for now.
follow_activity = {'id': follow_request.relationship_id}
outgoing.handle_outgoing_accept(requester, request.user, follow_activity)
user_slug = requester.localname if requester.localname \
else requester.username
return redirect('/user/%s' % user_slug)
@login_required
def delete_follow_request(request):
username = request.POST['user']
try:
requester = get_user_from_username(username)
except models.User.DoesNotExist:
return HttpResponseBadRequest()
try:
follow_request = models.UserFollowRequest.objects.get(user_subject=requester, user_object=request.user)
follow_request.delete()
# Generate a Reject activity here.
except models.UserFollowRequest.DoesNotExist:
pass
return redirect('/user/%s' % request.user.localname)