Send email after environment is provisioned
This commit is contained in:
parent
92acf3168e
commit
10c16cc4ef
11
atst/jobs.py
11
atst/jobs.py
@ -12,6 +12,7 @@ from atst.domain.csp.cloud import CloudProviderInterface, GeneralCSPException
|
|||||||
from atst.domain.environments import Environments
|
from atst.domain.environments import Environments
|
||||||
from atst.domain.environment_roles import EnvironmentRoles
|
from atst.domain.environment_roles import EnvironmentRoles
|
||||||
from atst.models.utils import claim_for_update
|
from atst.models.utils import claim_for_update
|
||||||
|
from atst.utils.localization import translate
|
||||||
|
|
||||||
|
|
||||||
class RecordEnvironmentFailure(celery.Task):
|
class RecordEnvironmentFailure(celery.Task):
|
||||||
@ -91,6 +92,10 @@ def do_create_atat_admin_user(csp: CloudProviderInterface, environment_id=None):
|
|||||||
db.session.commit()
|
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):
|
def do_create_environment_baseline(csp: CloudProviderInterface, environment_id=None):
|
||||||
environment = Environments.get(environment_id)
|
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
|
atat_remote_root_creds, environment.cloud_id
|
||||||
)
|
)
|
||||||
environment.baseline_info = baseline_info
|
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.add(environment)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
9
templates/emails/application/environment_ready.txt
Normal file
9
templates/emails/application/environment_ready.txt
Normal 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 %}
|
@ -100,7 +100,7 @@ def test_create_atat_admin_user(csp, session):
|
|||||||
assert environment.root_user_info
|
assert environment.root_user_info
|
||||||
|
|
||||||
|
|
||||||
def test_create_environment_baseline(csp, session):
|
def test_create_environment_baseline(csp, session, app):
|
||||||
environment = EnvironmentFactory.create(
|
environment = EnvironmentFactory.create(
|
||||||
root_user_info={"credentials": csp.root_creds()}
|
root_user_info={"credentials": csp.root_creds()}
|
||||||
)
|
)
|
||||||
@ -108,6 +108,7 @@ def test_create_environment_baseline(csp, session):
|
|||||||
session.refresh(environment)
|
session.refresh(environment)
|
||||||
|
|
||||||
assert environment.baseline_info
|
assert environment.baseline_info
|
||||||
|
assert len(app.mailer.messages) > 0
|
||||||
|
|
||||||
|
|
||||||
def test_dispatch_create_environment(session, monkeypatch):
|
def test_dispatch_create_environment(session, monkeypatch):
|
||||||
|
@ -104,6 +104,7 @@ errors:
|
|||||||
email:
|
email:
|
||||||
application_invite: "{inviter_name} has invited you to a JEDI cloud application"
|
application_invite: "{inviter_name} has invited you to a JEDI cloud application"
|
||||||
portfolio_invite: "{inviter_name} has invited you to a JEDI cloud portfolio"
|
portfolio_invite: "{inviter_name} has invited you to a JEDI cloud portfolio"
|
||||||
|
environment_ready: JEDI cloud environment ready
|
||||||
flash:
|
flash:
|
||||||
application:
|
application:
|
||||||
created: 'You have successfully created the {application_name} application.'
|
created: 'You have successfully created the {application_name} application.'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user