Merge "Use domain_context not effective domain to display domains list"

This commit is contained in:
Jenkins 2017-02-15 21:47:39 +00:00 committed by Gerrit Code Review
commit f716d559ad
2 changed files with 9 additions and 18 deletions

View File

@ -39,8 +39,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
@test.create_stubs({api.keystone: ('domain_get', @test.create_stubs({api.keystone: ('domain_get',
'domain_list',)}) 'domain_list',)})
def test_index(self): def test_index(self):
domain = self.domains.get(id="1")
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
self.mox.ReplayAll() self.mox.ReplayAll()
@ -59,8 +57,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
'domain_list', 'domain_list',
'keystone_can_edit_domain')}) 'keystone_can_edit_domain')})
def test_index_with_keystone_can_edit_domain_false(self): def test_index_with_keystone_can_edit_domain_false(self):
domain = self.domains.get(id="1")
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.keystone_can_edit_domain() \ api.keystone.keystone_can_edit_domain() \
.MultipleTimes().AndReturn(False) .MultipleTimes().AndReturn(False)
@ -83,7 +79,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_delete_domain(self): def test_delete_domain(self):
domain = self.domains.get(id="2") domain = self.domains.get(id="2")
api.keystone.domain_get(IsA(http.HttpRequest), '2').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.domain_delete(IgnoreArg(), domain.id) api.keystone.domain_delete(IgnoreArg(), domain.id)
@ -99,7 +94,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_delete_with_enabled_domain(self): def test_delete_with_enabled_domain(self):
domain = self.domains.get(id="1") domain = self.domains.get(id="1")
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
self.mox.ReplayAll() self.mox.ReplayAll()
@ -116,7 +110,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_disable(self): def test_disable(self):
domain = self.domains.get(id="1") domain = self.domains.get(id="1")
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.domain_update(IsA(http.HttpRequest), api.keystone.domain_update(IsA(http.HttpRequest),
description=domain.description, description=domain.description,
@ -138,7 +131,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_enable(self): def test_enable(self):
domain = self.domains.get(id="2") domain = self.domains.get(id="2")
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list()) api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.domain_update(IsA(http.HttpRequest), api.keystone.domain_update(IsA(http.HttpRequest),
description=domain.description, description=domain.description,

View File

@ -38,22 +38,21 @@ class IndexView(tables.DataTableView):
def get_data(self): def get_data(self):
domains = [] domains = []
domain_id = identity.get_domain_id_for_operation(self.request) domain_context = self.request.session.get('domain_context')
if policy.check((("identity", "identity:list_domains"),), if policy.check((
self.request): ("identity", "identity:list_domains"),
), self.request) and not domain_context:
try: try:
if domain_id:
domain = api.keystone.domain_get(self.request, domain_id)
domains.append(domain)
else:
domains = api.keystone.domain_list(self.request) domains = api.keystone.domain_list(self.request)
except Exception: except Exception:
exceptions.handle(self.request, exceptions.handle(self.request,
_('Unable to retrieve domain list.')) _('Unable to retrieve domain list.'))
elif policy.check((("identity", "identity:get_domain"),), elif policy.check((
self.request): ("identity", "identity:get_domain"),
), self.request):
try: try:
domain_id = identity.get_domain_id_for_operation(self.request)
domain = api.keystone.domain_get(self.request, domain_id) domain = api.keystone.domain_get(self.request, domain_id)
domains.append(domain) domains.append(domain)
except Exception: except Exception: