summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2017-02-01 15:23:34 +0100
committerRichard Jones <r1chardj0n3s@gmail.com>2017-02-15 22:37:52 +0000
commit1227d3eb1407c03e0005cdf8c705d86189491cbd (patch)
treef025964805ffad6ddff7deb0b9002ea91bbdcfd3
parentbef9bfe05a89d47de3c5bf0ba9981623ee558fbe (diff)
Disentangle domain context from effective domain
Since the existence of a domain token was equivalent with having selected a domain context with Keystone V2, some code confuses the two. This is no longer true for Kestone V3, so we have to separate the two concepts and use domain context when we mean the domain context. Close-bug: #1661537 Change-Id: Ifa66d8c397e34d16a4534e7216eb11c752699505 (cherry picked from commit 8b839938bca245fcb36988ce6dcd3f5d0d96cf3b)
Notes
Notes (review): Code-Review+2: David Lyle <dklyle0@gmail.com> Code-Review+1: alfred <chenjhfrontend@163.com> Code-Review+1: Kenji Ishii <ken-ishii@sx.jp.nec.com> Code-Review+1: daijing <daijing@awcloud.com> Code-Review+2: Rob Cresswell <robert.cresswell@outlook.com> Workflow+1: Rob Cresswell <robert.cresswell@outlook.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 16 Feb 2017 06:25:00 +0000 Reviewed-on: https://review.openstack.org/434542 Project: openstack/horizon Branch: refs/heads/stable/ocata
-rw-r--r--openstack_dashboard/dashboards/identity/domains/views.py3
-rw-r--r--openstack_dashboard/dashboards/identity/groups/forms.py5
-rw-r--r--openstack_dashboard/dashboards/identity/groups/tests.py8
-rw-r--r--openstack_dashboard/dashboards/identity/groups/views.py6
-rw-r--r--openstack_dashboard/dashboards/identity/projects/tests.py3
-rw-r--r--openstack_dashboard/dashboards/identity/projects/views.py5
-rw-r--r--openstack_dashboard/dashboards/identity/projects/workflows.py3
-rw-r--r--openstack_dashboard/dashboards/identity/users/tests.py8
-rw-r--r--openstack_dashboard/dashboards/identity/users/views.py5
-rw-r--r--openstack_dashboard/utils/identity.py28
10 files changed, 49 insertions, 25 deletions
diff --git a/openstack_dashboard/dashboards/identity/domains/views.py b/openstack_dashboard/dashboards/identity/domains/views.py
index 16ddec8..b1301cf 100644
--- a/openstack_dashboard/dashboards/identity/domains/views.py
+++ b/openstack_dashboard/dashboards/identity/domains/views.py
@@ -28,6 +28,7 @@ from openstack_dashboard.dashboards.identity.domains \
28 import tables as project_tables 28 import tables as project_tables
29from openstack_dashboard.dashboards.identity.domains \ 29from openstack_dashboard.dashboards.identity.domains \
30 import workflows as project_workflows 30 import workflows as project_workflows
31from openstack_dashboard.utils import identity
31 32
32 33
33class IndexView(tables.DataTableView): 34class IndexView(tables.DataTableView):
@@ -37,7 +38,7 @@ class IndexView(tables.DataTableView):
37 38
38 def get_data(self): 39 def get_data(self):
39 domains = [] 40 domains = []
40 domain_id = api.keystone.get_effective_domain_id(self.request) 41 domain_id = identity.get_domain_id_for_operation(self.request)
41 42
42 if policy.check((("identity", "identity:list_domains"),), 43 if policy.check((("identity", "identity:list_domains"),),
43 self.request): 44 self.request):
diff --git a/openstack_dashboard/dashboards/identity/groups/forms.py b/openstack_dashboard/dashboards/identity/groups/forms.py
index e0041be..379d83f 100644
--- a/openstack_dashboard/dashboards/identity/groups/forms.py
+++ b/openstack_dashboard/dashboards/identity/groups/forms.py
@@ -21,6 +21,7 @@ from horizon import forms
21from horizon import messages 21from horizon import messages
22 22
23from openstack_dashboard import api 23from openstack_dashboard import api
24from openstack_dashboard.utils import identity as identity_utils
24 25
25 26
26LOG = logging.getLogger(__name__) 27LOG = logging.getLogger(__name__)
@@ -36,10 +37,10 @@ class CreateGroupForm(forms.SelfHandlingForm):
36 def handle(self, request, data): 37 def handle(self, request, data):
37 try: 38 try:
38 LOG.info('Creating group with name "%s"' % data['name']) 39 LOG.info('Creating group with name "%s"' % data['name'])
39 domain_context = api.keystone.get_effective_domain_id(request)
40 api.keystone.group_create( 40 api.keystone.group_create(
41 request, 41 request,
42 domain_id=domain_context, 42 domain_id=identity_utils.get_domain_id_for_operation(
43 self.request),
43 name=data['name'], 44 name=data['name'],
44 description=data['description']) 45 description=data['description'])
45 messages.success(request, 46 messages.success(request,
diff --git a/openstack_dashboard/dashboards/identity/groups/tests.py b/openstack_dashboard/dashboards/identity/groups/tests.py
index f542681..0f9fb2c 100644
--- a/openstack_dashboard/dashboards/identity/groups/tests.py
+++ b/openstack_dashboard/dashboards/identity/groups/tests.py
@@ -49,8 +49,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
49 domain_id = self._get_domain_id() 49 domain_id = self._get_domain_id()
50 groups = self._get_groups(domain_id) 50 groups = self._get_groups(domain_id)
51 filters = {} 51 filters = {}
52 domain = self.domains.get(id="1")
53 api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
54 api.keystone.group_list(IgnoreArg(), 52 api.keystone.group_list(IgnoreArg(),
55 domain=domain_id, 53 domain=domain_id,
56 filters=filters) \ 54 filters=filters) \
@@ -79,8 +77,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
79 domain_context_name=domain.name) 77 domain_context_name=domain.name)
80 groups = self._get_groups(domain.id) 78 groups = self._get_groups(domain.id)
81 79
82 api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain.id)
83
84 api.keystone.group_list(IsA(http.HttpRequest), 80 api.keystone.group_list(IsA(http.HttpRequest),
85 domain=domain.id, 81 domain=domain.id,
86 filters=filters).AndReturn(groups) 82 filters=filters).AndReturn(groups)
@@ -105,9 +101,7 @@ class GroupsViewTests(test.BaseAdminViewTests):
105 def test_index_with_keystone_can_edit_group_false(self): 101 def test_index_with_keystone_can_edit_group_false(self):
106 domain_id = self._get_domain_id() 102 domain_id = self._get_domain_id()
107 groups = self._get_groups(domain_id) 103 groups = self._get_groups(domain_id)
108 domain = self.domains.get(id="1")
109 filters = {} 104 filters = {}
110 api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
111 api.keystone.group_list(IgnoreArg(), 105 api.keystone.group_list(IgnoreArg(),
112 domain=domain_id, 106 domain=domain_id,
113 filters=filters) \ 107 filters=filters) \
@@ -204,8 +198,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
204 filters = {} 198 filters = {}
205 group = self.groups.get(id="2") 199 group = self.groups.get(id="2")
206 200
207 domain = self.domains.get(id="1")
208 api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
209 api.keystone.group_list(IgnoreArg(), 201 api.keystone.group_list(IgnoreArg(),
210 domain=domain_id, 202 domain=domain_id,
211 filters=filters) \ 203 filters=filters) \
diff --git a/openstack_dashboard/dashboards/identity/groups/views.py b/openstack_dashboard/dashboards/identity/groups/views.py
index 13332f4..1fb72cd 100644
--- a/openstack_dashboard/dashboards/identity/groups/views.py
+++ b/openstack_dashboard/dashboards/identity/groups/views.py
@@ -31,6 +31,7 @@ from openstack_dashboard.dashboards.identity.groups \
31 import forms as project_forms 31 import forms as project_forms
32from openstack_dashboard.dashboards.identity.groups \ 32from openstack_dashboard.dashboards.identity.groups \
33 import tables as project_tables 33 import tables as project_tables
34from openstack_dashboard.utils import identity
34 35
35 36
36class IndexView(tables.DataTableView): 37class IndexView(tables.DataTableView):
@@ -58,8 +59,7 @@ class IndexView(tables.DataTableView):
58 self._needs_filter_first = True 59 self._needs_filter_first = True
59 return groups 60 return groups
60 61
61 domain_id = api.keystone.get_effective_domain_id(self.request) 62 domain_id = identity.get_domain_id_for_operation(self.request)
62
63 try: 63 try:
64 groups = api.keystone.group_list(self.request, 64 groups = api.keystone.group_list(self.request,
65 domain=domain_id, 65 domain=domain_id,
@@ -125,7 +125,7 @@ class GroupManageMixin(object):
125 @memoized.memoized_method 125 @memoized.memoized_method
126 def _get_group_members(self): 126 def _get_group_members(self):
127 group_id = self.kwargs['group_id'] 127 group_id = self.kwargs['group_id']
128 domain_id = api.keystone.get_effective_domain_id(self.request) 128 domain_id = identity.get_domain_id_for_operation(self.request)
129 return api.keystone.user_list(self.request, domain=domain_id, 129 return api.keystone.user_list(self.request, domain=domain_id,
130 group=group_id) 130 group=group_id)
131 131
diff --git a/openstack_dashboard/dashboards/identity/projects/tests.py b/openstack_dashboard/dashboards/identity/projects/tests.py
index 08c476e..d3d52a3 100644
--- a/openstack_dashboard/dashboards/identity/projects/tests.py
+++ b/openstack_dashboard/dashboards/identity/projects/tests.py
@@ -49,7 +49,6 @@ class TenantsViewTests(test.BaseAdminViewTests):
49 def test_index(self): 49 def test_index(self):
50 domain = self.domains.get(id="1") 50 domain = self.domains.get(id="1")
51 filters = {} 51 filters = {}
52 api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
53 api.keystone.tenant_list(IsA(http.HttpRequest), 52 api.keystone.tenant_list(IsA(http.HttpRequest),
54 domain=None, 53 domain=None,
55 paginate=True, 54 paginate=True,
@@ -79,8 +78,6 @@ class TenantsViewTests(test.BaseAdminViewTests):
79 domain_tenants = [tenant for tenant in self.tenants.list() 78 domain_tenants = [tenant for tenant in self.tenants.list()
80 if tenant.domain_id == domain.id] 79 if tenant.domain_id == domain.id]
81 80
82 api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain.id)
83
84 api.keystone.tenant_list(IsA(http.HttpRequest), 81 api.keystone.tenant_list(IsA(http.HttpRequest),
85 domain=domain.id, 82 domain=domain.id,
86 paginate=True, 83 paginate=True,
diff --git a/openstack_dashboard/dashboards/identity/projects/views.py b/openstack_dashboard/dashboards/identity/projects/views.py
index 405c546..95f66b1 100644
--- a/openstack_dashboard/dashboards/identity/projects/views.py
+++ b/openstack_dashboard/dashboards/identity/projects/views.py
@@ -39,6 +39,7 @@ from openstack_dashboard.dashboards.identity.projects \
39 import workflows as project_workflows 39 import workflows as project_workflows
40from openstack_dashboard.dashboards.project.overview \ 40from openstack_dashboard.dashboards.project.overview \
41 import views as project_views 41 import views as project_views
42from openstack_dashboard.utils import identity
42 43
43PROJECT_INFO_FIELDS = ("domain_id", 44PROJECT_INFO_FIELDS = ("domain_id",
44 "domain_name", 45 "domain_name",
@@ -99,11 +100,11 @@ class IndexView(tables.DataTableView):
99 self._more = False 100 self._more = False
100 return tenants 101 return tenants
101 102
102 domain_context = api.keystone.get_effective_domain_id(self.request) 103 domain_id = identity.get_domain_id_for_operation(self.request)
103 try: 104 try:
104 tenants, self._more = api.keystone.tenant_list( 105 tenants, self._more = api.keystone.tenant_list(
105 self.request, 106 self.request,
106 domain=domain_context, 107 domain=domain_id,
107 paginate=True, 108 paginate=True,
108 filters=filters, 109 filters=filters,
109 marker=marker) 110 marker=marker)
diff --git a/openstack_dashboard/dashboards/identity/projects/workflows.py b/openstack_dashboard/dashboards/identity/projects/workflows.py
index ad05218..d031db6 100644
--- a/openstack_dashboard/dashboards/identity/projects/workflows.py
+++ b/openstack_dashboard/dashboards/identity/projects/workflows.py
@@ -35,6 +35,7 @@ from openstack_dashboard.api import cinder
35from openstack_dashboard.api import keystone 35from openstack_dashboard.api import keystone
36from openstack_dashboard.api import nova 36from openstack_dashboard.api import nova
37from openstack_dashboard.usage import quotas 37from openstack_dashboard.usage import quotas
38from openstack_dashboard.utils import identity as identity
38 39
39 40
40LOG = logging.getLogger(__name__) 41LOG = logging.getLogger(__name__)
@@ -677,7 +678,7 @@ class UpdateProject(CommonQuotaWorkflow):
677 678
678 def _update_project(self, request, data): 679 def _update_project(self, request, data):
679 """Update project info""" 680 """Update project info"""
680 domain_id = api.keystone.get_effective_domain_id(self.request) 681 domain_id = identity.get_domain_id_for_operation(request)
681 try: 682 try:
682 project_id = data['project_id'] 683 project_id = data['project_id']
683 684
diff --git a/openstack_dashboard/dashboards/identity/users/tests.py b/openstack_dashboard/dashboards/identity/users/tests.py
index 1d5ecd1..10db5e8 100644
--- a/openstack_dashboard/dashboards/identity/users/tests.py
+++ b/openstack_dashboard/dashboards/identity/users/tests.py
@@ -57,13 +57,15 @@ class UsersViewTests(test.BaseAdminViewTests):
57 @test.create_stubs({api.keystone: ('user_list', 57 @test.create_stubs({api.keystone: ('user_list',
58 'get_effective_domain_id', 58 'get_effective_domain_id',
59 'domain_lookup')}) 59 'domain_lookup')})
60 def test_index(self): 60 def test_index(self, with_domain=False):
61 domain = self._get_default_domain() 61 domain = self._get_default_domain()
62 domain_id = domain.id 62 domain_id = domain.id
63 filters = {} 63 filters = {}
64 users = self._get_users(domain_id) 64 users = self._get_users(domain_id)
65 65
66 api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain_id) 66 if not with_domain:
67 api.keystone.get_effective_domain_id(
68 IgnoreArg()).AndReturn(domain_id)
67 69
68 api.keystone.user_list(IgnoreArg(), 70 api.keystone.user_list(IgnoreArg(),
69 domain=domain_id, 71 domain=domain_id,
@@ -84,7 +86,7 @@ class UsersViewTests(test.BaseAdminViewTests):
84 domain = self.domains.get(id="1") 86 domain = self.domains.get(id="1")
85 self.setSessionValues(domain_context=domain.id, 87 self.setSessionValues(domain_context=domain.id,
86 domain_context_name=domain.name) 88 domain_context_name=domain.name)
87 self.test_index() 89 self.test_index(with_domain=True)
88 90
89 @override_settings(USER_TABLE_EXTRA_INFO={'phone_num': 'Phone Number'}) 91 @override_settings(USER_TABLE_EXTRA_INFO={'phone_num': 'Phone Number'})
90 @test.create_stubs({api.keystone: ('user_create', 92 @test.create_stubs({api.keystone: ('user_create',
diff --git a/openstack_dashboard/dashboards/identity/users/views.py b/openstack_dashboard/dashboards/identity/users/views.py
index ea7af63..bda08c9 100644
--- a/openstack_dashboard/dashboards/identity/users/views.py
+++ b/openstack_dashboard/dashboards/identity/users/views.py
@@ -40,6 +40,7 @@ from openstack_dashboard.dashboards.identity.users \
40 import forms as project_forms 40 import forms as project_forms
41from openstack_dashboard.dashboards.identity.users \ 41from openstack_dashboard.dashboards.identity.users \
42 import tables as project_tables 42 import tables as project_tables
43from openstack_dashboard.utils import identity
43 44
44LOG = logging.getLogger(__name__) 45LOG = logging.getLogger(__name__)
45 46
@@ -69,10 +70,10 @@ class IndexView(tables.DataTableView):
69 self._needs_filter_first = True 70 self._needs_filter_first = True
70 return users 71 return users
71 72
72 domain_context = api.keystone.get_effective_domain_id(self.request) 73 domain_id = identity.get_domain_id_for_operation(self.request)
73 try: 74 try:
74 users = api.keystone.user_list(self.request, 75 users = api.keystone.user_list(self.request,
75 domain=domain_context, 76 domain=domain_id,
76 filters=filters) 77 filters=filters)
77 except Exception: 78 except Exception:
78 exceptions.handle(self.request, 79 exceptions.handle(self.request,
diff --git a/openstack_dashboard/utils/identity.py b/openstack_dashboard/utils/identity.py
new file mode 100644
index 0000000..cef1f0e
--- /dev/null
+++ b/openstack_dashboard/utils/identity.py
@@ -0,0 +1,28 @@
1# Copyright 2017 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from openstack_dashboard import api
16
17
18def get_domain_id_for_operation(request):
19 """Get the ID of the domain in which the current operation should happen.
20
21 If the user has a domain context set, use that, otherwise use the user's
22 effective domain.
23 """
24
25 domain_context = request.session.get('domain_context')
26 if domain_context:
27 return domain_context
28 return api.keystone.get_effective_domain_id(request)