Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions intranet/apps/announcements/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def request_announcement_email(request, form, obj):
emails.append(teacher.tj_email)
logger.info("%s: Announcement request to %s, %s", request.user, teachers, emails)
base_url = request.build_absolute_uri(reverse("index"))
formdata = form.data.copy()
formdata["content"] = obj.content
data = {
"teachers": teachers,
"user": request.user,
"formdata": form.data,
"formdata": formdata,
"info_link": request.build_absolute_uri(reverse("approve_announcement", args=[obj.id])),
"base_url": base_url,
}
logger.info("%s: Announcement request %s", request.user, data)
email_send_task.delay("announcements/emails/teacher_approve.txt", "announcements/emails/teacher_approve.html", data, subject, emails)


Expand Down
14 changes: 14 additions & 0 deletions intranet/apps/templatetags/strings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import string

from bs4 import BeautifulSoup
from django import template

register = template.Library()
Expand All @@ -15,3 +16,16 @@ def contains_digit(s):
@register.filter
def endswith(val, arg):
return val.endswith(arg)


@register.filter
def remove_inline_images(value: str) -> str:
"""Remove images embedded as data URLs from HTML."""
if "data:" not in value.lower():
return value

html = BeautifulSoup(value, "html.parser")
for image in html.find_all("img", src=True):
if image["src"].lstrip()[:5].lower() == "data:":
image.decompose()
return str(html)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load strings %}
{% with description="Approve announcement" target=info_link name="View announcement" %}
{% include "email_metadata.html" %}
{% endwith %}
Expand All @@ -6,7 +7,7 @@
<b>Title:</b> {{ formdata.title }}<br>
<b>Content:</b><br>
{% autoescape off %}
{{ req.content }}
{{ req.content|remove_inline_images }}
{% endautoescape %}
<br>
<b>Submitted by:</b> {{ req.user.full_name }} ({{ req.user.username }})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: {{ formdata.title }}

Content:
{% autoescape off %}
{{ req.content }}
{{ req.content|striptags }}
{% endautoescape %}

Submitted by: {{ req.user.full_name }} ({{ req.user.username }})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load strings %}
{% with description="Announcement approved" target=info_link name="View" %}
{% include "email_metadata.html" %}
{% endwith %}
Expand All @@ -23,7 +24,7 @@
<h2>{{ announcement.title }}</h2>

{% autoescape off %}
{{ announcement.content|truncatewords_html:30 }}
{{ announcement.content|remove_inline_images|truncatewords_html:30 }}
{% endautoescape %}

<p><a href="{{ info_link }}">View this announcement on Intranet</a></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ announcement.title }}

{% autoescape off %}
{{ announcement.content|truncatewords_html:30 }}
{{ announcement.content|striptags|truncatewords:30 }}
{% endautoescape %}

View this announcement on Intranet: {{ info_link }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% load strings %}
{% with description="Announcement posted" target=info_link name="View" %}
{% include "email_metadata.html" %}
{% endwith %}

{% autoescape off %}
{{ announcement.content }}
{{ announcement.content|remove_inline_images }}
{% endautoescape %}

<p>Posted by {{ announcement.get_author }} on {{ announcement.added|date:"l, F j, Y"}} at {{ announcement.added|date:"P"}} to {% if announcement.is_club_announcement %}{{ announcement.activity.name }}{% else %}{% if announcement.groups.count == 0 %}everyone{% else %}{{ announcement.groups.all|join:", " }}{% endif %}{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% autoescape off %}
{{ announcement.content }}
{{ announcement.content|striptags }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Plain-text emails lose link destinations

The new striptags calls remove link URLs from plain-text emails. For example, <a href="https://example.org/signup">Register here</a> becomes only “Register here.” Recipients reading plain text must open Intranet to find the signup link. This affects all four changed text templates. Use an HTML-to-text conversion that keeps link destinations while dropping image tags.

Knowledge Base Used: Announcements, events, and notifications

Fix in Codex Fix in Claude Code

{% endautoescape %}

Posted by {{ announcement.get_author }} on {{ announcement.added|date:"l, F j, Y"}} at {{ announcement.added|date:"P"}} to {% if announcement.is_club_announcement %}{{ announcement.activity.name }}{% else %}{% if announcement.groups.count == 0 %}everyone{% else %}{{ announcement.groups.all|join:", " }}{% endif %}{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load strings %}
{% with description="Announcement needs approval" target=info_link name="View announcement" %}
{% include "email_metadata.html" %}
{% endwith %}
Expand All @@ -6,7 +7,7 @@
<b>Title:</b> {{ formdata.title }}<br>
<b>Content (that will be posted):</b><br>
{% autoescape off %}
{{ formdata.content }}
{{ formdata.content|remove_inline_images }}
{% endautoescape %}
<br>
<b>Notes (for you and the Intranet administrators):</b><br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: {{ formdata.title }}

Content (that will be posted):
{% autoescape off %}
{{ formdata.content }}
{{ formdata.content|striptags }}
{% endautoescape %}

Notes (for you and the Intranet administrators):
Expand Down
Loading