mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Improves privacy-related display
This commit is contained in:
parent
dcd4baed82
commit
bcdf2ee142
6 changed files with 29 additions and 25 deletions
|
@ -22,11 +22,8 @@ def dict_key(d, k):
|
|||
@register.filter(name='rating')
|
||||
def get_rating(book, user):
|
||||
''' get the overall rating of a book '''
|
||||
queryset = views.helpers.get_activity_feed(
|
||||
user,
|
||||
['public', 'followers', 'unlisted', 'direct'],
|
||||
queryset=models.Review.objects.filter(book=book),
|
||||
)
|
||||
queryset = views.helpers.privacy_filter(
|
||||
user, models.Review.objects.filter(book=book))
|
||||
return queryset.aggregate(Avg('rating'))['rating__avg']
|
||||
|
||||
|
||||
|
|
|
@ -96,9 +96,8 @@ class Book(View):
|
|||
'rating': reviews.aggregate(Avg('rating'))['rating__avg'],
|
||||
'tags': models.UserTag.objects.filter(book=book),
|
||||
'lists': privacy_filter(
|
||||
request.user,
|
||||
book.list_set.all(),
|
||||
['public', 'unlisted', 'followers']),
|
||||
request.user, book.list_set.all()
|
||||
),
|
||||
'user_tags': user_tags,
|
||||
'user_shelves': user_shelves,
|
||||
'other_edition_shelves': other_edition_shelves,
|
||||
|
|
|
@ -28,15 +28,21 @@ class Feed(View):
|
|||
page = 1
|
||||
|
||||
if tab == 'home':
|
||||
activities = get_activity_feed(
|
||||
request.user, ['public', 'unlisted', 'followers'],
|
||||
following_only=True)
|
||||
activities = get_activity_feed(request.user, following_only=True)
|
||||
# we only want to show private messages if they're related to books
|
||||
activities = activities.exclude(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
privacy='direct'
|
||||
)
|
||||
elif tab == 'local':
|
||||
activities = get_activity_feed(
|
||||
request.user, ['public', 'followers'], local_only=True)
|
||||
request.user, privacy=['public', 'followers'], local_only=True)
|
||||
else:
|
||||
activities = get_activity_feed(
|
||||
request.user, ['public', 'followers'])
|
||||
request.user, privacy=['public', 'followers'])
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
|
||||
data = {**feed_page_data(request.user), **{
|
||||
|
@ -72,7 +78,7 @@ class DirectMessage(View):
|
|||
queryset = queryset.filter(Q(user=user) | Q(mention_users=user))
|
||||
|
||||
activities = get_activity_feed(
|
||||
request.user, 'direct', queryset=queryset)
|
||||
request.user, privacy=['direct'], queryset=queryset)
|
||||
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
activity_page = paginated.page(page)
|
||||
|
|
|
@ -59,8 +59,11 @@ def object_visible_to_user(viewer, obj):
|
|||
return False
|
||||
|
||||
|
||||
def privacy_filter(viewer, queryset, privacy_levels, following_only=False):
|
||||
def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
|
||||
''' filter objects that have "user" and "privacy" fields '''
|
||||
privacy_levels = privacy_levels or \
|
||||
['public', 'unlisted', 'followers', 'direct']
|
||||
|
||||
# exclude blocks from both directions
|
||||
if not viewer.is_anonymous:
|
||||
blocked = models.User.objects.filter(id__in=viewer.blocks.all()).all()
|
||||
|
@ -104,18 +107,16 @@ def privacy_filter(viewer, queryset, privacy_levels, following_only=False):
|
|||
|
||||
|
||||
def get_activity_feed(
|
||||
user, privacy, local_only=False, following_only=False,
|
||||
queryset=models.Status.objects):
|
||||
user, privacy=None, local_only=False, following_only=False,
|
||||
queryset=None):
|
||||
''' get a filtered queryset of statuses '''
|
||||
# if we're looking at Status, we need this. We don't if it's Comment
|
||||
if hasattr(queryset, 'select_subclasses'):
|
||||
queryset = queryset.select_subclasses()
|
||||
if not queryset:
|
||||
queryset = models.Status.objects.select_subclasses()
|
||||
|
||||
# exclude deleted
|
||||
queryset = queryset.exclude(deleted=True).order_by('-published_date')
|
||||
|
||||
# apply privacy filters
|
||||
privacy = privacy if isinstance(privacy, list) else [privacy]
|
||||
queryset = privacy_filter(
|
||||
user, queryset, privacy, following_only=following_only)
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ class Lists(View):
|
|||
).filter(
|
||||
item_count__gt=0
|
||||
).distinct().all()
|
||||
lists = privacy_filter(request.user, lists, ['public', 'followers'])
|
||||
lists = privacy_filter(
|
||||
request.user, lists, privacy_levels=['public', 'followers'])
|
||||
|
||||
paginated = Paginator(lists, 12)
|
||||
data = {
|
||||
|
@ -67,8 +68,7 @@ class UserLists(View):
|
|||
page = 1
|
||||
user = get_user_from_username(request.user, username)
|
||||
lists = models.List.objects.filter(user=user).all()
|
||||
lists = privacy_filter(
|
||||
request.user, lists, ['public', 'followers', 'unlisted'])
|
||||
lists = privacy_filter(request.user, lists)
|
||||
paginated = Paginator(lists, 12)
|
||||
|
||||
data = {
|
||||
|
|
|
@ -44,7 +44,8 @@ class Search(View):
|
|||
|
||||
# any relevent lists?
|
||||
list_results = privacy_filter(
|
||||
request.user, models.List.objects, ['public', 'followers']
|
||||
request.user, models.List.objects,
|
||||
privacy_levels=['public', 'followers']
|
||||
).annotate(
|
||||
similarity=Greatest(
|
||||
TrigramSimilarity('name', query),
|
||||
|
|
Loading…
Reference in a new issue