From ac2ab2981f15955d8d3a2d07a5e33ef6eb25d01c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 25 Jan 2021 14:03:18 -0800 Subject: [PATCH] ui path to iniate blocks --- bookwyrm/templates/snippets/block_button.html | 11 +++++++ .../templates/snippets/status_options.html | 11 ++----- bookwyrm/templates/snippets/user_header.html | 13 +++++---- bookwyrm/templates/snippets/user_options.html | 14 +++++++++ bookwyrm/views/block.py | 29 +++++++++++++++++++ bookwyrm/views/helpers.py | 7 +++-- 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 bookwyrm/templates/snippets/block_button.html create mode 100644 bookwyrm/templates/snippets/user_options.html create mode 100644 bookwyrm/views/block.py diff --git a/bookwyrm/templates/snippets/block_button.html b/bookwyrm/templates/snippets/block_button.html new file mode 100644 index 00000000..ed9bb551 --- /dev/null +++ b/bookwyrm/templates/snippets/block_button.html @@ -0,0 +1,11 @@ +{% if not user in request.user.blocks.all %} +
+ {% csrf_token %} + +
+{% else %} +
+ {% csrf_token %} + +
+{% endif %} diff --git a/bookwyrm/templates/snippets/status_options.html b/bookwyrm/templates/snippets/status_options.html index 9b312c7c..2e2e5d35 100644 --- a/bookwyrm/templates/snippets/status_options.html +++ b/bookwyrm/templates/snippets/status_options.html @@ -17,14 +17,9 @@ -
  • -{% endif %} +{% else %}
  • - + {% include 'snippets/block_button.html' with user=status.user %}
  • +{% endif %} {% endblock %} diff --git a/bookwyrm/templates/snippets/user_header.html b/bookwyrm/templates/snippets/user_header.html index 14216d4b..8f5e264a 100644 --- a/bookwyrm/templates/snippets/user_header.html +++ b/bookwyrm/templates/snippets/user_header.html @@ -35,11 +35,14 @@ {% if not is_self %} - {% include 'snippets/follow_button.html' with user=user %} -
    - {% csrf_token %} - -
    +
    +
    + {% include 'snippets/follow_button.html' with user=user %} +
    +
    + {% include 'snippets/user_options.html' with user=user class="is-small" %} +
    +
    {% endif %} {% if is_self and user.follower_requests.all %} diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html new file mode 100644 index 00000000..9515d912 --- /dev/null +++ b/bookwyrm/templates/snippets/user_options.html @@ -0,0 +1,14 @@ +{% extends 'snippets/components/dropdown.html' %} +{% load bookwyrm_tags %} + +{% block dropdown-trigger %} + + More options + +{% endblock %} + +{% block dropdown-list %} +
  • + {% include 'snippets/block_button.html' with user=user %} +
  • +{% endblock %} diff --git a/bookwyrm/views/block.py b/bookwyrm/views/block.py new file mode 100644 index 00000000..36f64f73 --- /dev/null +++ b/bookwyrm/views/block.py @@ -0,0 +1,29 @@ +''' views for actions you can take in the application ''' +from django.contrib.auth.decorators import login_required +from django.shortcuts import get_object_or_404, redirect +from django.utils.decorators import method_decorator +from django.views import View + +from bookwyrm import models +from bookwyrm.broadcast import broadcast + +# pylint: disable= no-self-use +@method_decorator(login_required, name='dispatch') +class Block(View): + ''' blocking users ''' + def get(self, request): + ''' list of blocked users? ''' + + def post(self, request, user_id): + ''' block a user ''' + to_block = get_object_or_404(models.User, id=user_id) + block = models.UserBlocks.objects.create( + user_subject=request.user, user_object=to_block) + if not to_block.local: + broadcast( + request.user, + block.to_activity(), + privacy='direct', + direct_recipients=[to_block] + ) + return redirect('/blocks') diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index b0f867b7..5872b2de 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -72,9 +72,10 @@ def get_activity_feed( queryset = queryset.exclude(deleted=True).order_by('-published_date') # exclude blocks from both directions - blocked = models.User.objects.filter(id__in=user.blocks.all()).all() - queryset = queryset.exclude( - Q(user__in=blocked) | Q(user__blocks=user)) + if not user.is_anonymous: + blocked = models.User.objects.filter(id__in=user.blocks.all()).all() + queryset = queryset.exclude( + Q(user__in=blocked) | Q(user__blocks=user)) # you can't see followers only or direct messages if you're not logged in if user.is_anonymous: