Merge pull request #1246 from dod-ccpo/log-user-disable-error
Log any CSP errors that occur when disabling a user.
This commit is contained in:
@@ -20,6 +20,7 @@ from atst.domain.permission_sets import PermissionSets
|
|||||||
from atst.utils.flash import formatted_flash as flash
|
from atst.utils.flash import formatted_flash as flash
|
||||||
from atst.utils.localization import translate
|
from atst.utils.localization import translate
|
||||||
from atst.jobs import send_mail
|
from atst.jobs import send_mail
|
||||||
|
from atst.routes.errors import log_error
|
||||||
|
|
||||||
|
|
||||||
def get_environments_obj_for_app(application):
|
def get_environments_obj_for_app(application):
|
||||||
@@ -234,7 +235,8 @@ def handle_update_member(application_id, application_role_id, form_data):
|
|||||||
|
|
||||||
flash("application_member_updated", user_name=app_role.user_name)
|
flash("application_member_updated", user_name=app_role.user_name)
|
||||||
|
|
||||||
except GeneralCSPException:
|
except GeneralCSPException as exc:
|
||||||
|
log_error(exc)
|
||||||
flash(
|
flash(
|
||||||
"application_member_update_error", user_name=app_role.user_name,
|
"application_member_update_error", user_name=app_role.user_name,
|
||||||
)
|
)
|
||||||
|
@@ -12,6 +12,7 @@ from atst.domain.application_roles import ApplicationRoles
|
|||||||
from atst.domain.environment_roles import EnvironmentRoles
|
from atst.domain.environment_roles import EnvironmentRoles
|
||||||
from atst.domain.invitations import ApplicationInvitations
|
from atst.domain.invitations import ApplicationInvitations
|
||||||
from atst.domain.common import Paginator
|
from atst.domain.common import Paginator
|
||||||
|
from atst.domain.csp.cloud import GeneralCSPException
|
||||||
from atst.domain.permission_sets import PermissionSets
|
from atst.domain.permission_sets import PermissionSets
|
||||||
from atst.models.application_role import Status as ApplicationRoleStatus
|
from atst.models.application_role import Status as ApplicationRoleStatus
|
||||||
from atst.models.environment_role import CSPRole, EnvironmentRole
|
from atst.models.environment_role import CSPRole, EnvironmentRole
|
||||||
@@ -748,3 +749,41 @@ def test_handle_update_member(set_g):
|
|||||||
assert len(application.roles) == 1
|
assert len(application.roles) == 1
|
||||||
assert len(app_role.environment_roles) == 1
|
assert len(app_role.environment_roles) == 1
|
||||||
assert app_role.environment_roles[0].environment == env
|
assert app_role.environment_roles[0].environment == env
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_update_member_with_error(set_g, monkeypatch, mock_logger):
|
||||||
|
exception = "An error occurred."
|
||||||
|
|
||||||
|
def _raise_csp_exception(*args, **kwargs):
|
||||||
|
raise GeneralCSPException(exception)
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"atst.domain.environments.Environments.update_env_role", _raise_csp_exception
|
||||||
|
)
|
||||||
|
|
||||||
|
user = UserFactory.create()
|
||||||
|
application = ApplicationFactory.create(
|
||||||
|
environments=[{"name": "Naboo"}, {"name": "Endor"}]
|
||||||
|
)
|
||||||
|
(env, env_1) = application.environments
|
||||||
|
app_role = ApplicationRoleFactory(application=application)
|
||||||
|
set_g("current_user", application.portfolio.owner)
|
||||||
|
set_g("portfolio", application.portfolio)
|
||||||
|
set_g("application", application)
|
||||||
|
|
||||||
|
form_data = ImmutableMultiDict(
|
||||||
|
{
|
||||||
|
"environment_roles-0-environment_id": env.id,
|
||||||
|
"environment_roles-0-role": "Basic Access",
|
||||||
|
"environment_roles-0-environment_name": env.name,
|
||||||
|
"environment_roles-1-environment_id": env_1.id,
|
||||||
|
"environment_roles-1-role": NO_ACCESS,
|
||||||
|
"environment_roles-1-environment_name": env_1.name,
|
||||||
|
"perms_env_mgmt": True,
|
||||||
|
"perms_team_mgmt": True,
|
||||||
|
"perms_del_env": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
handle_update_member(application.id, app_role.id, form_data)
|
||||||
|
|
||||||
|
assert mock_logger.messages[-1] == exception
|
||||||
|
@@ -40,6 +40,9 @@ class FakeLogger:
|
|||||||
def error(self, msg, *args, **kwargs):
|
def error(self, msg, *args, **kwargs):
|
||||||
self._log("error", msg, *args, **kwargs)
|
self._log("error", msg, *args, **kwargs)
|
||||||
|
|
||||||
|
def exception(self, msg, *args, **kwargs):
|
||||||
|
self._log("exception", msg, *args, **kwargs)
|
||||||
|
|
||||||
def _log(self, _lvl, msg, *args, **kwargs):
|
def _log(self, _lvl, msg, *args, **kwargs):
|
||||||
self.messages.append(msg)
|
self.messages.append(msg)
|
||||||
if "extra" in kwargs:
|
if "extra" in kwargs:
|
||||||
|
Reference in New Issue
Block a user