mirror of https://github.com/zulip/zulip.git
send_custom_email: Use a special .gitignored directory.
Previously, the send_custom_email code path leaked files in paths that were not `.gitignored`, under templates/zerver/emails. This became problematic when we added automated tests for this code path, as it meant we leaked these files every time `test-backend` ran. Fix this by ensuring all the files we generate are in this special subdirectory.
This commit is contained in:
parent
b5f2ba5566
commit
703fae8980
|
@ -29,12 +29,12 @@ def configure_cssutils() -> None:
|
||||||
configure_cssutils()
|
configure_cssutils()
|
||||||
|
|
||||||
def inline_template(template_source_name: str) -> None:
|
def inline_template(template_source_name: str) -> None:
|
||||||
os.makedirs(COMPILED_EMAIL_TEMPLATES_PATH, exist_ok=True)
|
|
||||||
|
|
||||||
template_name = template_source_name.split('.source.html')[0]
|
template_name = template_source_name.split('.source.html')[0]
|
||||||
compiled_template_path = os.path.join(COMPILED_EMAIL_TEMPLATES_PATH,
|
|
||||||
template_name + ".html")
|
|
||||||
template_path = os.path.join(EMAIL_TEMPLATES_PATH, template_source_name)
|
template_path = os.path.join(EMAIL_TEMPLATES_PATH, template_source_name)
|
||||||
|
compiled_template_path = os.path.join(os.path.dirname(template_path), "compiled",
|
||||||
|
os.path.basename(template_name) + ".html")
|
||||||
|
|
||||||
|
os.makedirs(os.path.dirname(compiled_template_path), exist_ok=True)
|
||||||
|
|
||||||
with open(template_path) as template_source_file:
|
with open(template_path) as template_source_file:
|
||||||
template_str = template_source_file.read()
|
template_str = template_source_file.read()
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
compiled
|
compiled
|
||||||
|
custom
|
||||||
|
|
|
@ -265,12 +265,13 @@ def send_custom_email(users: List[UserProfile], options: Dict[str, Any]) -> None
|
||||||
parsed_email_template = Parser(policy=default).parsestr(text)
|
parsed_email_template = Parser(policy=default).parsestr(text)
|
||||||
email_template_hash = hashlib.sha256(text.encode('utf-8')).hexdigest()[0:32]
|
email_template_hash = hashlib.sha256(text.encode('utf-8')).hexdigest()[0:32]
|
||||||
|
|
||||||
email_filename = "custom_email_%s.source.html" % (email_template_hash,)
|
email_filename = "custom/custom_email_%s.source.html" % (email_template_hash,)
|
||||||
email_id = "zerver/emails/custom_email_%s" % (email_template_hash,)
|
email_id = "zerver/emails/custom/custom_email_%s" % (email_template_hash,)
|
||||||
markdown_email_base_template_path = "templates/zerver/emails/custom_email_base.pre.html"
|
markdown_email_base_template_path = "templates/zerver/emails/custom_email_base.pre.html"
|
||||||
html_source_template_path = "templates/%s.source.html" % (email_id,)
|
html_source_template_path = "templates/%s.source.html" % (email_id,)
|
||||||
plain_text_template_path = "templates/%s.txt" % (email_id,)
|
plain_text_template_path = "templates/%s.txt" % (email_id,)
|
||||||
subject_path = "templates/%s.subject.txt" % (email_id,)
|
subject_path = "templates/%s.subject.txt" % (email_id,)
|
||||||
|
os.makedirs(os.path.dirname(html_source_template_path), exist_ok=True)
|
||||||
|
|
||||||
# First, we render the markdown input file just like our
|
# First, we render the markdown input file just like our
|
||||||
# user-facing docs with render_markdown_path.
|
# user-facing docs with render_markdown_path.
|
||||||
|
|
Loading…
Reference in New Issue