Merge pull request #1425 from dod-ccpo/email-notification-new-app-role
Email notification for new app role
This commit is contained in:
commit
bd14955a6a
12
atst/jobs.py
12
atst/jobs.py
@ -111,6 +111,18 @@ def do_create_user(csp: CloudProviderInterface, application_role_ids=None):
|
|||||||
db.session.add(app_role)
|
db.session.add(app_role)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
username = payload.user_principal_name
|
||||||
|
send_mail(
|
||||||
|
recipients=[user.email],
|
||||||
|
subject=translate("email.app_role_created.subject"),
|
||||||
|
body=translate(
|
||||||
|
"email.app_role_created.body",
|
||||||
|
{"url": app.config.get("AZURE_LOGIN_URL"), "username": username},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
app.logger.info(
|
||||||
|
f"Application role created notification email sent. User id: {user.id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def do_create_environment(csp: CloudProviderInterface, environment_id=None):
|
def do_create_environment(csp: CloudProviderInterface, environment_id=None):
|
||||||
|
@ -135,28 +135,63 @@ def test_create_application_job_is_idempotent(csp):
|
|||||||
csp.create_application.assert_not_called()
|
csp.create_application.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_create_user_job(session, csp, app):
|
class TestCreateUserJob:
|
||||||
portfolio = PortfolioFactory.create(
|
@pytest.fixture
|
||||||
csp_data={
|
def portfolio(self, app):
|
||||||
"tenant_id": str(uuid4()),
|
return PortfolioFactory.create(
|
||||||
"domain_name": f"rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}",
|
csp_data={
|
||||||
}
|
"tenant_id": str(uuid4()),
|
||||||
)
|
"domain_name": f"rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}",
|
||||||
application = ApplicationFactory.create(portfolio=portfolio, cloud_id="321")
|
}
|
||||||
user = UserFactory.create(
|
)
|
||||||
first_name="Han", last_name="Solo", email="han@example.com"
|
|
||||||
)
|
|
||||||
app_role = ApplicationRoleFactory.create(
|
|
||||||
application=application,
|
|
||||||
user=user,
|
|
||||||
status=ApplicationRoleStatus.ACTIVE,
|
|
||||||
cloud_id=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
do_create_user(csp, [app_role.id])
|
@pytest.fixture
|
||||||
session.refresh(app_role)
|
def app_1(self, portfolio):
|
||||||
|
return ApplicationFactory.create(portfolio=portfolio, cloud_id="321")
|
||||||
|
|
||||||
assert app_role.cloud_id
|
@pytest.fixture
|
||||||
|
def app_2(self, portfolio):
|
||||||
|
return ApplicationFactory.create(portfolio=portfolio, cloud_id="123")
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def user(self):
|
||||||
|
return UserFactory.create(
|
||||||
|
first_name="Han", last_name="Solo", email="han@example.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def app_role_1(self, app_1, user):
|
||||||
|
return ApplicationRoleFactory.create(
|
||||||
|
application=app_1,
|
||||||
|
user=user,
|
||||||
|
status=ApplicationRoleStatus.ACTIVE,
|
||||||
|
cloud_id=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def app_role_2(self, app_2, user):
|
||||||
|
return ApplicationRoleFactory.create(
|
||||||
|
application=app_2,
|
||||||
|
user=user,
|
||||||
|
status=ApplicationRoleStatus.ACTIVE,
|
||||||
|
cloud_id=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_user_job(self, session, csp, app_role_1):
|
||||||
|
assert not app_role_1.cloud_id
|
||||||
|
|
||||||
|
session.begin_nested()
|
||||||
|
do_create_user(csp, [app_role_1.id])
|
||||||
|
session.rollback()
|
||||||
|
|
||||||
|
assert app_role_1.cloud_id
|
||||||
|
|
||||||
|
def test_create_user_sends_email(self, monkeypatch, csp, app_role_1, app_role_2):
|
||||||
|
mock = Mock()
|
||||||
|
monkeypatch.setattr("atst.jobs.send_mail", mock)
|
||||||
|
|
||||||
|
do_create_user(csp, [app_role_1.id, app_role_2.id])
|
||||||
|
assert mock.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_dispatch_create_environment(session, monkeypatch):
|
def test_dispatch_create_environment(session, monkeypatch):
|
||||||
|
@ -83,7 +83,10 @@ errors:
|
|||||||
not_found_sub: This page does not exist.
|
not_found_sub: This page does not exist.
|
||||||
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"
|
app_role_created:
|
||||||
|
subject: Application Role Created
|
||||||
|
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."
|
||||||
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