diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 05e7d8a05..aa4b5b687 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -396,7 +396,7 @@ def resolve_remote_id( def get_representative(): """Get or create an actor representing the instance - to sign requests to 'secure mastodon' servers""" + to sign outgoing HTTP GET requests""" username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}" email = "bookwyrm@localhost" try: diff --git a/bookwyrm/migrations/0187_partial_publication_dates.py b/bookwyrm/migrations/0187_partial_publication_dates.py new file mode 100644 index 000000000..10ef599a7 --- /dev/null +++ b/bookwyrm/migrations/0187_partial_publication_dates.py @@ -0,0 +1,54 @@ +# Generated by Django 3.2.20 on 2023-11-09 16:57 + +import bookwyrm.models.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0186_invite_request_notification"), + ] + + operations = [ + migrations.AddField( + model_name="book", + name="first_published_date_precision", + field=models.CharField( + blank=True, + choices=[ + ("DAY", "Day prec."), + ("MONTH", "Month prec."), + ("YEAR", "Year prec."), + ], + editable=False, + max_length=10, + null=True, + ), + ), + migrations.AddField( + model_name="book", + name="published_date_precision", + field=models.CharField( + blank=True, + choices=[ + ("DAY", "Day prec."), + ("MONTH", "Month prec."), + ("YEAR", "Year prec."), + ], + editable=False, + max_length=10, + null=True, + ), + ), + migrations.AlterField( + model_name="book", + name="first_published_date", + field=bookwyrm.models.fields.PartialDateField(blank=True, null=True), + ), + migrations.AlterField( + model_name="book", + name="published_date", + field=bookwyrm.models.fields.PartialDateField(blank=True, null=True), + ), + ] diff --git a/bookwyrm/migrations/0188_theme_loads.py b/bookwyrm/migrations/0188_theme_loads.py new file mode 100644 index 000000000..846aaf549 --- /dev/null +++ b/bookwyrm/migrations/0188_theme_loads.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2023-11-20 18:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0187_partial_publication_dates"), + ] + + operations = [ + migrations.AddField( + model_name="theme", + name="loads", + field=models.BooleanField(blank=True, null=True), + ), + ] diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index e5941136f..6893b9da1 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -135,8 +135,8 @@ class Book(BookDataModel): preview_image = models.ImageField( upload_to="previews/covers/", blank=True, null=True ) - first_published_date = fields.DateTimeField(blank=True, null=True) - published_date = fields.DateTimeField(blank=True, null=True) + first_published_date = fields.PartialDateField(blank=True, null=True) + published_date = fields.PartialDateField(blank=True, null=True) objects = InheritanceManager() field_tracker = FieldTracker(fields=["authors", "title", "subtitle", "cover"]) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 1e458c815..4bd580705 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -20,6 +20,11 @@ from markdown import markdown from bookwyrm import activitypub from bookwyrm.connectors import get_image from bookwyrm.utils.sanitizer import clean +from bookwyrm.utils.partial_date import ( + PartialDate, + PartialDateModel, + from_partial_isoformat, +) from bookwyrm.settings import MEDIA_FULL_URL @@ -539,7 +544,6 @@ class DateTimeField(ActivitypubFieldMixin, models.DateTimeField): def field_from_activity(self, value, allow_external_connections=True): missing_fields = datetime(1970, 1, 1) # "2022-10" => "2022-10-01" try: - # TODO(dato): investigate `ignoretz=True` wrt bookwyrm#3028. date_value = dateutil.parser.parse(value, default=missing_fields) try: return timezone.make_aware(date_value) @@ -549,6 +553,37 @@ class DateTimeField(ActivitypubFieldMixin, models.DateTimeField): return None +class PartialDateField(ActivitypubFieldMixin, PartialDateModel): + """activitypub-aware partial date field""" + + def field_to_activity(self, value) -> str: + return value.partial_isoformat() if value else None + + def field_from_activity(self, value, allow_external_connections=True): + # pylint: disable=no-else-return + try: + return from_partial_isoformat(value) + except ValueError: + pass + + # fallback to full ISO-8601 parsing + try: + parsed = dateutil.parser.isoparse(value) + except (ValueError, ParserError): + return None + + if timezone.is_aware(parsed): + return PartialDate.from_datetime(parsed) + else: + # Should not happen on the wire, but truncate down to date parts. + return PartialDate.from_date_parts(parsed.year, parsed.month, parsed.day) + + # FIXME: decide whether to fix timestamps like "2023-09-30T21:00:00-03": + # clearly Oct 1st, not Sep 30th (an unwanted side-effect of USE_TZ). It's + # basically the remnants of #3028; there is a data migration pending (see …) + # but over the wire we might get these for an indeterminate amount of time. + + class HtmlField(ActivitypubFieldMixin, models.TextField): """a text field for storing html""" diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index a27c4b70d..b962d597b 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -149,6 +149,7 @@ class Theme(SiteModel): created_date = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=50, unique=True) path = models.CharField(max_length=50, unique=True) + loads = models.BooleanField(null=True, blank=True) def __str__(self): # pylint: disable=invalid-str-returned diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index 3e9bef9c4..a13ee97fd 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -8,6 +8,7 @@ from opentelemetry import trace from bookwyrm import models from bookwyrm.redis_store import RedisStore, r +from bookwyrm.settings import INSTANCE_ACTOR_USERNAME from bookwyrm.tasks import app, SUGGESTED_USERS from bookwyrm.telemetry import open_telemetry @@ -98,9 +99,15 @@ class SuggestedUsers(RedisStore): for (pk, score) in values ] # annotate users with mutuals and shared book counts - users = models.User.objects.filter( - is_active=True, bookwyrm_user=True, id__in=[pk for (pk, _) in values] - ).annotate(mutuals=Case(*annotations, output_field=IntegerField(), default=0)) + users = ( + models.User.objects.filter( + is_active=True, bookwyrm_user=True, id__in=[pk for (pk, _) in values] + ) + .annotate( + mutuals=Case(*annotations, output_field=IntegerField(), default=0) + ) + .exclude(localname=INSTANCE_ACTOR_USERNAME) + ) if local: users = users.filter(local=True) return users.order_by("-mutuals")[:5] diff --git a/bookwyrm/templates/403.html b/bookwyrm/templates/403.html new file mode 100644 index 000000000..0b78bc6b8 --- /dev/null +++ b/bookwyrm/templates/403.html @@ -0,0 +1,20 @@ +{% extends 'layout.html' %} +{% load i18n %} +{% load utilities %} + +{% block title %}{% trans "Oh no!" %}{% endblock %} + +{% block content %} +
+ {% blocktrans trimmed with level=request.user|get_user_permission %}
+ You do not have permission to view this page or perform this action. Your user permission level is {{ level }}
.
+ {% endblocktrans %}
+
{% trans "If you think you should have access, please speak to your BookWyrm server administrator." %} +
+ +{% trans "View user profile" %}
+ {% endif %} + + {% url 'settings-user' user.id as url %} {% if not request.path == url %}{% trans "Go to user admin" %}
diff --git a/bookwyrm/templates/settings/users/user_moderation_actions.html b/bookwyrm/templates/settings/users/user_moderation_actions.html index 4a624a5e4..fd3e66aa8 100644 --- a/bookwyrm/templates/settings/users/user_moderation_actions.html +++ b/bookwyrm/templates/settings/users/user_moderation_actions.html @@ -1,4 +1,5 @@ {% load i18n %} +{% load utilities %}- {% trans "Send direct message" %} -
- {% endif %} + {% if user.localname|is_instance_admin %} ++ {% trans "Send direct message" %} +
+ {% endif %} - {% if not user.is_active and user.deactivation_reason == "pending" %} - - {% endif %} - {% if user.is_active or user.deactivation_reason == "pending" %} - - {% else %} - + {% if not user.is_active and user.deactivation_reason == "pending" %} + + {% endif %} + {% if user.is_active or user.deactivation_reason == "pending" %} + + {% else %} + + {% endif %} + + {% if user.local %} +