Send email after environment is provisioned

This commit is contained in:
leigh-mil 2019-10-08 15:57:31 -04:00
parent 92acf3168e
commit 10c16cc4ef
4 changed files with 23 additions and 1 deletions

View File

@ -12,6 +12,7 @@ from atst.domain.csp.cloud import CloudProviderInterface, GeneralCSPException
from atst.domain.environments import Environments
from atst.domain.environment_roles import EnvironmentRoles
from atst.models.utils import claim_for_update
from atst.utils.localization import translate
class RecordEnvironmentFailure(celery.Task):
@ -91,6 +92,10 @@ def do_create_atat_admin_user(csp: CloudProviderInterface, environment_id=None):
db.session.commit()
def render_email(template_path, context):
return app.jinja_env.get_template(template_path).render(context)
def do_create_environment_baseline(csp: CloudProviderInterface, environment_id=None):
environment = Environments.get(environment_id)
@ -102,6 +107,12 @@ def do_create_environment_baseline(csp: CloudProviderInterface, environment_id=N
atat_remote_root_creds, environment.cloud_id
)
environment.baseline_info = baseline_info
body = render_email(
"emails/application/environment_ready.txt", {"environment": environment}
)
app.mailer.send(
[environment.creator.email], translate("email.environment_ready"), body
)
db.session.add(environment)
db.session.commit()

View File

@ -0,0 +1,9 @@
{% extends "emails/base.txt" %}
{% block content %}
A JEDI environment you set up is now available. Please click the link below to access your JEDI application.
{{ url_for("applications.settings", application_id=environment.application_id, _external=True) }}
{% endblock %}

View File

@ -100,7 +100,7 @@ def test_create_atat_admin_user(csp, session):
assert environment.root_user_info
def test_create_environment_baseline(csp, session):
def test_create_environment_baseline(csp, session, app):
environment = EnvironmentFactory.create(
root_user_info={"credentials": csp.root_creds()}
)
@ -108,6 +108,7 @@ def test_create_environment_baseline(csp, session):
session.refresh(environment)
assert environment.baseline_info
assert len(app.mailer.messages) > 0
def test_dispatch_create_environment(session, monkeypatch):

View File

@ -104,6 +104,7 @@ errors:
email:
application_invite: "{inviter_name} has invited you to a JEDI cloud application"
portfolio_invite: "{inviter_name} has invited you to a JEDI cloud portfolio"
environment_ready: JEDI cloud environment ready
flash:
application:
created: 'You have successfully created the {application_name} application.'