Check workspace permissions, not project

This commit is contained in:
richard-dds 2018-09-10 14:01:36 -04:00
parent df84f1959a
commit 79ba272f70
2 changed files with 8 additions and 10 deletions

View File

@ -52,7 +52,7 @@ class ScopedProject(ScopedResource):
@property @property
def environments(self): def environments(self):
can_view_all_environments = Authorization.has_workspace_permission( can_view_all_environments = Authorization.has_workspace_permission(
self.user, self.resource, Permissions.VIEW_ENVIRONMENT_IN_APPLICATION self.user, self.resource.workspace, Permissions.VIEW_ENVIRONMENT_IN_APPLICATION
) )
if can_view_all_environments: if can_view_all_environments:

View File

@ -203,7 +203,7 @@ def test_scoped_workspace_only_returns_users_projects_and_environments():
assert scoped_workspace.projects[0].environments == [dev_environment] assert scoped_workspace.projects[0].environments == [dev_environment]
def test_scoped_workspace_returns_all_projects_for_ccpo(): def test_scoped_workspace_returns_all_projects_for_workspace_admin():
workspace = Workspaces.create(RequestFactory.create()) workspace = Workspaces.create(RequestFactory.create())
for _ in range(5): for _ in range(5):
Projects.create( Projects.create(
@ -214,8 +214,10 @@ def test_scoped_workspace_returns_all_projects_for_ccpo():
["dev", "staging", "prod"], ["dev", "staging", "prod"],
) )
ccpo = UserFactory.from_atat_role("ccpo") admin = Workspaces.add_member(
scoped_workspace = Workspaces.get(ccpo, workspace.id) workspace, UserFactory.from_atat_role("default"), "admin"
).user
scoped_workspace = Workspaces.get(admin, workspace.id)
assert len(scoped_workspace.projects) == 5 assert len(scoped_workspace.projects) == 5
assert len(scoped_workspace.projects[0].environments) == 3 assert len(scoped_workspace.projects[0].environments) == 3
@ -223,16 +225,12 @@ def test_scoped_workspace_returns_all_projects_for_ccpo():
def test_scoped_workspace_returns_all_projects_for_workspace_owner(): def test_scoped_workspace_returns_all_projects_for_workspace_owner():
workspace = Workspaces.create(RequestFactory.create()) workspace = Workspaces.create(RequestFactory.create())
owner = workspace.owner
for _ in range(5): for _ in range(5):
Projects.create( Projects.create(
workspace.owner, owner, workspace, "My Project", "My project", ["dev", "staging", "prod"]
workspace,
"My Project",
"My project",
["dev", "staging", "prod"],
) )
owner = UserFactory.from_atat_role("owner")
scoped_workspace = Workspaces.get(owner, workspace.id) scoped_workspace = Workspaces.get(owner, workspace.id)
assert len(scoped_workspace.projects) == 5 assert len(scoped_workspace.projects) == 5