diff --git a/atst/domain/projects.py b/atst/domain/projects.py index 611ee2f9..b3456ddf 100644 --- a/atst/domain/projects.py +++ b/atst/domain/projects.py @@ -8,10 +8,13 @@ from atst.models.project import Project class Projects(object): @classmethod - def create(cls, workspace, name, description, environment_names): + def create(cls, user, workspace, name, description, environment_names): project = Project(workspace=workspace, name=name, description=description) Environments.create_many(project, environment_names) + for environment in project.environments: + Environments.add_member(user, environment, user) + db.session.add(project) db.session.commit() diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py index ecd97bac..e8d0df8d 100644 --- a/atst/routes/workspaces.py +++ b/atst/routes/workspaces.py @@ -112,6 +112,7 @@ def create_project(workspace_id): if form.validate(): project_data = form.data Projects.create( + g.current_user, workspace, project_data["name"], project_data["description"], diff --git a/script/seed.py b/script/seed.py index 01050427..cebe5528 100644 --- a/script/seed.py +++ b/script/seed.py @@ -68,6 +68,7 @@ def seed_db(): Workspaces.create_member(user, workspace, workspace_user) Projects.create( + user, workspace=workspace, name="First Project", description="This is our first project.", diff --git a/tests/domain/test_projects.py b/tests/domain/test_projects.py index 8845c04a..e959d00c 100644 --- a/tests/domain/test_projects.py +++ b/tests/domain/test_projects.py @@ -4,7 +4,7 @@ from tests.factories import WorkspaceFactory def test_create_project_with_multiple_environments(): workspace = WorkspaceFactory.create() - project = Projects.create(workspace, "My Test Project", "Test", ["dev", "prod"]) + project = Projects.create(workspace.owner, workspace, "My Test Project", "Test", ["dev", "prod"]) assert project.workspace == workspace assert project.name == "My Test Project" diff --git a/tests/models/test_environments.py b/tests/models/test_environments.py index 6bb4768f..05be623f 100644 --- a/tests/models/test_environments.py +++ b/tests/models/test_environments.py @@ -10,7 +10,7 @@ def test_add_user_to_environment(): workspace = Workspaces.create(RequestFactory.create(creator=owner)) project = Projects.create( - workspace, "my test project", "It's mine.", ["dev", "staging", "prod"] + owner, workspace, "my test project", "It's mine.", ["dev", "staging", "prod"] ) dev_environment = project.environments[0] diff --git a/tests/models/test_workspace_user.py b/tests/models/test_workspace_user.py index afa8c306..ef2c7749 100644 --- a/tests/models/test_workspace_user.py +++ b/tests/models/test_workspace_user.py @@ -33,7 +33,7 @@ def test_has_environment_roles(): workspace = Workspaces.create(RequestFactory.create(creator=owner)) workspace_user = Workspaces.create_member(owner, workspace, developer_data) project = Projects.create( - workspace, "my test project", "It's mine.", ["dev", "staging", "prod"] + owner, workspace, "my test project", "It's mine.", ["dev", "staging", "prod"] ) Environments.add_member(owner, project.environments[0], workspace_user.user) assert workspace_user.has_environment_roles