Skip to content

Commit

Permalink
Merge branch 'main' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Jul 9, 2022
2 parents f09fdc8 + 27e9ece commit 7382f23
Show file tree
Hide file tree
Showing 64 changed files with 4,131 additions and 1,735 deletions.
2 changes: 1 addition & 1 deletion bookwyrm/models/base_model.py
Expand Up @@ -132,7 +132,7 @@ def raise_not_deletable(self, viewer):
return

# but generally moderators can delete other people's stuff
if self.user == viewer or viewer.has_perm("moderate_post"):
if self.user == viewer or viewer.has_perm("bookwyrm.moderate_post"):
return

raise PermissionDenied()
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/models/link.py
Expand Up @@ -84,7 +84,7 @@ class LinkDomain(BookWyrmModel):
)

def raise_not_editable(self, viewer):
if viewer.has_perm("moderate_post"):
if viewer.has_perm("bookwyrm.moderate_post"):
return
raise PermissionDenied()

Expand Down
10 changes: 8 additions & 2 deletions bookwyrm/models/notification.py
Expand Up @@ -71,7 +71,9 @@ def notify(cls, user, related_user, **kwargs):
"""Create a notification"""
if related_user and (not user.local or user == related_user):
return
notification, _ = cls.objects.get_or_create(user=user, **kwargs)
notification = cls.objects.filter(user=user, **kwargs).first()
if not notification:
notification = cls.objects.create(user=user, **kwargs)
if related_user:
notification.related_users.add(related_user)
notification.read = False
Expand Down Expand Up @@ -222,8 +224,12 @@ def notify_user_on_import_complete(
@receiver(models.signals.post_save, sender=Report)
@transaction.atomic
# pylint: disable=unused-argument
def notify_admins_on_report(sender, instance, *args, **kwargs):
def notify_admins_on_report(sender, instance, created, *args, **kwargs):
"""something is up, make sure the admins know"""
if not created:
# otherwise you'll get a notification when you resolve a report
return

# moderators and superusers should be notified
admins = User.objects.filter(
models.Q(user_permissions__name__in=["moderate_user", "moderate_post"])
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/templates/feed/direct_messages.html
Expand Up @@ -14,7 +14,7 @@ <h1 class="title">
</header>

<div class="box">
{% include 'snippets/create_status/status.html' with type="direct" uuid=1 mention=partner no_script=True %}
{% include 'snippets/create_status/status.html' with type="direct" uuid=1 mention=partner %}
</div>

<section class="block">
Expand Down
67 changes: 23 additions & 44 deletions bookwyrm/templates/settings/dashboard/dashboard.html
Expand Up @@ -38,60 +38,39 @@ <h3>{% trans "Works" %}</h3>

<div class="columns block is-multiline">
{% if email_config_error %}
<div class="column is-flex">
<span class="notification is-warning is-block is-flex-grow-1">
{% blocktrans trimmed %}
Your outgoing email address, <code>{{ email_sender }}</code>, may be misconfigured.
{% endblocktrans %}
{% trans "Check the <code>EMAIL_SENDER_NAME</code> and <code>EMAIL_SENDER_DOMAIN</code> in your <code>.env</code>." %}
</span>
{% include 'settings/dashboard/warnings/email_config.html' with warning_level="danger" fullwidth=True %}
{% endif %}

{% if current_version %}
{% include 'settings/dashboard/warnings/update_version.html' with warning_level="warning" fullwidth=True %}
{% endif %}

{% if missing_privacy or missing_conduct %}
<div class="column is-12 columns m-0 p-0">
{% if missing_privacy %}
{% include 'settings/dashboard/warnings/missing_privacy.html' with warning_level="danger" %}
{% endif %}

{% if missing_conduct %}
{% include 'settings/dashboard/warnings/missing_conduct.html' with warning_level="warning" %}
{% endif %}
</div>
{% endif %}

{% if current_version %}
{% include 'settings/dashboard/warnings/update_version.html' with warning_level="warning" fullwidth=True %}
{% endif %}

{% if reports %}
<div class="column is-flex">
<a href="{% url 'settings-reports' %}" class="notification is-warning is-block is-flex-grow-1">
{% blocktrans trimmed count counter=reports with display_count=reports|intcomma %}
{{ display_count }} open report
{% plural %}
{{ display_count }} open reports
{% endblocktrans %}
</a>
</div>
{% include 'settings/dashboard/warnings/reports.html' with warning_level="warning" %}
{% endif %}

{% if pending_domains %}
<div class="column is-flex">
<a href="{% url 'settings-link-domain' %}" class="notification is-primary is-block is-flex-grow-1">
{% blocktrans trimmed count counter=pending_domains with display_count=pending_domains|intcomma %}
{{ display_count }} domain needs review
{% plural %}
{{ display_count }} domains need review
{% endblocktrans %}
</a>
</div>
{% include 'settings/dashboard/warnings/domain_review.html' with warning_level="primary" %}
{% endif %}

{% if not site.allow_registration and site.allow_invite_requests and invite_requests %}
<div class="column is-flex">
<a href="{% url 'settings-invite-requests' %}" class="notification is-block is-success is-flex-grow-1">
{% blocktrans trimmed count counter=invite_requests with display_count=invite_requests|intcomma %}
{{ display_count }} invite request
{% plural %}
{{ display_count }} invite requests
{% endblocktrans %}
</a>
</div>
{% endif %}

{% if current_version %}
<div class="column is-flex">
<a href="https://docs.joinbookwyrm.com/updating-your-instance.html" class="notification is-block is-warning is-flex-grow-1" target="_blank">
{% blocktrans trimmed with current=current_version available=available_version %}
An update is available! You're running v{{ current }} and the latest release is {{ available }}.
{% endblocktrans %}
</a>
</div>
{% include 'settings/dashboard/warnings/invites.html' with warning_level="success" %}
{% endif %}
</div>

Expand Down
15 changes: 15 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/domain_review.html
@@ -0,0 +1,15 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}
{% load humanize %}

{% block warning_link %}{% url 'settings-link-domain' %}{% endblock %}

{% block warning_text %}

{% blocktrans trimmed count counter=pending_domains with display_count=pending_domains|intcomma %}
{{ display_count }} domain needs review
{% plural %}
{{ display_count }} domains need review
{% endblocktrans %}

{% endblock %}
13 changes: 13 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/email_config.html
@@ -0,0 +1,13 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}

{% block warning_link %}https://docs.joinbookwyrm.com/install-prod.html{% endblock %}

{% block warning_text %}

{% blocktrans trimmed %}
Your outgoing email address, <code>{{ email_sender }}</code>, may be misconfigured.
{% endblocktrans %}
{% trans "Check the <code>EMAIL_SENDER_NAME</code> and <code>EMAIL_SENDER_DOMAIN</code> in your <code>.env</code> file." %}

{% endblock %}
15 changes: 15 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/invites.html
@@ -0,0 +1,15 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}
{% load humanize %}

{% block warning_link %}{% url 'settings-invite-requests' %}{% endblock %}

{% block warning_text %}

{% blocktrans trimmed count counter=invite_requests with display_count=invite_requests|intcomma %}
{{ display_count }} invite request
{% plural %}
{{ display_count }} invite requests
{% endblocktrans %}

{% endblock %}
5 changes: 5 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/layout.html
@@ -0,0 +1,5 @@
<div class="column is-flex{% if fullwidth %} is-12{% endif %}">
<a href="{% block warning_link %}{% endblock %}" class="notification is-{{ warning_level }} is-block is-flex-grow-1">
{% block warning_text %}{% endblock %}
</a>
</div>
@@ -0,0 +1,10 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}

{% block warning_link %}{% url 'settings-site' %}#instance-info{% endblock %}

{% block warning_text %}

{% trans "Your instance is missing a code of conduct." %}

{% endblock %}
@@ -0,0 +1,10 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}

{% block warning_link %}{% url 'settings-site' %}#instance-info{% endblock %}

{% block warning_text %}

{% trans "Your instance is missing a privacy policy." %}

{% endblock %}
15 changes: 15 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/reports.html
@@ -0,0 +1,15 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}
{% load humanize %}

{% block warning_link %}{% url 'settings-reports' %}{% endblock %}

{% block warning_text %}

{% blocktrans trimmed count counter=reports with display_count=reports|intcomma %}
{{ display_count }} open report
{% plural %}
{{ display_count }} open reports
{% endblocktrans %}

{% endblock %}
12 changes: 12 additions & 0 deletions bookwyrm/templates/settings/dashboard/warnings/update_version.html
@@ -0,0 +1,12 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}

{% block warning_link %}https://docs.joinbookwyrm.com/updating.html{% endblock %}

{% block warning_text %}

{% blocktrans trimmed with current=current_version available=available_version %}
An update is available! You're running v{{ current }} and the latest release is {{ available }}.
{% endblocktrans %}

{% endblock %}
2 changes: 1 addition & 1 deletion bookwyrm/templates/settings/federation/instance.html
Expand Up @@ -56,7 +56,7 @@ <h2 class="title is-4">{% trans "Activity" %}</h2>
<dt class="is-pulled-left mr-5">{% trans "Users:" %}</dt>
<dd>
{{ users.count }}
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
{% if server.user_set.count %}(<a href="{% url 'settings-users' status="federated" %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
</dd>

<dt class="is-pulled-left mr-5">{% trans "Reports:" %}</dt>
Expand Down
15 changes: 11 additions & 4 deletions bookwyrm/templates/settings/users/user_admin.html
Expand Up @@ -24,6 +24,10 @@
<li {% if request.path in url %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Local users" %}</a>
</li>
{% url 'settings-users' status="deleted" as url %}
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Deleted users" %}</a>
</li>
{% url 'settings-users' status="federated" as url %}
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Federated community" %}</a>
Expand All @@ -36,7 +40,7 @@
<table class="table is-striped is-fullwidth">
<tr>
{% url 'settings-users' as url %}
<th>
<th colspan="2">
{% trans "Username" as text %}
{% include 'snippets/table-sort-header.html' with field="username" sort=sort text=text %}
</th>
Expand All @@ -52,7 +56,7 @@
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="is_active" sort=sort text=text %}
</th>
{% if status != "local" %}
{% if status == "federated" %}
<th>
{% trans "Remote instance" as text %}
{% include 'snippets/table-sort-header.html' with field="federated_server__server_name" sort=sort text=text %}
Expand All @@ -61,7 +65,10 @@
</tr>
{% for user in users %}
<tr>
<td class="overflow-wrap-anywhere">
<td class="pr-0">
{% include 'snippets/avatar.html' with user=user %}
</td>
<td class="overflow-wrap-anywhere pl-1">
<a href="{% url 'settings-user' user.id %}">{{ user|username }}</a>
</td>
<td>{{ user.created_date }}</td>
Expand All @@ -86,7 +93,7 @@
<span class="help">({{ user.get_deactivation_reason_display }})</span>
{% endif %}
</td>
{% if status != "local" %}
{% if status == "federated" %}
<td>
{% if user.federated_server %}
<a href="{% url 'settings-federated-server' user.federated_server.id %}">{{ user.federated_server.server_name }}</a>
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/templates/setup/config.html
Expand Up @@ -144,7 +144,7 @@ <h2 class="title is-4">{% trans "Does everything look right?" %}</h2>
{% blocktrans trimmed %}
You can change your instance settings in the <code>.env</code> file on your server.
{% endblocktrans %}
<a href="https://docs.joinbookwyrm.com/installing-in-production.html" target="_blank">
<a href="https://docs.joinbookwyrm.com/install-prod.html" target="_blank">
{% trans "View installation instructions" %}
</a>
</p>
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/templates/snippets/follow_button.html
Expand Up @@ -26,7 +26,7 @@
<form action="{% url 'unfollow' %}" method="POST" class="interaction follow_{{ user.id }} {% if not relationship.is_following and not relationship.is_follow_pending %}is-hidden{%endif %}" data-id="follow_{{ user.id }}">
{% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}">
{% if user.manually_approves_followers and not relationship.is_following %}
{% if relationship.is_follow_pending %}
<button class="button is-small is-danger is-light" type="submit">
{% trans "Undo follow request" %}
</button>
Expand Down
4 changes: 2 additions & 2 deletions bookwyrm/templatetags/interaction.py
Expand Up @@ -42,11 +42,11 @@ def get_relationship(context, user_object):
"""caches the relationship between the logged in user and another user"""
user = context["request"].user
return get_or_set(
f"cached-relationship-{user.id}-{user_object.id}",
f"relationship-{user.id}-{user_object.id}",
get_relationship_name,
user,
user_object,
timeout=259200,
timeout=60 * 60,
)


Expand Down
11 changes: 11 additions & 0 deletions bookwyrm/tests/models/test_notification.py
Expand Up @@ -76,6 +76,17 @@ def test_notify_grouping(self):
notification.refresh_from_db()
self.assertEqual(notification.related_users.count(), 2)

def test_notify_grouping_with_dupes(self):
"""If there are multiple options to group with, don't cause an error"""
models.Notification.objects.create(
user=self.local_user, notification_type="FAVORITE"
)
models.Notification.objects.create(
user=self.local_user, notification_type="FAVORITE"
)
models.Notification.notify(self.local_user, None, notification_type="FAVORITE")
self.assertEqual(models.Notification.objects.count(), 2)

def test_notify_remote(self):
"""Don't create notifications for remote users"""
models.Notification.notify(
Expand Down

0 comments on commit 7382f23

Please sign in to comment.