Use application_role_id on environment_roles.
In the future, an `application_invitation1 will not refer to a `user` until someone accepts the invitation; they'll only reference an `application_role`. When a user is invited to an application, the inviter can specify the environments the invitee should have access to. For this to be possible, an `environment_role` should reference an `application_role`, because no `user` entity will be known at that time. In addition to updating all the models and domain methods necessary for this change, this commit deletes unused code and tests that were dependent on `environment_roles` having a `user_id` foreign key.
This commit is contained in:
@@ -45,6 +45,8 @@ def test_environment_roles():
|
||||
environment = EnvironmentFactory.create(application=application)
|
||||
user = UserFactory.create()
|
||||
application_role = ApplicationRoleFactory.create(application=application, user=user)
|
||||
environment_role = EnvironmentRoleFactory.create(environment=environment, user=user)
|
||||
environment_role = EnvironmentRoleFactory.create(
|
||||
environment=environment, application_role=application_role
|
||||
)
|
||||
|
||||
assert application_role.environment_roles == [environment_role]
|
||||
|
@@ -3,13 +3,7 @@ from atst.models.environment_role import CSPRole
|
||||
from atst.domain.environments import Environments
|
||||
from atst.domain.applications import Applications
|
||||
|
||||
from tests.factories import (
|
||||
PortfolioFactory,
|
||||
UserFactory,
|
||||
EnvironmentFactory,
|
||||
ApplicationFactory,
|
||||
ApplicationRoleFactory,
|
||||
)
|
||||
from tests.factories import *
|
||||
|
||||
|
||||
def test_add_user_to_environment():
|
||||
@@ -22,9 +16,13 @@ def test_add_user_to_environment():
|
||||
)
|
||||
dev_environment = application.environments[0]
|
||||
|
||||
ApplicationRoleFactory.create(user=developer, application=application)
|
||||
dev_environment = Environments.add_member(
|
||||
dev_environment, developer, CSPRole.BASIC_ACCESS.value
|
||||
application_role = ApplicationRoleFactory.create(
|
||||
user=developer, application=application
|
||||
)
|
||||
EnvironmentRoleFactory.create(
|
||||
application_role=application_role,
|
||||
environment=dev_environment,
|
||||
role=CSPRole.BASIC_ACCESS.value,
|
||||
)
|
||||
assert developer in dev_environment.users
|
||||
|
||||
|
@@ -8,16 +8,7 @@ from atst.domain.applications import Applications
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.models import AuditEvent, InvitationStatus, PortfolioRoleStatus, CSPRole
|
||||
|
||||
from tests.factories import (
|
||||
UserFactory,
|
||||
PortfolioInvitationFactory,
|
||||
PortfolioRoleFactory,
|
||||
EnvironmentFactory,
|
||||
EnvironmentRoleFactory,
|
||||
ApplicationFactory,
|
||||
ApplicationRoleFactory,
|
||||
PortfolioFactory,
|
||||
)
|
||||
from tests.factories import *
|
||||
from atst.domain.portfolio_roles import PortfolioRoles
|
||||
|
||||
|
||||
@@ -97,8 +88,9 @@ def test_has_no_env_role_history(session):
|
||||
application=application, name="new environment!"
|
||||
)
|
||||
|
||||
app_role = ApplicationRoleFactory.create(user=user, application=application)
|
||||
env_role = EnvironmentRoleFactory.create(
|
||||
user=user, environment=environment, role="developer"
|
||||
application_role=app_role, environment=environment, role="developer"
|
||||
)
|
||||
create_event = (
|
||||
session.query(AuditEvent)
|
||||
@@ -110,22 +102,24 @@ def test_has_no_env_role_history(session):
|
||||
|
||||
|
||||
def test_has_env_role_history(session):
|
||||
owner = UserFactory.create()
|
||||
user = UserFactory.create()
|
||||
portfolio = PortfolioFactory.create(owner=owner)
|
||||
portfolio_role = PortfolioRoleFactory.create(portfolio=portfolio, user=user)
|
||||
application = ApplicationFactory.create(portfolio=portfolio)
|
||||
ApplicationRoleFactory.create(user=user, application=application)
|
||||
application = ApplicationFactory.create()
|
||||
app_role = ApplicationRoleFactory.create(user=user, application=application)
|
||||
environment = EnvironmentFactory.create(
|
||||
application=application, name="new environment!"
|
||||
)
|
||||
|
||||
env_role = EnvironmentRoleFactory.create(
|
||||
user=user, environment=environment, role="developer"
|
||||
)
|
||||
Environments.update_env_roles_by_member(
|
||||
user, [{"role": "admin", "id": environment.id}]
|
||||
application_role=app_role, environment=environment, role="developer"
|
||||
)
|
||||
session.add(env_role)
|
||||
session.commit()
|
||||
session.refresh(env_role)
|
||||
|
||||
env_role.role = "admin"
|
||||
session.add(env_role)
|
||||
session.commit()
|
||||
|
||||
changed_events = (
|
||||
session.query(AuditEvent)
|
||||
.filter(AuditEvent.resource_id == env_role.id, AuditEvent.action == "update")
|
||||
@@ -147,44 +141,6 @@ def test_event_details():
|
||||
assert portfolio_role.event_details["updated_user_id"] == str(user.id)
|
||||
|
||||
|
||||
def test_has_no_environment_roles():
|
||||
owner = UserFactory.create()
|
||||
developer_data = {
|
||||
"dod_id": "1234567890",
|
||||
"first_name": "Test",
|
||||
"last_name": "User",
|
||||
"email": "test.user@mail.com",
|
||||
"portfolio_role": "developer",
|
||||
}
|
||||
|
||||
portfolio = PortfolioFactory.create(owner=owner)
|
||||
portfolio_role = Portfolios.create_member(portfolio, developer_data)
|
||||
|
||||
assert not portfolio_role.has_environment_roles
|
||||
|
||||
|
||||
def test_has_environment_roles():
|
||||
owner = UserFactory.create()
|
||||
developer_data = {
|
||||
"dod_id": "1234567890",
|
||||
"first_name": "Test",
|
||||
"last_name": "User",
|
||||
"email": "test.user@mail.com",
|
||||
"portfolio_role": "developer",
|
||||
}
|
||||
|
||||
portfolio = PortfolioFactory.create(owner=owner)
|
||||
portfolio_role = Portfolios.create_member(portfolio, developer_data)
|
||||
application = Applications.create(
|
||||
portfolio, "my test application", "It's mine.", ["dev", "staging", "prod"]
|
||||
)
|
||||
ApplicationRoleFactory.create(user=portfolio_role.user, application=application)
|
||||
Environments.add_member(
|
||||
application.environments[0], portfolio_role.user, CSPRole.BASIC_ACCESS.value
|
||||
)
|
||||
assert portfolio_role.has_environment_roles
|
||||
|
||||
|
||||
def test_status_when_member_is_active():
|
||||
portfolio_role = PortfolioRoleFactory.create(status=PortfolioRoleStatus.ACTIVE)
|
||||
assert portfolio_role.display_status == "Active"
|
||||
|
Reference in New Issue
Block a user