Send email to user when env role is created
This commit is contained in:
parent
f8dd072340
commit
2c37b16963
15
atst/jobs.py
15
atst/jobs.py
@ -177,7 +177,20 @@ def do_create_environment_role(csp: CloudProviderInterface, environment_role_id=
|
|||||||
env_role.cloud_id = result.id
|
env_role.cloud_id = result.id
|
||||||
db.session.add(env_role)
|
db.session.add(env_role)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# TODO: should send notification email to the user, maybe with their portal login name
|
user = env_role.application_role.user
|
||||||
|
mail_name = user.full_name.replace(" ", ".").lower()
|
||||||
|
username = f"{mail_name}@{csp_details.get('tennant_id')}.{app.config.get('OFFICE_365_DOMAIN')}"
|
||||||
|
send_mail(
|
||||||
|
recipients=[user.email],
|
||||||
|
subject=translate("email.azure_account_update.subject"),
|
||||||
|
body=translate(
|
||||||
|
"email.azure_account_update.body",
|
||||||
|
{"url": app.config.get("AZURE_LOGIN_URL"), "username": username},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
app.logger.info(
|
||||||
|
f"Notification email sent for enivornment role creation. User id: {user.id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def render_email(template_path, context):
|
def render_email(template_path, context):
|
||||||
|
@ -399,23 +399,44 @@ def test_dispatch_create_environment_role(monkeypatch):
|
|||||||
mock.delay.assert_called_once_with(environment_role_id=env_role.id)
|
mock.delay.assert_called_once_with(environment_role_id=env_role.id)
|
||||||
|
|
||||||
|
|
||||||
def test_create_environment_role():
|
class TestCreateEnvironmentRole:
|
||||||
portfolio = PortfolioFactory.create(csp_data={"tenant_id": "123"})
|
def test_success(self):
|
||||||
app = ApplicationFactory.create(portfolio=portfolio)
|
portfolio = PortfolioFactory.create(csp_data={"tenant_id": "123"})
|
||||||
app_role = ApplicationRoleFactory.create(
|
app = ApplicationFactory.create(portfolio=portfolio)
|
||||||
application=app, status=ApplicationRoleStatus.ACTIVE, cloud_id="123",
|
app_role = ApplicationRoleFactory.create(
|
||||||
)
|
application=app, status=ApplicationRoleStatus.ACTIVE, cloud_id="123",
|
||||||
env = EnvironmentFactory.create(application=app, cloud_id="123")
|
)
|
||||||
env_role = EnvironmentRoleFactory.create(
|
env = EnvironmentFactory.create(application=app, cloud_id="123")
|
||||||
environment=env, application_role=app_role, cloud_id=None
|
env_role = EnvironmentRoleFactory.create(
|
||||||
)
|
environment=env, application_role=app_role, cloud_id=None
|
||||||
|
)
|
||||||
|
|
||||||
csp = Mock()
|
csp = Mock()
|
||||||
result = UserRoleCSPResult(id="a-cloud-id")
|
result = UserRoleCSPResult(id="a-cloud-id")
|
||||||
csp.create_user_role = MagicMock(return_value=result)
|
csp.create_user_role = MagicMock(return_value=result)
|
||||||
do_create_environment_role(csp, environment_role_id=env_role.id)
|
do_create_environment_role(csp, environment_role_id=env_role.id)
|
||||||
|
|
||||||
assert env_role.cloud_id == "a-cloud-id"
|
assert env_role.cloud_id == "a-cloud-id"
|
||||||
|
|
||||||
|
def test_sends_email(self, monkeypatch):
|
||||||
|
send_mail = Mock()
|
||||||
|
monkeypatch.setattr("atst.jobs.send_mail", send_mail)
|
||||||
|
|
||||||
|
portfolio = PortfolioFactory.create(csp_data={"tenant_id": "123"})
|
||||||
|
app = ApplicationFactory.create(portfolio=portfolio)
|
||||||
|
app_role = ApplicationRoleFactory.create(
|
||||||
|
application=app, status=ApplicationRoleStatus.ACTIVE, cloud_id="123",
|
||||||
|
)
|
||||||
|
env = EnvironmentFactory.create(application=app, cloud_id="123")
|
||||||
|
env_role = EnvironmentRoleFactory.create(
|
||||||
|
environment=env, application_role=app_role, cloud_id=None
|
||||||
|
)
|
||||||
|
|
||||||
|
csp = Mock()
|
||||||
|
result = UserRoleCSPResult(id="a-cloud-id")
|
||||||
|
csp.create_user_role = MagicMock(return_value=result)
|
||||||
|
do_create_environment_role(csp, environment_role_id=env_role.id)
|
||||||
|
assert send_mail.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
class TestSendTaskOrderFiles:
|
class TestSendTaskOrderFiles:
|
||||||
|
@ -86,7 +86,10 @@ email:
|
|||||||
app_role_created:
|
app_role_created:
|
||||||
subject: Application Role Created
|
subject: Application Role Created
|
||||||
body: "Your application role has been created.\nVisit {url}, and use your username, {username}, to log in."
|
body: "Your application role has been created.\nVisit {url}, and use your username, {username}, to log in."
|
||||||
portfolio_invite: "{inviter_name} has invited you to a JEDI cloud portfolio."
|
azure_account_update:
|
||||||
|
subject: Azure account update
|
||||||
|
body: "There has been an update to your Azure account. \nVisit {url}, and use your username, {username}, to log in."
|
||||||
|
portfolio_invite: "{inviter_name} has invited you to a JEDI cloud portfolio"
|
||||||
portfolio_ready:
|
portfolio_ready:
|
||||||
subject: Portfolio Provisioned
|
subject: Portfolio Provisioned
|
||||||
body: "Your portfolio has been provisioned.\nVisit {password_reset_address}, and use your username, {username}, to create a password."
|
body: "Your portfolio has been provisioned.\nVisit {password_reset_address}, and use your username, {username}, to create a password."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user