Content warning name customisation

Allows the name of Content Warning to be customized (e.g. to "Content Summary").

Fixes #28.
pull/38/head
Michael Manfre 2022-11-22 21:52:40 -05:00 zatwierdzone przez GitHub
rodzic db0edcd2ae
commit cdfff32f9a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 71 dodań i 5 usunięć

1
.gitignore vendored
Wyświetl plik

@ -4,6 +4,7 @@
*.pyc
*.sqlite3
.venv
.vscode
/*.env
/build
/docs/_build

Wyświetl plik

@ -135,9 +135,10 @@ class Compose(FormView):
)
content_warning = forms.CharField(
required=False,
label=Config.lazy_system_value("content_warning_text"),
widget=forms.TextInput(
attrs={
"placeholder": "Content Warning",
"placeholder": Config.lazy_system_value("content_warning_text"),
},
),
help_text="Optional - Post will be hidden behind this text until clicked",

Wyświetl plik

@ -5,6 +5,7 @@ from django.utils.decorators import method_decorator
from django.views.generic import FormView, ListView
from activities.models import Post, PostInteraction, TimelineEvent
from core.models import Config
from users.decorators import identity_required
@ -23,10 +24,11 @@ class Home(FormView):
)
content_warning = forms.CharField(
required=False,
label=Config.lazy_system_value("content_warning_text"),
widget=forms.TextInput(
attrs={
"placeholder": "Content Warning",
"class": "hidden",
"placeholder": Config.lazy_system_value("content_warning_text"),
},
),
)

Wyświetl plik

@ -5,6 +5,7 @@ import pydantic
from django.core.files import File
from django.db import models
from django.templatetags.static import static
from django.utils.functional import lazy
from core.uploads import upload_namer
from takahe import __version__
@ -55,6 +56,15 @@ class Config(models.Model):
system: ClassVar["Config.ConfigOptions"] # type: ignore
@classmethod
def lazy_system_value(cls, key: str):
"""
Lazily load a System.Config value
"""
if key not in cls.SystemOptions.__fields__:
raise KeyError(f"Undefined SystemOption for {key}")
return lazy(lambda: getattr(Config.system, key))
@classmethod
def load_values(cls, options_class, filters):
"""
@ -166,6 +176,7 @@ class Config(models.Model):
signup_allowed: bool = True
signup_invite_only: bool = False
signup_text: str = ""
content_warning_text: str = "Content Warning"
post_length: int = 500
identity_min_length: int = 2

Wyświetl plik

@ -0,0 +1,24 @@
import re
import mock
import pytest
from activities.views.posts import Compose
@pytest.mark.django_db
def test_content_warning_text(identity, user, rf, config_system):
request = rf.get("/compose/")
request.user = user
request.identity = identity
config_system.content_warning_text = "Content Summary"
with mock.patch("core.models.Config.load_system", return_value=config_system):
view = Compose.as_view()
resp = view(request)
assert resp.status_code == 200
content = str(resp.rendered_content)
assert 'placeholder="Content Summary"' in content
assert re.search(
r"<label.*>\s*Content Summary\s*</label>", content, flags=re.MULTILINE
)

Wyświetl plik

@ -0,0 +1,18 @@
import mock
import pytest
from activities.views.timelines import Home
@pytest.mark.django_db
def test_content_warning_text(identity, user, rf, config_system):
request = rf.get("/")
request.user = user
request.identity = identity
config_system.content_warning_text = "Content Summary"
with mock.patch("core.models.Config.load_system", return_value=config_system):
view = Home.as_view()
resp = view(request)
assert resp.status_code == 200
assert 'placeholder="Content Summary"' in str(resp.rendered_content)

Wyświetl plik

@ -62,11 +62,16 @@ def config_system(keypair):
@pytest.fixture
@pytest.mark.django_db
def identity():
def user() -> User:
return User.objects.create(email="test@example.com")
@pytest.fixture
@pytest.mark.django_db
def identity(user):
"""
Creates a basic test identity with a user and domain.
"""
user = User.objects.create(email="test@example.com")
domain = Domain.objects.create(domain="example.com", local=True, public=True)
identity = Identity.objects.create(
actor_uri="https://example.com/test-actor/",

Wyświetl plik

@ -37,6 +37,10 @@ class BasicSettings(AdminSettingsPage):
"title": "Maximum Post Length",
"help_text": "The maximum number of characters allowed per post",
},
"content_warning_text": {
"title": "Content Warning Feature Name",
"help_text": "What the feature that lets users provide post summaries is called",
},
"site_about": {
"title": "About This Site",
"help_text": "Displayed on the homepage and the about page.\nNewlines are preserved; HTML also allowed.",
@ -87,7 +91,7 @@ class BasicSettings(AdminSettingsPage):
"highlight_color",
],
"Signups": ["signup_allowed", "signup_invite_only", "signup_text"],
"Posts": ["post_length"],
"Posts": ["post_length", "content_warning_text"],
"Identities": [
"identity_max_per_user",
"identity_min_length",