Prevent error from being raised when user is not trying to update a
disabled env role We were only checking to see if a role was disabled or deleted before raising an error, so I added in a check to see if the user was trying to update the env role before raising an error. The error should only be raised if the role is disabled or deleted AND the user is trying to assign a new role to the env role. I also added in a disabled property to the EnvironmentRole model to make things more readable.
This commit is contained in:
@@ -88,7 +88,7 @@ def test_disable_completed(application_role, environment):
|
||||
|
||||
environment_role = EnvironmentRoles.disable(environment_role.id)
|
||||
|
||||
assert environment_role.status == EnvironmentRole.Status.DISABLED
|
||||
assert environment_role.disabled
|
||||
|
||||
|
||||
def test_get_for_update(application_role, environment):
|
||||
|
@@ -42,21 +42,26 @@ def test_update_env_role_no_access():
|
||||
env_role.application_role.id, env_role.environment.id
|
||||
)
|
||||
assert env_role.role is None
|
||||
assert env_role.status == EnvironmentRole.Status.DISABLED
|
||||
assert env_role.disabled
|
||||
|
||||
|
||||
def test_update_env_role_disabled_role():
|
||||
env_role = EnvironmentRoleFactory.create(role=CSPRole.BASIC_ACCESS.value)
|
||||
Environments.update_env_role(env_role.environment, env_role.application_role, None)
|
||||
|
||||
# An exception should be raised when a new role is passed to Environments.update_env_role
|
||||
with pytest.raises(DisabledError):
|
||||
Environments.update_env_role(
|
||||
env_role.environment,
|
||||
env_role.application_role,
|
||||
CSPRole.TECHNICAL_READ.value,
|
||||
)
|
||||
|
||||
assert env_role.role is None
|
||||
assert env_role.status == EnvironmentRole.Status.DISABLED
|
||||
assert env_role.disabled
|
||||
|
||||
# An exception should not be raised when no new role is passed
|
||||
Environments.update_env_role(env_role.environment, env_role.application_role, None)
|
||||
|
||||
|
||||
def test_get_excludes_deleted():
|
||||
|
@@ -563,7 +563,7 @@ def test_update_member(client, user_session, session):
|
||||
# check that the user has roles in the correct envs
|
||||
assert len(environment_roles) == 3
|
||||
assert updated_role.role == CSPRole.TECHNICAL_READ.value
|
||||
assert suspended_role.status == EnvironmentRole.Status.DISABLED
|
||||
assert suspended_role.disabled
|
||||
|
||||
|
||||
def test_revoke_invite(client, user_session):
|
||||
|
Reference in New Issue
Block a user