Automatically assign workspace owner to environments
This commit is contained in:
parent
59a5b2da5a
commit
996596f2b3
@ -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()
|
||||
|
||||
|
@ -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"],
|
||||
|
@ -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.",
|
||||
|
@ -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"
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user