ui path to iniate blocks

This commit is contained in:
Mouse Reeve 2021-01-25 14:03:18 -08:00
parent d994d8d3c8
commit ac2ab2981f
6 changed files with 69 additions and 16 deletions

View file

@ -0,0 +1,11 @@
{% if not user in request.user.blocks.all %}
<form name="blocks" method="post" action="/block/{{ user.id }}">
{% csrf_token %}
<button class="button is-danger is-light is-small is-fullwidth" type="submit">Block</button>
</form>
{% else %}
<form name="unblocks" method="post" action="/unblock/{{ user.id }}">
{% csrf_token %}
<button class="button is-small is-fullwidth" type="submit">Un-block</button>
</form>
{% endif %}

View file

@ -17,14 +17,9 @@
</button>
</form>
</li>
<li><hr class="navbar-divider"></li>
{% endif %}
{% else %}
<li role="menuitem">
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="/delete-status/{{ status.id }}" method="post">
{% csrf_token %}
<button class="button is-danger is-light is-fullwidth is-small" type="submit">
Block @{{ status.user|username }}
</button>
</form>
{% include 'snippets/block_button.html' with user=status.user %}
</li>
{% endif %}
{% endblock %}

View file

@ -35,11 +35,14 @@
</div>
</div>
{% if not is_self %}
{% include 'snippets/follow_button.html' with user=user %}
<form name="blocks" method="post" action="/block/{{ user.id }}">
{% csrf_token %}
<button type="submit">Block</button>
</form>
<div class="field has-addons">
<div class="control">
{% include 'snippets/follow_button.html' with user=user %}
</div>
<div class="control">
{% include 'snippets/user_options.html' with user=user class="is-small" %}
</div>
</div>
{% endif %}
{% if is_self and user.follower_requests.all %}

View file

@ -0,0 +1,14 @@
{% extends 'snippets/components/dropdown.html' %}
{% load bookwyrm_tags %}
{% block dropdown-trigger %}
<span class="icon icon-dots-three">
<span class="is-sr-only">More options</span>
</span>
{% endblock %}
{% block dropdown-list %}
<li role="menuitem">
{% include 'snippets/block_button.html' with user=user %}
</li>
{% endblock %}

29
bookwyrm/views/block.py Normal file
View file

@ -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')

View file

@ -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: