Merge pull request #2184 from bookwyrm-social/userless-link-domain

Handle link domains with no associated user
This commit is contained in:
Mouse Reeve 2022-07-05 17:51:12 -07:00 committed by GitHub
commit cccf0ec3a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 53 additions and 12 deletions

View file

@ -45,6 +45,7 @@ def moderation_report_email(report):
"""a report was created"""
data = email_data()
data["reporter"] = report.reporter.localname or report.reporter.username
if report.user:
data["reportee"] = report.user.localname or report.user.username
data["report_link"] = report.remote_id

View file

@ -11,7 +11,7 @@ class Report(BookWyrmModel):
"User", related_name="reporter", on_delete=models.PROTECT
)
note = models.TextField(null=True, blank=True)
user = models.ForeignKey("User", on_delete=models.PROTECT)
user = models.ForeignKey("User", on_delete=models.PROTECT, null=True, blank=True)
status = models.ForeignKey(
"Status",
null=True,

View file

@ -42,7 +42,11 @@
<a href="{{ link.url }}" target="_blank" rel="noopener noreferrer">{{ link.url }}</a>
</td>
<td>
{% if link.added_by %}
<a href="{% url 'user-feed' link.added_by.id %}">{{ link.added_by.display_name }}</a>
{% else %}
<em>{% trans "Unknown user" %}</em>
{% endif %}
</td>
<td>
{{ link.filelink.filetype }}
@ -50,7 +54,7 @@
<td>
{{ link.domain.name }}
<p>
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
<a href="{% url 'report-link' link.id %}">{% trans "Report spam" %}</a>
</p>
</td>
<td>

View file

@ -19,7 +19,7 @@ Is that where you'd like to go?
{% block modal-footer %}
{% if request.user.is_authenticated %}
<div class="is-flex-grow-1">
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
<a href="{% url 'report-link' link.id %}">{% trans "Report spam" %}</a>
</div>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>

View file

@ -3,7 +3,19 @@
{% block content %}
<p>
{% blocktrans %}@{{ reporter }} has flagged behavior by @{{ reportee }} for moderation. {% endblocktrans %}
{% if report_link %}
{% blocktrans trimmed %}
@{{ reporter }} has flagged a link domain for moderation.
{% endblocktrans %}
{% else %}
{% blocktrans trimmed %}
@{{ reporter }} has flagged behavior by @{{ reportee }} for moderation.
{% endblocktrans %}
{% endif %}
</p>
{% trans "View report" as text %}

View file

@ -2,7 +2,15 @@
{% load i18n %}
{% block content %}
{% blocktrans %}@{{ reporter}} has flagged behavior by @{{ reportee }} for moderation. {% endblocktrans %}
{% if report_link %}
{% blocktrans trimmed %}
@{{ reporter }} has flagged a link domain for moderation.
{% endblocktrans %}
{% else %}
{% blocktrans trimmed %}
@{{ reporter }} has flagged behavior by @{{ reportee }} for moderation.
{% endblocktrans %}
{% endif %}
{% trans "View report" %}
{{ report_link }}

View file

@ -15,7 +15,11 @@
<a href="{{ link.url }}" target="_blank" rel="noopener noreferrer">{{ link.url }}</a>
</td>
<td>
{% if link.added_by %}
<a href="{% url 'settings-user' link.added_by.id %}">@{{ link.added_by|username }}</a>
{% else %}
<em>{% trans "Unknown user" %}</em>
{% endif %}
</td>
<td>
{% if link.filelink.filetype %}

View file

@ -55,9 +55,11 @@
</div>
{% endif %}
{% if report.user %}
{% include 'settings/users/user_info.html' with user=report.user %}
{% include 'settings/users/user_moderation_actions.html' with user=report.user %}
{% endif %}
<div class="block">
<h3 class="title is-4">{% trans "Moderator Comments" %}</h3>

View file

@ -9,9 +9,15 @@ Report #{{ report_id }}: Status posted by @{{ username }}
{% elif report.links.exists %}
{% blocktrans trimmed with report_id=report.id username=report.user|username %}
Report #{{ report_id }}: Link added by @{{ username }}
{% endblocktrans %}
{% if report.user %}
{% blocktrans trimmed with report_id=report.id username=report.user|username %}
Report #{{ report_id }}: Link added by @{{ username }}
{% endblocktrans %}
{% else %}
{% blocktrans trimmed with report_id=report.id %}
Report #{{ report_id }}: Link domain
{% endblocktrans %}
{% endif %}
{% else %}

View file

@ -287,7 +287,7 @@ urlpatterns = [
name="report-status",
),
re_path(
r"^report/(?P<user_id>\d+)/link/(?P<link_id>\d+)?$",
r"^report/link/(?P<link_id>\d+)?$",
views.Report.as_view(),
name="report-link",
),

View file

@ -13,9 +13,13 @@ from bookwyrm import emailing, forms, models
class Report(View):
"""Make reports"""
def get(self, request, user_id, status_id=None, link_id=None):
def get(self, request, user_id=None, status_id=None, link_id=None):
"""static view of report modal"""
data = {"user": get_object_or_404(models.User, id=user_id)}
data = {"user": None}
if user_id:
# but normally we should have an error if the user is not found
data["user"] = get_object_or_404(models.User, id=user_id)
if status_id:
data["status"] = status_id
if link_id: