Skip to content
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 responsive email format to the babylon-notifier #662

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions notifier/.s2i/bin/assemble
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

npm install -g npm@8.19.3
npm install -g mjml@4.13.0

exec /usr/libexec/s2i/assemble
5 changes: 3 additions & 2 deletions notifier/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ RUN dnf install -y @ruby && \
rm -rf /tmp/src/.git* && \
chown -R 1001 /tmp/src && \
chgrp -R 0 /tmp/src && \
chmod -R g+w /tmp/src
chmod -R g+w /tmp/src \
cp -rp /tmp/src/.s2i/bin /tmp/scripts

USER 1001

RUN /usr/libexec/s2i/assemble
RUN /tmp/scripts/assemble

CMD ["/usr/libexec/s2i/run"]
3 changes: 2 additions & 1 deletion notifier/devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
commands:
- exec:
commandLine: /usr/libexec/s2i/assemble
commandLine: >-
rm -rf /tmp/src && cp /tmp/projects -r /tmp/src && /tmp/src/.s2i/bin/assemble
component: s2i-builder
group:
isDefault: true
Expand Down
12 changes: 10 additions & 2 deletions notifier/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ def send_notification_email(
)
)
template_vars['have_attachments'] = len(attachments) > 0
template_vars['service_status'] = ' '.join(elem.capitalize() for elem in template.replace('-', ' ').split())

email_subject = j2env.from_string(subject).render(**template_vars)

Expand All @@ -726,9 +727,16 @@ def send_notification_email(
else:
message_template = catalog_item.get_message_template(kebabToCamelCase(template))
if message_template:
email_body = j2env.from_string(message_template).render(**template_vars)
mjml_template = j2env.from_string(message_template).render(**template_vars)
else:
email_body = j2env.get_template(template + '.html.j2').render(**template_vars)
mjml_template = j2env.get_template(template + '.mjml.j2').render(**template_vars)

# Call for the MJML CLI to generate final HTML
email_body = subprocess.run(
['mjml', '-i'],
stdout=subprocess.PIPE,
input=mjml_template,
encoding='ascii').stdout

msg = MIMEMultipart('alternative')
msg['Subject'] = email_subject
Expand Down
58 changes: 58 additions & 0 deletions notifier/operator/templates/base.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<mjml>
<mj-body>
<!-- Company Header -->
<mj-section full-width="full-width" background-color="#151515" padding-top="8px" padding-bottom="8px" padding-left="12px" padding-right="12px">
<mj-group>
<mj-column vertical-align="middle">
<mj-image href="https://demo.redhat.com/" title="RedHat" alt="RedHat" width="185px" src="https://public-assets-email.s3.us-east-2.amazonaws.com/Logo-Red_Hat-A-Reverse-RGB.png" />
</mj-column>
</mj-group>
</mj-section>
<!-- spacer -->
<mj-section padding-top="0" padding-bottom="0" padding-left="0" padding-right="0">
<mj-column>
<mj-spacer height="25px" />
</mj-column>
</mj-section>
<!-- Title -->
<mj-section padding-top="21px" padding-bottom="12px" padding-left="12px" padding-right="12px">
<mj-column>
<mj-text font-family="Red Hat Text" font-weight="regular" align="center" font-size="16px" color="#000" line-height="1.2">
Status: {{ service_status }}
</mj-text>
<mj-text font-family="Red Hat Display" font-weight="regular" align="center" font-size="35px" color="#000" line-height="1.2">
{{ service_display_name }}
</mj-text>
<mj-text font-family="Red Hat Text" font-weight="regular" align="center" font-size="16px" color="#000" line-height="1.2">
from {{ catalog_namespace.display_name }}
</mj-text>
</mj-column>
</mj-section>

<!-- spacer -->
<mj-section padding-top="0" padding-bottom="0" padding-left="0" padding-right="0">
<mj-column>
<mj-spacer height="25px" />
</mj-column>
</mj-section>
<!-- Text -->
<mj-section padding-top="12px" padding-bottom="12px" padding-left="12px" padding-right="12px" background-color="#f0f0f0">
<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">
{% block content %}{% endblock %}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Lift the content to be inside the mj-section
And then in every .mjml template use the mj-column / mj-text accordingly. As it is now the templates will not have lots of flexibility as they are encapsulated under those elements and they use plain html syntax without having the benefits of mjml syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I wanted to implement it this way initially but for some reason I've change my mind and left child templates with pure HTML/JINJA2 without any MJML tags.

New commit should fix it - 164ccd9

</mj-text>
</mj-column>
</mj-section>

<!-- Footer -->
<mj-section padding-top="12px" padding-bottom="12px" padding-left="12px" padding-right="12px">
<mj-column>
<mj-text align="center" font-size="12px" color="#4a5557" font-family="Red Hat Text" line-height="1.5">
<b>RedHat
</b> &copy; Copyright 2022 - All rights reserved
</mj-text>
</mj-column>
</mj-section>
<!-- Footer -->
</mj-body>
</mjml>
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service, {{ service_display_name }}, has failed to provision.
{% if have_attachments %}
Please see attached Ansible log.
Expand All @@ -8,3 +11,5 @@ Please see attached Ansible log.
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Thank you for ordering {{ catalog_item.display_name }}.</p>

<p>Provisioning has started on your {{ catalog_namespace.display_name }} service, {{ service_display_name }}.</p>
Expand All @@ -8,3 +11,5 @@
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Reminder:<br>
Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has been deleted.</p>

<p>To conserve resources data on these systems is not archived and cannot be retrieved.
Expand All @@ -7,3 +10,5 @@ Thank you for using {{ catalog_namespace.display_name }}.</p>
{% if survey_link %}
<p>We would love your feedback on your demo/lab, please fill out our short Survey (<a href="{{ survey_link | escape }}">click here</a>) to help us improve your experience.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Thank you for ordering {{ catalog_item.display_name }}.</p>

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} is ready.</p>
Expand Down Expand Up @@ -42,3 +45,5 @@ All data will be lost upon expiration.</p>
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has started.</p>

<p>NOTICE:<br>
Expand All @@ -8,3 +11,5 @@ Your environment will expire and be deleted in {{ retirement_timedelta_humanized
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to start.
{% if have_attachments %}
Please see attached Ansible log.
Expand All @@ -8,3 +11,5 @@ Please see attached Ansible log.
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has stopped.</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to stop.
{% if have_attachments %}
Please see attached Ansible log.
Expand All @@ -8,3 +11,5 @@ Please see attached Ansible log.
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% extends "base.mjml.j2" %}
{% block content %}

<p>Reminder:<br>
Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

{% endblock content %}