Repository navigation
Have staff write assignment emails as plain text - #145
Merged
Merged
Conversation
The HTML email is built from the plain text by a template in the repo, which escapes every piece of it; staff text is never run as a template. The subject comes first with the exam's name, the variables are listed on the page, unknown variables are refused, and the preview shows the email a student would get, filled in by the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🚀 Staging Preview Deployed! URL: https://preview-seating-pr-145-137456085712.us-west1.run.app |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
==========================================
+ Coverage 79.64% 80.01% +0.36%
==========================================
Files 31 31
Lines 2398 2442 +44
==========================================
+ Hits 1910 1954 +44
Misses 488 488
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…eir own lines Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… period Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #140. Staff write assignment emails as plain text, and never see or write HTML. As agreed on the issue, this is plain text with variables, not Markdown.
http(s)://links become clickable.Room: {{ROOM}}and so on), so staff can see and edit each one.{{ROOOM}}) is refused before anything is sent. Before, it reached every student exactly as typed.Safety
Staff text is only ever data, and is never run as a Jinja template. Running it as one would let anyone who can write an email run code on the server.
assignment_email.htmlescapes each piece as it outputs it. HTML typed by staff shows up as text.http://andhttps://URLs become links.<iframe>, so nothing in it can run scripts or reach the page.Changes
server/services/email/templates/:__init__.py:VARIABLES, one list that the page, the check and the substitution all use.unknown_variables, which finds placeholders that aren't variables.render_textandrender_html, which build the two versions.get_email, which now just returns the starting subject and body.assignment_email.html: the HTML template: paragraphs, line breaks and links.assignment_inform_email.txt: the default message, replacing the old.htmlone.server/services/email/__init__.py:assignment_values: the values of the variables for one student.substitute_about_assignment: returns the subject, text and HTML. Every send path uses it: all students, one student, test emails and the batch endpoint.server/forms.py: thebody_htmlfield is removed, and both subject and body are checked for unknown variables. The newEmailPreviewFormis the part ofEmailFormthe preview needs.server/views.py:email_preview(/students/email/preview/) returns a student's email as JSON.server/templates/email.html:server/static/css/style.css: styles for the preview, the note and the table.Tests
tests/unit/test_email_substitution.py: rewritten for plain text. It covers:{{ 7 * 7 }},{% if %},{{ config }})javascript:, quotes)tests/unit/test_email_page.py: the plain-text prefill, the subject before the message, the variables table, unknown variables refused by both the page and the batch endpoint, and the preview endpoint.tests/e2e/test_email_preview.py: in Chrome, Preview shows the filled-in email and its link, and a typo shows an error instead.test_email.py,test_email_test_send.py,test_email_batches.pyandtest_email_copies.py.Locally: unit 425, e2e 17, a11y 4 passing.
🤖 Generated with Claude Code