Fix regression in Projects.create
A new project's creator was not being assigned a role in the project's environments.
This commit is contained in:
parent
d0c1bc563f
commit
b65fdd56a0
@ -21,9 +21,13 @@ class Environments(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_many(cls, project, names):
|
def create_many(cls, project, names):
|
||||||
|
environments = []
|
||||||
for name in names:
|
for name in names:
|
||||||
environment = Environment(project=project, name=name)
|
environment = Environment(project=project, name=name)
|
||||||
db.session.add(environment)
|
environments.append(environment)
|
||||||
|
|
||||||
|
db.session.add_all(environments)
|
||||||
|
return environments
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_member(cls, environment, user, role):
|
def add_member(cls, environment, user, role):
|
||||||
@ -31,8 +35,6 @@ class Environments(object):
|
|||||||
user=user, environment=environment, role=role
|
user=user, environment=environment, role=role
|
||||||
)
|
)
|
||||||
db.session.add(environment_user)
|
db.session.add(environment_user)
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
return environment
|
return environment
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -14,10 +14,9 @@ class Projects(object):
|
|||||||
project = Project(workspace=workspace, name=name, description=description)
|
project = Project(workspace=workspace, name=name, description=description)
|
||||||
db.session.add(project)
|
db.session.add(project)
|
||||||
|
|
||||||
Environments.create_many(project, environment_names)
|
environments = Environments.create_many(project, environment_names)
|
||||||
|
for environment in environments:
|
||||||
for environment in project.environments:
|
Environments.add_member(environment, user, "owner")
|
||||||
Environments.add_member(user, environment, user)
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return project
|
return project
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from atst.domain.projects import Projects
|
from atst.domain.projects import Projects
|
||||||
from tests.factories import RequestFactory
|
from tests.factories import RequestFactory, UserFactory
|
||||||
from atst.domain.workspaces import Workspaces
|
from atst.domain.workspaces import Workspaces
|
||||||
|
|
||||||
|
|
||||||
@ -14,3 +14,16 @@ def test_create_project_with_multiple_environments():
|
|||||||
assert project.name == "My Test Project"
|
assert project.name == "My Test Project"
|
||||||
assert project.description == "Test"
|
assert project.description == "Test"
|
||||||
assert sorted(e.name for e in project.environments) == ["dev", "prod"]
|
assert sorted(e.name for e in project.environments) == ["dev", "prod"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_creator_has_environment_access():
|
||||||
|
owner = UserFactory.create()
|
||||||
|
request = RequestFactory.create(creator=owner)
|
||||||
|
workspace = Workspaces.create(request)
|
||||||
|
project = Projects.create(
|
||||||
|
owner, workspace, "My Test Project", "Test", ["dev", "prod"]
|
||||||
|
)
|
||||||
|
|
||||||
|
environment = project.environments[0]
|
||||||
|
|
||||||
|
assert owner in environment.users
|
||||||
|
Loading…
x
Reference in New Issue
Block a user