New Moderation Report Email (#346)

This commit is contained in:
NaphalSec 2023-01-02 18:31:32 -05:00 committed by GitHub
parent 03bfc417df
commit c10aa46fc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 2 deletions

View file

@ -0,0 +1,33 @@
{% extends "emails/base.html" %}
{% load mail_tags %}
{% autoescape off %}
{% block title %}{{config.site_name}} - New Moderation Report{% endblock title %}
{% block subtitle %}{{config.site_name}} - New Moderation Report{% endblock subtitle %}
{% block body_greeting %}
{% email_body_content "Moderation Team," %}
{% email_body_content "A new report has been recieved for {{config.site_name}}." %}
{% endblock body_greeting %}
{% block body_content %}
{% email_body_content "=============== Report Summary ===============" %}
{% if report.source_identity %}
{% email_body_content "Reporter Identity: {{report.source_identity}} @ {{report.source_domain}}" %}
{% else %}
{% email_body_content "Reporter Identity: Anonymous Report from {{report.source_domain}}" %}
{% endif %}
{% email_body_content "Reported Identity: {{report.subject_identity}}" %}
{% email_body_content "Complaint Type: {{report.type}}" %}
{% email_body_content "Complaint Notes: {{report.complaint}}" %}
{% endblock body_content %}
{% block body_button %}
{% email_button button_text="View Report" button_link="https://{{settings.MAIN_DOMAIN}}/admin/reports/{{report.id}}/" %}
{% endblock body_button %}
{% block extra_footer %}
{% email_footer "You are recieving this email because you are a moderator on the Takahe instance https://{{settings.MAIN_DOMAIN}}" %}
{% endblock extra_footer %}
{% endautoescape %}

View file

@ -0,0 +1,22 @@
A new report has been recieved for {{config.site_name}}.
Please review the report at the link below:
https://{{settings.MAIN_DOMAIN}}/admin/reports/{{report.id}}/
=============== Report Summary ===============
{% if report.source_identity %}
Reporter Identity: {{report.source_identity}} @ {{report.source_domain}}
{% else %}
Reporter Identity: Anonymous Report from {{report.source_domain}}
{% endif %}
Reported Identity: {{report.subject_identity}}
Complaint Type: {{report.type}}
Complaint Notes: {{report.complaint}}
=============== End Report ===============
You are recieving this email because you are a moderator on the Takahe instance https://{{settings.MAIN_DOMAIN}}

View file

@ -2,9 +2,14 @@ from urllib.parse import urlparse
import httpx
import urlman
from asgiref.sync import sync_to_async
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.template.loader import render_to_string
from core.ld import canonicalise, get_list
from core.models import Config
from stator.models import State, StateField, StateGraph, StatorModel
from users.models import Domain
@ -20,9 +25,15 @@ class ReportStates(StateGraph):
"""
Sends the report to the remote server if we need to
"""
from users.models import SystemActor
from users.models import SystemActor, User
recipients = []
report = await instance.afetch_full()
async for mod in User.objects.filter(
models.Q(moderator=True) | models.Q(admin=True)
).values_list("email", flat=True):
recipients.append(mod)
if report.forward and not report.subject_identity.domain.local:
system_actor = SystemActor()
try:
@ -32,7 +43,32 @@ class ReportStates(StateGraph):
body=canonicalise(report.to_ap()),
)
except httpx.RequestError:
return
pass
email = EmailMultiAlternatives(
subject=f"{Config.system.site_name}: New Moderation Report",
body=render_to_string(
"emails/report_new.txt",
{
"report": report,
"config": Config.system,
"settings": settings,
},
),
from_email=settings.SERVER_EMAIL,
bcc=recipients,
)
email.attach_alternative(
content=render_to_string(
"emails/report_new.html",
{
"report": report,
"config": Config.system,
"settings": settings,
},
),
mimetype="text/html",
)
await sync_to_async(email.send)()
return cls.sent