mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-18 22:26:34 +00:00
Merge branch 'main' into locale-improvements
This commit is contained in:
commit
fe00032da5
6 changed files with 87 additions and 7 deletions
|
@ -67,16 +67,15 @@ class BookWyrmModel(models.Model):
|
||||||
return
|
return
|
||||||
|
|
||||||
# you can see the followers only posts of people you follow
|
# you can see the followers only posts of people you follow
|
||||||
if (
|
if self.privacy == "followers" and (
|
||||||
self.privacy == "followers"
|
self.user.followers.filter(id=viewer.id).first()
|
||||||
and self.user.followers.filter(id=viewer.id).first()
|
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
# you can see dms you are tagged in
|
# you can see dms you are tagged in
|
||||||
if hasattr(self, "mention_users"):
|
if hasattr(self, "mention_users"):
|
||||||
if (
|
if (
|
||||||
self.privacy == "direct"
|
self.privacy in ["direct", "followers"]
|
||||||
and self.mention_users.filter(id=viewer.id).first()
|
and self.mention_users.filter(id=viewer.id).first()
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
|
@ -224,6 +224,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct"
|
~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def followers_filter(cls, queryset, viewer):
|
||||||
|
"""Override-able filter for "followers" privacy level"""
|
||||||
|
return queryset.exclude(
|
||||||
|
~Q( # not yourself, a follower, or someone who is tagged
|
||||||
|
Q(user__followers=viewer) | Q(user=viewer) | Q(mention_users=viewer)
|
||||||
|
),
|
||||||
|
privacy="followers", # and the status is followers only
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GeneratedNote(Status):
|
class GeneratedNote(Status):
|
||||||
"""these are app-generated messages about user activity"""
|
"""these are app-generated messages about user activity"""
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load utilities %}
|
{% load utilities %}
|
||||||
|
|
||||||
{% block title %}{% trans "Compose status" %}{% endblock %}
|
{% block title %}{% trans "Edit status" %}{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<header class="block content">
|
<header class="block content">
|
||||||
<h1>{% trans "Compose status" %}</h1>
|
<h1>{% trans "Edit status" %}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{% with 0|uuid as uuid %}
|
{% with 0|uuid as uuid %}
|
||||||
|
@ -22,6 +22,10 @@
|
||||||
<div class="column">
|
<div class="column">
|
||||||
{% if draft.reply_parent %}
|
{% if draft.reply_parent %}
|
||||||
{% include 'snippets/status/status.html' with status=draft.reply_parent no_interact=True %}
|
{% include 'snippets/status/status.html' with status=draft.reply_parent no_interact=True %}
|
||||||
|
{% else %}
|
||||||
|
<div class="block">
|
||||||
|
{% include "snippets/status/header.html" with status=draft %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not draft %}
|
{% if not draft %}
|
||||||
|
|
|
@ -15,6 +15,7 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j
|
||||||
{% trans "Some thoughts on the book" as placeholder %}
|
{% trans "Some thoughts on the book" as placeholder %}
|
||||||
|
|
||||||
{% block post_content_additions %}
|
{% block post_content_additions %}
|
||||||
|
{% if not draft.reading_status %}
|
||||||
{# Supplemental fields #}
|
{# Supplemental fields #}
|
||||||
<div>
|
<div>
|
||||||
{% active_shelf book as active_shelf %}
|
{% active_shelf book as active_shelf %}
|
||||||
|
@ -68,6 +69,7 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -33,6 +33,9 @@ reply_parent: the Status object this post will be in reply to, if applicable
|
||||||
<input type="hidden" name="book" value="{{ book.id }}">
|
<input type="hidden" name="book" value="{{ book.id }}">
|
||||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||||
<input type="hidden" name="reply_parent" value="{% firstof draft.reply_parent.id reply_parent.id %}">
|
<input type="hidden" name="reply_parent" value="{% firstof draft.reply_parent.id reply_parent.id %}">
|
||||||
|
{% if draft %}
|
||||||
|
<input type="hidden" name="reading_status" value="{{ draft.reading_status|default:'' }}">
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% include "snippets/create_status/content_warning_field.html" %}
|
{% include "snippets/create_status/content_warning_field.html" %}
|
||||||
|
|
|
@ -3,11 +3,13 @@ from unittest.mock import patch
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
from PIL import Image
|
from django.http import Http404
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from PIL import Image
|
||||||
import responses
|
import responses
|
||||||
|
|
||||||
from bookwyrm import activitypub, models, settings
|
from bookwyrm import activitypub, models, settings
|
||||||
|
@ -50,6 +52,9 @@ class Status(TestCase):
|
||||||
image.save(output, format=image.format)
|
image.save(output, format=image.format)
|
||||||
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||||
|
|
||||||
|
self.anonymous_user = AnonymousUser
|
||||||
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
||||||
def test_status_generated_fields(self, *_):
|
def test_status_generated_fields(self, *_):
|
||||||
"""setting remote id"""
|
"""setting remote id"""
|
||||||
status = models.Status.objects.create(content="bleh", user=self.local_user)
|
status = models.Status.objects.create(content="bleh", user=self.local_user)
|
||||||
|
@ -460,3 +465,60 @@ class Status(TestCase):
|
||||||
responses.add(responses.GET, "http://fish.com/nothing", status=404)
|
responses.add(responses.GET, "http://fish.com/nothing", status=404)
|
||||||
|
|
||||||
self.assertTrue(models.Status.ignore_activity(activity))
|
self.assertTrue(models.Status.ignore_activity(activity))
|
||||||
|
|
||||||
|
def test_raise_visible_to_user_public(self, *_):
|
||||||
|
"""privacy settings"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
content="bleh", user=self.local_user, privacy="public"
|
||||||
|
)
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.remote_user))
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.local_user))
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.anonymous_user))
|
||||||
|
|
||||||
|
def test_raise_visible_to_user_unlisted(self, *_):
|
||||||
|
"""privacy settings"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
content="bleh", user=self.local_user, privacy="unlisted"
|
||||||
|
)
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.remote_user))
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.local_user))
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.anonymous_user))
|
||||||
|
|
||||||
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
|
def test_raise_visible_to_user_followers(self, *_):
|
||||||
|
"""privacy settings"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
content="bleh", user=self.local_user, privacy="followers"
|
||||||
|
)
|
||||||
|
status.raise_visible_to_user(self.local_user)
|
||||||
|
with self.assertRaises(Http404):
|
||||||
|
status.raise_visible_to_user(self.remote_user)
|
||||||
|
with self.assertRaises(Http404):
|
||||||
|
status.raise_visible_to_user(self.anonymous_user)
|
||||||
|
|
||||||
|
self.local_user.followers.add(self.remote_user)
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.remote_user))
|
||||||
|
|
||||||
|
def test_raise_visible_to_user_followers_mentioned(self, *_):
|
||||||
|
"""privacy settings"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
content="bleh", user=self.local_user, privacy="followers"
|
||||||
|
)
|
||||||
|
status.mention_users.set([self.remote_user])
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.remote_user))
|
||||||
|
|
||||||
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
|
def test_raise_visible_to_user_direct(self, *_):
|
||||||
|
"""privacy settings"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
content="bleh", user=self.local_user, privacy="direct"
|
||||||
|
)
|
||||||
|
status.raise_visible_to_user(self.local_user)
|
||||||
|
with self.assertRaises(Http404):
|
||||||
|
status.raise_visible_to_user(self.remote_user)
|
||||||
|
with self.assertRaises(Http404):
|
||||||
|
status.raise_visible_to_user(self.anonymous_user)
|
||||||
|
|
||||||
|
# mentioned user
|
||||||
|
status.mention_users.set([self.remote_user])
|
||||||
|
self.assertIsNone(status.raise_visible_to_user(self.remote_user))
|
||||||
|
|
Loading…
Reference in a new issue