ui path to iniate blocks
This commit is contained in:
29
bookwyrm/views/block.py
Normal file
29
bookwyrm/views/block.py
Normal 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')
|
@ -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:
|
||||
|
Reference in New Issue
Block a user