diff --git a/atst/jobs.py b/atst/jobs.py index 2a3ea97f..320cbbfe 100644 --- a/atst/jobs.py +++ b/atst/jobs.py @@ -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() diff --git a/templates/emails/application/environment_ready.txt b/templates/emails/application/environment_ready.txt new file mode 100644 index 00000000..99f3c60b --- /dev/null +++ b/templates/emails/application/environment_ready.txt @@ -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 %} diff --git a/tests/test_jobs.py b/tests/test_jobs.py index b0058851..ce710d69 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -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): diff --git a/translations.yaml b/translations.yaml index 80cfd9f9..95a431a3 100644 --- a/translations.yaml +++ b/translations.yaml @@ -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.'