-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default email template #1898
Open
milescalabresi
wants to merge
15
commits into
main
Choose a base branch
from
add-default-email-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
868435f
Create default_email_html.txt
milescalabresi d584bf0
use default HTML email template
milescalabresi eff3d7b
fixes missing comma
milescalabresi 594b670
add instructions for admins to use new template
milescalabresi 3284a76
fixes missing import in commmodule.py
milescalabresi eda9ad5
add (curently inactive) radio buttons for text vs HTML
milescalabresi 53a614c
add DIY unsubscribe message at bottom
milescalabresi 1db5e2d
initial crude JS validator to see if HTML present
milescalabresi b06685e
finish JS validator for HTML vs plaintext
milescalabresi 06a548b
add explanation for 'your email' and move JS to separate script file
milescalabresi f68ef1d
Merge remote-tracking branch 'origin/main' into add-default-email-tem…
milescalabresi e50ec11
improve handling of user's selected language
milescalabresi 0b4ec30
pass correct html vs plaintxt variables
milescalabresi 121b465
pass correct template and escape HTML
milescalabresi d8599f4
rename email template wrapper for consistency
milescalabresi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<html> | ||
{% autoescape off %} | ||
{{ msgbdy|safe }} | ||
{% endautoescape %} | ||
<small> | ||
You received this email because you have signed up for an account on our website, | ||
<a href=>{% templatetag openvariable %}EMAIL_HOST{% templatetag closevariable %}. | ||
This email was sent to the email account associated with the | ||
user {% templatetag openvariable %}user.username{% templatetag closevariable %}. | ||
If you received the same email message multiple times, you may have duplicate accounts; | ||
please email us to delete them. If you no longer wish for {% templatetag openvariable %}user.username{% templatetag closevariable %} | ||
to receive emails from us, email us or click | ||
<a href="/myesp/disableaccount" style="color: #336699;font-weight: normal;text-decoration: underline;">here</a>. | ||
This action will unsubscribe you from receiving emails to {% templatetag openvariable %}user.username{% templatetag closevariable %}. | ||
You will still receive messages to this email address if it is listed in the contact information for other accounts on our site. | ||
</small> | ||
</html> |
38 changes: 38 additions & 0 deletions
38
esp/templates/program/modules/commmodule/commpanel_step2.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
function showEmailExplanation() { | ||
document.getElementById("from-help").style.display = ''; | ||
} | ||
|
||
function hideEmailExplanation() { | ||
document.getElementById("from-help").style.display = 'none'; | ||
document.getElementById("from").focus(); | ||
} | ||
|
||
|
||
function validateMsgLang() { | ||
var msgTypes = document.getElementsByName("msglang"); | ||
var containsTag = /<(\/?((.)|(br ?\/?)))>|(<img)/i.test( | ||
document.getElementById("emailbody").value); | ||
var containsHTag = /<\/?html>/i.test( | ||
document.getElementById("emailbody").value); | ||
|
||
if(containsHTag) { | ||
return confirm("Didn't we say not to include <html> tags?!? " | ||
+ "If you're sure you know what you're doing, " | ||
+ "click 'OK' to continue."); | ||
} else if(msgTypes[1].checked && !containsTag) { | ||
return confirm('You selected "HTML" but included no HTML tags. ' | ||
+ 'Continuing might squash your formatting. ' | ||
+ 'Would you still like to proceed?'); | ||
} else if(msgTypes[0].checked && containsTag) { | ||
return confirm('You selected "Plain Text" but have HTML tags ' | ||
+ '(such as <p>) in your message. ' | ||
+ 'Continuing will leave your tags in your message ' | ||
+ '(so you would see "<b>hello</b>" instead of ' | ||
+ 'a bold "hello"). ' | ||
+ 'Would you still like to proceed?'); | ||
} | ||
else { | ||
return true; | ||
} | ||
} |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes the template to render user variables in the template itself (not message body) with information about the sender. Not a problem with the default since there's no use of the user, but this is what's causing Yale's bug. Since the template is going to get rendered into one copy for all users, which then gets further transformed later into the individual copies, user information shouldn't be passed here at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add user information into the template? It would be very useful to put, for instance, the username the email was sent to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you can still put user information in the template; it will just get interpreted on the second render pass, when we add user variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't quite understand what the difference is / what needs to be done in order to make sure the right thing happens instead of the variables being rendered in the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This template should get rendered twice. First, here, we render
msgbdy
intodefault_email_html.txt
to getmsgtext
. This happens once, and therefore should not include any user data, because we don't yet know what user the email will be sent to. Then, later, below, we the output of that (msgtext
) into the actual email, once for each user, injecting their information into the template. Any variables inmsgtext
will get interpreted on the second pass. When you includerequest.user
the first time, it means that any user variables indefault_email_html.txt
get rendered according to the user sending the email, because that's whorequest.user
is; instead you want to render them the second time with the email's recipient as the user.I wrote too quickly above and was a bit incorrect: any template variables that you put in
default_email_html.txt
that should get rendered on the second pass, i.e., any user variables, need to have their template tags excaped, using{% templatetag openvariable %}
instead of{{
and{% templatetag closevariable %}
instead of}}
. This way, the first rendering pass will convert those to{{
and}}
and then the second rendering pass will see them as normal variables, and interpolate the correct user's information.