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):
|
class Projects(object):
|
||||||
@classmethod
|
@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)
|
project = Project(workspace=workspace, name=name, description=description)
|
||||||
Environments.create_many(project, environment_names)
|
Environments.create_many(project, environment_names)
|
||||||
|
|
||||||
|
for environment in project.environments:
|
||||||
|
Environments.add_member(user, environment, user)
|
||||||
|
|
||||||
db.session.add(project)
|
db.session.add(project)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ def create_project(workspace_id):
|
|||||||
if form.validate():
|
if form.validate():
|
||||||
project_data = form.data
|
project_data = form.data
|
||||||
Projects.create(
|
Projects.create(
|
||||||
|
g.current_user,
|
||||||
workspace,
|
workspace,
|
||||||
project_data["name"],
|
project_data["name"],
|
||||||
project_data["description"],
|
project_data["description"],
|
||||||
|
@ -68,6 +68,7 @@ def seed_db():
|
|||||||
Workspaces.create_member(user, workspace, workspace_user)
|
Workspaces.create_member(user, workspace, workspace_user)
|
||||||
|
|
||||||
Projects.create(
|
Projects.create(
|
||||||
|
user,
|
||||||
workspace=workspace,
|
workspace=workspace,
|
||||||
name="First Project",
|
name="First Project",
|
||||||
description="This is our first project.",
|
description="This is our first project.",
|
||||||
|
@ -4,7 +4,7 @@ from tests.factories import WorkspaceFactory
|
|||||||
|
|
||||||
def test_create_project_with_multiple_environments():
|
def test_create_project_with_multiple_environments():
|
||||||
workspace = WorkspaceFactory.create()
|
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.workspace == workspace
|
||||||
assert project.name == "My Test Project"
|
assert project.name == "My Test Project"
|
||||||
|
@ -10,7 +10,7 @@ def test_add_user_to_environment():
|
|||||||
|
|
||||||
workspace = Workspaces.create(RequestFactory.create(creator=owner))
|
workspace = Workspaces.create(RequestFactory.create(creator=owner))
|
||||||
project = Projects.create(
|
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]
|
dev_environment = project.environments[0]
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ def test_has_environment_roles():
|
|||||||
workspace = Workspaces.create(RequestFactory.create(creator=owner))
|
workspace = Workspaces.create(RequestFactory.create(creator=owner))
|
||||||
workspace_user = Workspaces.create_member(owner, workspace, developer_data)
|
workspace_user = Workspaces.create_member(owner, workspace, developer_data)
|
||||||
project = Projects.create(
|
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)
|
Environments.add_member(owner, project.environments[0], workspace_user.user)
|
||||||
assert workspace_user.has_environment_roles
|
assert workspace_user.has_environment_roles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user