Merge "Disentangle domain context from effective domain"
This commit is contained in:
commit
392ddec13b
@ -28,6 +28,7 @@ from openstack_dashboard.dashboards.identity.domains \
|
|||||||
import tables as project_tables
|
import tables as project_tables
|
||||||
from openstack_dashboard.dashboards.identity.domains \
|
from openstack_dashboard.dashboards.identity.domains \
|
||||||
import workflows as project_workflows
|
import workflows as project_workflows
|
||||||
|
from openstack_dashboard.utils import identity
|
||||||
|
|
||||||
|
|
||||||
class IndexView(tables.DataTableView):
|
class IndexView(tables.DataTableView):
|
||||||
@ -37,7 +38,7 @@ class IndexView(tables.DataTableView):
|
|||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
domains = []
|
domains = []
|
||||||
domain_id = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(self.request)
|
||||||
|
|
||||||
if policy.check((("identity", "identity:list_domains"),),
|
if policy.check((("identity", "identity:list_domains"),),
|
||||||
self.request):
|
self.request):
|
||||||
|
@ -21,6 +21,7 @@ from horizon import forms
|
|||||||
from horizon import messages
|
from horizon import messages
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
|
from openstack_dashboard.utils import identity as identity_utils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -36,10 +37,10 @@ class CreateGroupForm(forms.SelfHandlingForm):
|
|||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
try:
|
try:
|
||||||
LOG.info('Creating group with name "%s"' % data['name'])
|
LOG.info('Creating group with name "%s"' % data['name'])
|
||||||
domain_context = api.keystone.get_effective_domain_id(request)
|
|
||||||
api.keystone.group_create(
|
api.keystone.group_create(
|
||||||
request,
|
request,
|
||||||
domain_id=domain_context,
|
domain_id=identity_utils.get_domain_id_for_operation(
|
||||||
|
self.request),
|
||||||
name=data['name'],
|
name=data['name'],
|
||||||
description=data['description'])
|
description=data['description'])
|
||||||
messages.success(request,
|
messages.success(request,
|
||||||
|
@ -49,8 +49,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
|
|||||||
domain_id = self._get_domain_id()
|
domain_id = self._get_domain_id()
|
||||||
groups = self._get_groups(domain_id)
|
groups = self._get_groups(domain_id)
|
||||||
filters = {}
|
filters = {}
|
||||||
domain = self.domains.get(id="1")
|
|
||||||
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
|
|
||||||
api.keystone.group_list(IgnoreArg(),
|
api.keystone.group_list(IgnoreArg(),
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
filters=filters) \
|
filters=filters) \
|
||||||
@ -79,8 +77,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
|
|||||||
domain_context_name=domain.name)
|
domain_context_name=domain.name)
|
||||||
groups = self._get_groups(domain.id)
|
groups = self._get_groups(domain.id)
|
||||||
|
|
||||||
api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain.id)
|
|
||||||
|
|
||||||
api.keystone.group_list(IsA(http.HttpRequest),
|
api.keystone.group_list(IsA(http.HttpRequest),
|
||||||
domain=domain.id,
|
domain=domain.id,
|
||||||
filters=filters).AndReturn(groups)
|
filters=filters).AndReturn(groups)
|
||||||
@ -105,9 +101,7 @@ class GroupsViewTests(test.BaseAdminViewTests):
|
|||||||
def test_index_with_keystone_can_edit_group_false(self):
|
def test_index_with_keystone_can_edit_group_false(self):
|
||||||
domain_id = self._get_domain_id()
|
domain_id = self._get_domain_id()
|
||||||
groups = self._get_groups(domain_id)
|
groups = self._get_groups(domain_id)
|
||||||
domain = self.domains.get(id="1")
|
|
||||||
filters = {}
|
filters = {}
|
||||||
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
|
|
||||||
api.keystone.group_list(IgnoreArg(),
|
api.keystone.group_list(IgnoreArg(),
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
filters=filters) \
|
filters=filters) \
|
||||||
@ -204,8 +198,6 @@ class GroupsViewTests(test.BaseAdminViewTests):
|
|||||||
filters = {}
|
filters = {}
|
||||||
group = self.groups.get(id="2")
|
group = self.groups.get(id="2")
|
||||||
|
|
||||||
domain = self.domains.get(id="1")
|
|
||||||
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
|
|
||||||
api.keystone.group_list(IgnoreArg(),
|
api.keystone.group_list(IgnoreArg(),
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
filters=filters) \
|
filters=filters) \
|
||||||
|
@ -31,6 +31,7 @@ from openstack_dashboard.dashboards.identity.groups \
|
|||||||
import forms as project_forms
|
import forms as project_forms
|
||||||
from openstack_dashboard.dashboards.identity.groups \
|
from openstack_dashboard.dashboards.identity.groups \
|
||||||
import tables as project_tables
|
import tables as project_tables
|
||||||
|
from openstack_dashboard.utils import identity
|
||||||
|
|
||||||
|
|
||||||
class IndexView(tables.DataTableView):
|
class IndexView(tables.DataTableView):
|
||||||
@ -58,8 +59,7 @@ class IndexView(tables.DataTableView):
|
|||||||
self._needs_filter_first = True
|
self._needs_filter_first = True
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
domain_id = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(self.request)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
groups = api.keystone.group_list(self.request,
|
groups = api.keystone.group_list(self.request,
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
@ -125,7 +125,7 @@ class GroupManageMixin(object):
|
|||||||
@memoized.memoized_method
|
@memoized.memoized_method
|
||||||
def _get_group_members(self):
|
def _get_group_members(self):
|
||||||
group_id = self.kwargs['group_id']
|
group_id = self.kwargs['group_id']
|
||||||
domain_id = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(self.request)
|
||||||
return api.keystone.user_list(self.request, domain=domain_id,
|
return api.keystone.user_list(self.request, domain=domain_id,
|
||||||
group=group_id)
|
group=group_id)
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ class TenantsViewTests(test.BaseAdminViewTests):
|
|||||||
def test_index(self):
|
def test_index(self):
|
||||||
domain = self.domains.get(id="1")
|
domain = self.domains.get(id="1")
|
||||||
filters = {}
|
filters = {}
|
||||||
api.keystone.domain_get(IsA(http.HttpRequest), '1').AndReturn(domain)
|
|
||||||
api.keystone.tenant_list(IsA(http.HttpRequest),
|
api.keystone.tenant_list(IsA(http.HttpRequest),
|
||||||
domain=None,
|
domain=None,
|
||||||
paginate=True,
|
paginate=True,
|
||||||
@ -79,8 +78,6 @@ class TenantsViewTests(test.BaseAdminViewTests):
|
|||||||
domain_tenants = [tenant for tenant in self.tenants.list()
|
domain_tenants = [tenant for tenant in self.tenants.list()
|
||||||
if tenant.domain_id == domain.id]
|
if tenant.domain_id == domain.id]
|
||||||
|
|
||||||
api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain.id)
|
|
||||||
|
|
||||||
api.keystone.tenant_list(IsA(http.HttpRequest),
|
api.keystone.tenant_list(IsA(http.HttpRequest),
|
||||||
domain=domain.id,
|
domain=domain.id,
|
||||||
paginate=True,
|
paginate=True,
|
||||||
|
@ -39,6 +39,7 @@ from openstack_dashboard.dashboards.identity.projects \
|
|||||||
import workflows as project_workflows
|
import workflows as project_workflows
|
||||||
from openstack_dashboard.dashboards.project.overview \
|
from openstack_dashboard.dashboards.project.overview \
|
||||||
import views as project_views
|
import views as project_views
|
||||||
|
from openstack_dashboard.utils import identity
|
||||||
|
|
||||||
PROJECT_INFO_FIELDS = ("domain_id",
|
PROJECT_INFO_FIELDS = ("domain_id",
|
||||||
"domain_name",
|
"domain_name",
|
||||||
@ -99,11 +100,11 @@ class IndexView(tables.DataTableView):
|
|||||||
self._more = False
|
self._more = False
|
||||||
return tenants
|
return tenants
|
||||||
|
|
||||||
domain_context = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(self.request)
|
||||||
try:
|
try:
|
||||||
tenants, self._more = api.keystone.tenant_list(
|
tenants, self._more = api.keystone.tenant_list(
|
||||||
self.request,
|
self.request,
|
||||||
domain=domain_context,
|
domain=domain_id,
|
||||||
paginate=True,
|
paginate=True,
|
||||||
filters=filters,
|
filters=filters,
|
||||||
marker=marker)
|
marker=marker)
|
||||||
|
@ -35,6 +35,7 @@ from openstack_dashboard.api import cinder
|
|||||||
from openstack_dashboard.api import keystone
|
from openstack_dashboard.api import keystone
|
||||||
from openstack_dashboard.api import nova
|
from openstack_dashboard.api import nova
|
||||||
from openstack_dashboard.usage import quotas
|
from openstack_dashboard.usage import quotas
|
||||||
|
from openstack_dashboard.utils import identity as identity
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -677,7 +678,7 @@ class UpdateProject(CommonQuotaWorkflow):
|
|||||||
|
|
||||||
def _update_project(self, request, data):
|
def _update_project(self, request, data):
|
||||||
"""Update project info"""
|
"""Update project info"""
|
||||||
domain_id = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(request)
|
||||||
try:
|
try:
|
||||||
project_id = data['project_id']
|
project_id = data['project_id']
|
||||||
|
|
||||||
|
@ -57,13 +57,15 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
@test.create_stubs({api.keystone: ('user_list',
|
@test.create_stubs({api.keystone: ('user_list',
|
||||||
'get_effective_domain_id',
|
'get_effective_domain_id',
|
||||||
'domain_lookup')})
|
'domain_lookup')})
|
||||||
def test_index(self):
|
def test_index(self, with_domain=False):
|
||||||
domain = self._get_default_domain()
|
domain = self._get_default_domain()
|
||||||
domain_id = domain.id
|
domain_id = domain.id
|
||||||
filters = {}
|
filters = {}
|
||||||
users = self._get_users(domain_id)
|
users = self._get_users(domain_id)
|
||||||
|
|
||||||
api.keystone.get_effective_domain_id(IgnoreArg()).AndReturn(domain_id)
|
if not with_domain:
|
||||||
|
api.keystone.get_effective_domain_id(
|
||||||
|
IgnoreArg()).AndReturn(domain_id)
|
||||||
|
|
||||||
api.keystone.user_list(IgnoreArg(),
|
api.keystone.user_list(IgnoreArg(),
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
@ -84,7 +86,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
domain = self.domains.get(id="1")
|
domain = self.domains.get(id="1")
|
||||||
self.setSessionValues(domain_context=domain.id,
|
self.setSessionValues(domain_context=domain.id,
|
||||||
domain_context_name=domain.name)
|
domain_context_name=domain.name)
|
||||||
self.test_index()
|
self.test_index(with_domain=True)
|
||||||
|
|
||||||
@override_settings(USER_TABLE_EXTRA_INFO={'phone_num': 'Phone Number'})
|
@override_settings(USER_TABLE_EXTRA_INFO={'phone_num': 'Phone Number'})
|
||||||
@test.create_stubs({api.keystone: ('user_create',
|
@test.create_stubs({api.keystone: ('user_create',
|
||||||
|
@ -40,6 +40,7 @@ from openstack_dashboard.dashboards.identity.users \
|
|||||||
import forms as project_forms
|
import forms as project_forms
|
||||||
from openstack_dashboard.dashboards.identity.users \
|
from openstack_dashboard.dashboards.identity.users \
|
||||||
import tables as project_tables
|
import tables as project_tables
|
||||||
|
from openstack_dashboard.utils import identity
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -69,10 +70,10 @@ class IndexView(tables.DataTableView):
|
|||||||
self._needs_filter_first = True
|
self._needs_filter_first = True
|
||||||
return users
|
return users
|
||||||
|
|
||||||
domain_context = api.keystone.get_effective_domain_id(self.request)
|
domain_id = identity.get_domain_id_for_operation(self.request)
|
||||||
try:
|
try:
|
||||||
users = api.keystone.user_list(self.request,
|
users = api.keystone.user_list(self.request,
|
||||||
domain=domain_context,
|
domain=domain_id,
|
||||||
filters=filters)
|
filters=filters)
|
||||||
except Exception:
|
except Exception:
|
||||||
exceptions.handle(self.request,
|
exceptions.handle(self.request,
|
||||||
|
28
openstack_dashboard/utils/identity.py
Normal file
28
openstack_dashboard/utils/identity.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright 2017 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from openstack_dashboard import api
|
||||||
|
|
||||||
|
|
||||||
|
def get_domain_id_for_operation(request):
|
||||||
|
"""Get the ID of the domain in which the current operation should happen.
|
||||||
|
|
||||||
|
If the user has a domain context set, use that, otherwise use the user's
|
||||||
|
effective domain.
|
||||||
|
"""
|
||||||
|
|
||||||
|
domain_context = request.session.get('domain_context')
|
||||||
|
if domain_context:
|
||||||
|
return domain_context
|
||||||
|
return api.keystone.get_effective_domain_id(request)
|
Loading…
Reference in New Issue
Block a user