Use domain_context not effective domain to display domains list

Use domain_context to decide whether to call domain_list or domain_get
in the list of domains. Previous code used the user's effective domain
instead, which is no longer the same thing with Keystone V3.

Closes-Bug: #1660602

Change-Id: Ie410d282c5b19a061fe83b496785f35bbcfad9ad
This commit is contained in:
Radomir Dopieralski 2017-01-31 13:01:51 +01:00
parent c40fe6b31f
commit 1be065aed8
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',
'domain_list',)})
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())
self.mox.ReplayAll()
@ -59,8 +57,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
'domain_list',
'keystone_can_edit_domain')})
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.keystone_can_edit_domain() \
.MultipleTimes().AndReturn(False)
@ -83,7 +79,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_delete_domain(self):
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_delete(IgnoreArg(), domain.id)
@ -99,7 +94,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_delete_with_enabled_domain(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())
self.mox.ReplayAll()
@ -116,7 +110,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_disable(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_update(IsA(http.HttpRequest),
description=domain.description,
@ -138,7 +131,6 @@ class DomainsViewTests(test.BaseAdminViewTests):
def test_enable(self):
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_update(IsA(http.HttpRequest),
description=domain.description,

View File

@ -38,22 +38,21 @@ class IndexView(tables.DataTableView):
def get_data(self):
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"),),
self.request):
if policy.check((
("identity", "identity:list_domains"),
), self.request) and not domain_context:
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:
exceptions.handle(self.request,
_('Unable to retrieve domain list.'))
elif policy.check((("identity", "identity:get_domain"),),
self.request):
elif policy.check((
("identity", "identity:get_domain"),
), self.request):
try:
domain_id = identity.get_domain_id_for_operation(self.request)
domain = api.keystone.domain_get(self.request, domain_id)
domains.append(domain)
except Exception: