Fixes bug when getting hierarchy on Project API

GET /v3/projects/project_id?parents_as_list and
GET /v3/projects/project_id?subtree_as_list
should return only the projects in the hierarchy
the user has access to.

This patch fixes a bug in which all projects in
the hierarchy are always returned.

Co-Authored-By: Raildo Mascena <raildo@lsd.ufcg.edu.br>

Closes-Bug: #1434916

Change-Id: I1b2403b9b2af510f127ce1ea47604d53eef3850c
This commit is contained in:
Samuel de Medeiros Queiroz 2015-03-24 09:58:35 -03:00
parent fe31e5283e
commit 5b38ec1344
2 changed files with 4 additions and 7 deletions

View File

@ -241,15 +241,15 @@ class Manager(manager.Manager):
user_projects = self.assignment_api.list_projects_for_user(user_id)
user_projects_ids = set([proj['id'] for proj in user_projects])
# Keep only the projects present in user_projects
projects_list = [proj for proj in projects_list
if proj['id'] in user_projects_ids]
return [proj for proj in projects_list
if proj['id'] in user_projects_ids]
def list_project_parents(self, project_id, user_id=None):
parents = self.driver.list_project_parents(project_id)
# If a user_id was provided, the returned list should be filtered
# against the projects this user has access to.
if user_id:
self._filter_projects_list(parents, user_id)
parents = self._filter_projects_list(parents, user_id)
return parents
def _build_parents_as_ids_dict(self, project, parents_by_id):
@ -300,7 +300,7 @@ class Manager(manager.Manager):
# If a user_id was provided, the returned list should be filtered
# against the projects this user has access to.
if user_id:
self._filter_projects_list(subtree, user_id)
subtree = self._filter_projects_list(subtree, user_id)
return subtree
def _build_subtree_as_ids_dict(self, project_id, subtree_by_parent):

View File

@ -20,7 +20,6 @@ from keystone.common import controller
from keystone import exception
from keystone.tests import unit as tests
from keystone.tests.unit import test_v3
from keystone.tests.unit import utils as test_utils
CONF = cfg.CONF
@ -725,7 +724,6 @@ class AssignmentTestCase(test_v3.RestfulTestCase):
self.assertIn(parent, r.result['project']['parents'])
self.assertEqual(2, len(r.result['project']['parents']))
@test_utils.wip('Waiting on bug #1434916')
def test_get_project_with_parents_as_list_with_partial_access(self):
"""``GET /projects/{project_id}?parents_as_list`` with partial access.
@ -909,7 +907,6 @@ class AssignmentTestCase(test_v3.RestfulTestCase):
self.assertIn(subproject, r.result['project']['subtree'])
self.assertEqual(2, len(r.result['project']['subtree']))
@test_utils.wip('Waiting on bug #1434916')
def test_get_project_with_subtree_as_list_with_partial_access(self):
"""``GET /projects/{project_id}?subtree_as_list`` with partial access.