Fix the Domain context for Projects panel
Add display of Domain ID and Domain Name in the Create and Update Projects page to give user a hint where the Project will be created. For Keystone V2, the two fields will be hidden. When the Domain Context is set, the Project will be created in that Domain Context. Otherwise, the Project will be created in the Domain of the logon user. On project creation, the listing of available users and groups will be based on the Domain where it will be created. While on project update, the listing of available users and groups will be based on the Domain of the Project. Fixes bug 1215196 Change-Id: Ia2ab25956621d01c2173e08402241b7f60401e0f
This commit is contained in:
parent
3f84582846
commit
ff3071612f
@ -213,6 +213,28 @@ def tenant_create(request, name, description=None, enabled=None, domain=None):
|
||||
enabled=enabled)
|
||||
|
||||
|
||||
def get_default_domain(request):
|
||||
"""
|
||||
Gets the default domain object to use when creating Identity object.
|
||||
Returns the domain context if is set, otherwise return the domain
|
||||
of the logon user.
|
||||
"""
|
||||
domain_id = request.session.get("domain_context", None)
|
||||
domain_name = request.session.get("domain_context_name", None)
|
||||
# if running in Keystone V3 or later
|
||||
if VERSIONS.active >= 3 and not domain_id:
|
||||
# if no domain context set, default to users' domain
|
||||
domain_id = request.user.user_domain_id
|
||||
try:
|
||||
domain = domain_get(request, domain_id)
|
||||
domain_name = domain.name
|
||||
except Exception:
|
||||
LOG.warning("Unable to retrieve Domain: %s" % domain_id)
|
||||
domain = base.APIDictWrapper({"id": domain_id,
|
||||
"name": domain_name})
|
||||
return domain
|
||||
|
||||
|
||||
# TODO(gabriel): Is there ever a valid case for admin to be false here?
|
||||
# A quick search through the codebase reveals that it's always called with
|
||||
# admin=true so I suspect we could eliminate it entirely as with the other
|
||||
|
@ -70,15 +70,18 @@ class TenantsViewTests(test.BaseAdminViewTests):
|
||||
|
||||
class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
def _get_project_info(self, project):
|
||||
domain_id = self.request.session.get('domain_context', None)
|
||||
domain = self._get_default_domain()
|
||||
project_info = {"name": project.name,
|
||||
"description": project.description,
|
||||
"enabled": project.enabled,
|
||||
"domain": domain_id}
|
||||
"domain": domain.id}
|
||||
return project_info
|
||||
|
||||
def _get_workflow_fields(self, project):
|
||||
project_info = {"name": project.name,
|
||||
domain = self._get_default_domain()
|
||||
project_info = {"domain_id": domain.id,
|
||||
"domain_name": domain.name,
|
||||
"name": project.name,
|
||||
"description": project.description,
|
||||
"enabled": project.enabled}
|
||||
return project_info
|
||||
@ -101,8 +104,13 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project_info.update(quota_data)
|
||||
return project_info
|
||||
|
||||
def _get_domain_id(self):
|
||||
return self.request.session.get('domain_context', None)
|
||||
def _get_default_domain(self):
|
||||
default_domain = self.domain
|
||||
domain = {"id": self.request.session.get('domain_context',
|
||||
default_domain.id),
|
||||
"name": self.request.session.get('domain_context_name',
|
||||
default_domain.name)}
|
||||
return api.base.APIDictWrapper(domain)
|
||||
|
||||
def _get_all_users(self, domain_id):
|
||||
if not domain_id:
|
||||
@ -120,7 +128,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
if group.domain_id == domain_id]
|
||||
return groups
|
||||
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
@test.create_stubs({api.keystone: ('get_default_domain',
|
||||
'get_default_role',
|
||||
'user_list',
|
||||
'group_list',
|
||||
'role_list'),
|
||||
@ -128,14 +137,17 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
def test_add_project_get(self):
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
|
||||
# init
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(default_role)
|
||||
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
|
||||
@ -233,7 +245,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
@ -320,16 +333,20 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({api.keystone: ('user_list',
|
||||
'role_list',
|
||||
'group_list',
|
||||
'get_default_domain',
|
||||
'get_default_role'),
|
||||
quotas: ('get_default_quota_data',)})
|
||||
def test_add_project_quota_defaults_error(self):
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)) \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
|
||||
@ -360,18 +377,22 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'user_list',
|
||||
'role_list',
|
||||
'group_list',
|
||||
'get_default_domain',
|
||||
'get_default_role'),
|
||||
quotas: ('get_default_quota_data',)})
|
||||
def test_add_project_tenant_create_error(self):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
@ -409,6 +430,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'user_list',
|
||||
'role_list',
|
||||
'group_list',
|
||||
'get_default_domain',
|
||||
'get_default_role',
|
||||
'add_tenant_user_role'),
|
||||
quotas: ('get_default_quota_data',),
|
||||
@ -417,12 +439,15 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
@ -486,6 +511,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'user_list',
|
||||
'role_list',
|
||||
'group_list',
|
||||
'get_default_domain',
|
||||
'get_default_role',
|
||||
'add_tenant_user_role'),
|
||||
quotas: ('get_default_quota_data',),
|
||||
@ -495,12 +521,15 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
@ -563,18 +592,22 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({api.keystone: ('user_list',
|
||||
'role_list',
|
||||
'group_list',
|
||||
'get_default_domain',
|
||||
'get_default_role'),
|
||||
quotas: ('get_default_quota_data',)})
|
||||
def test_add_project_missing_field_error(self):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
default_domain = self._get_default_domain()
|
||||
domain_id = default_domain.id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
@ -616,9 +649,6 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
quota_data[field] = int(neutron_quota.get(field).limit)
|
||||
return quota_data
|
||||
|
||||
def _get_domain_id(self):
|
||||
return self.request.session.get('domain_context', None)
|
||||
|
||||
def _get_all_users(self, domain_id):
|
||||
if not domain_id:
|
||||
users = self.users.list()
|
||||
@ -646,6 +676,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
'roles_for_user',
|
||||
'tenant_get',
|
||||
'domain_get',
|
||||
'user_list',
|
||||
'roles_for_group',
|
||||
'group_list',
|
||||
@ -655,7 +686,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
domain_id = project.domain_id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
@ -663,6 +694,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest),
|
||||
self.tenant.id, admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
@ -712,13 +745,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'<UpdateProjectGroups: update_group_members>',
|
||||
'<UpdateProjectQuota: update_quotas>'])
|
||||
|
||||
def test_update_project_get_domain(self):
|
||||
domain = self.domains.get(id="1")
|
||||
self.setSessionValues(domain_context=domain.id,
|
||||
domain_context_name=domain.name)
|
||||
self.test_update_project_get()
|
||||
|
||||
@test.create_stubs({api.keystone: ('tenant_get',
|
||||
'domain_get',
|
||||
'tenant_update',
|
||||
'get_default_role',
|
||||
'roles_for_user',
|
||||
@ -737,7 +765,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
domain_id = project.domain_id
|
||||
users = self._get_all_users(domain_id)
|
||||
proj_users = self._get_proj_users(project.id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
@ -748,6 +776,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest),
|
||||
self.tenant.id, admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
@ -779,6 +809,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['2'] # member role
|
||||
|
||||
# update some fields
|
||||
project._info["domain_id"] = domain_id
|
||||
project._info["name"] = "updated name"
|
||||
project._info["description"] = "updated description"
|
||||
quota.metadata_items = 444
|
||||
@ -895,7 +926,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# submit form data
|
||||
project_data = {"name": project._info["name"],
|
||||
project_data = {"domain_id": project._info["domain_id"],
|
||||
"name": project._info["name"],
|
||||
"id": project.id,
|
||||
"description": project._info["description"],
|
||||
"enabled": project.enabled}
|
||||
@ -909,12 +941,6 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(error=0, warning=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
def test_update_project_save_domain(self):
|
||||
domain = self.domains.get(id="1")
|
||||
self.setSessionValues(domain_context=domain.id,
|
||||
domain_context_name=domain.name)
|
||||
self.test_update_project_save()
|
||||
|
||||
@test.create_stubs({api.neutron: ('is_extension_supported',
|
||||
'tenant_quota_get',
|
||||
'tenant_quota_update')})
|
||||
@ -950,6 +976,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.keystone: ('tenant_get',
|
||||
'domain_get',
|
||||
'tenant_update',
|
||||
'get_default_role',
|
||||
'roles_for_user',
|
||||
@ -967,7 +994,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
domain_id = project.domain_id
|
||||
users = self._get_all_users(domain_id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
@ -976,6 +1003,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
@ -1010,6 +1039,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
.append(group.id)
|
||||
|
||||
# update some fields
|
||||
project._info["domain_id"] = domain_id
|
||||
project._info["name"] = "updated name"
|
||||
project._info["description"] = "updated description"
|
||||
quota.metadata_items = 444
|
||||
@ -1029,7 +1059,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# submit form data
|
||||
project_data = {"name": project._info["name"],
|
||||
project_data = {"domain_id": project._info["domain_id"],
|
||||
"name": project._info["name"],
|
||||
"id": project.id,
|
||||
"description": project._info["description"],
|
||||
"enabled": project.enabled}
|
||||
@ -1042,13 +1073,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
def test_update_project_tenant_update_error_domain(self):
|
||||
domain = self.domains.get(id="1")
|
||||
self.setSessionValues(domain_context=domain.id,
|
||||
domain_context_name=domain.name)
|
||||
self.test_update_project_tenant_update_error()
|
||||
|
||||
@test.create_stubs({api.keystone: ('tenant_get',
|
||||
'domain_get',
|
||||
'tenant_update',
|
||||
'get_default_role',
|
||||
'roles_for_user',
|
||||
@ -1066,7 +1092,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
domain_id = project.domain_id
|
||||
users = self._get_all_users(domain_id)
|
||||
proj_users = self._get_proj_users(project.id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
@ -1077,6 +1103,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
@ -1110,6 +1138,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
|
||||
|
||||
# update some fields
|
||||
project._info["domain_id"] = domain_id
|
||||
project._info["name"] = "updated name"
|
||||
project._info["description"] = "updated description"
|
||||
quota[0].limit = 444
|
||||
@ -1188,10 +1217,11 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# submit form data
|
||||
project_data = {"name": project._info["name"],
|
||||
"id": project.id,
|
||||
"description": project._info["description"],
|
||||
"enabled": project.enabled}
|
||||
project_data = {"domain_id": project._info["domain_id"],
|
||||
"name": project._info["name"],
|
||||
"id": project.id,
|
||||
"description": project._info["description"],
|
||||
"enabled": project.enabled}
|
||||
workflow_data.update(project_data)
|
||||
workflow_data.update(updated_quota)
|
||||
url = reverse('horizon:admin:projects:update',
|
||||
@ -1202,13 +1232,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(error=1, warning=0)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
def test_update_project_quota_update_error_domain(self):
|
||||
domain = self.domains.get(id="1")
|
||||
self.setSessionValues(domain_context=domain.id,
|
||||
domain_context_name=domain.name)
|
||||
self.test_update_project_quota_update_error()
|
||||
|
||||
@test.create_stubs({api.keystone: ('tenant_get',
|
||||
'domain_get',
|
||||
'tenant_update',
|
||||
'get_default_role',
|
||||
'roles_for_user',
|
||||
@ -1225,7 +1250,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
project = self.tenants.first()
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
domain_id = self._get_domain_id()
|
||||
domain_id = project.domain_id
|
||||
users = self._get_all_users(domain_id)
|
||||
proj_users = self._get_proj_users(project.id)
|
||||
groups = self._get_all_groups(domain_id)
|
||||
@ -1235,6 +1260,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
@ -1265,6 +1292,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
workflow_data[GROUP_ROLE_PREFIX + "1"] = ['1', '3'] # admin role
|
||||
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
|
||||
# update some fields
|
||||
project._info["domain_id"] = domain_id
|
||||
project._info["name"] = "updated name"
|
||||
project._info["description"] = "updated description"
|
||||
quota.metadata_items = 444
|
||||
@ -1305,7 +1333,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# submit form data
|
||||
project_data = {"name": project._info["name"],
|
||||
project_data = {"domain_id": project._info["domain_id"],
|
||||
"name": project._info["name"],
|
||||
"id": project.id,
|
||||
"description": project._info["description"],
|
||||
"enabled": project.enabled}
|
||||
@ -1319,16 +1348,13 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(error=1, warning=0)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
def test_update_project_member_update_error_domain(self):
|
||||
domain = self.domains.get(id="1")
|
||||
self.setSessionValues(domain_context=domain.id,
|
||||
domain_context_name=domain.name)
|
||||
self.test_update_project_member_update_error()
|
||||
|
||||
@test.create_stubs({api.keystone: ('get_default_role', 'tenant_get'),
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
'tenant_get',
|
||||
'domain_get'),
|
||||
quotas: ('get_tenant_quota_data',)})
|
||||
def test_update_project_when_default_role_does_not_exist(self):
|
||||
project = self.tenants.first()
|
||||
domain_id = project.domain_id
|
||||
quota = self.quotas.first()
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
@ -1336,6 +1362,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
|
@ -28,6 +28,7 @@ from horizon import tables
|
||||
from horizon import workflows
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.api import keystone
|
||||
from openstack_dashboard import usage
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
@ -38,7 +39,9 @@ from openstack_dashboard.dashboards.admin.projects \
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
PROJECT_INFO_FIELDS = ("name",
|
||||
PROJECT_INFO_FIELDS = ("domain_id",
|
||||
"domain_name",
|
||||
"name",
|
||||
"description",
|
||||
"enabled")
|
||||
|
||||
@ -106,6 +109,11 @@ class CreateProjectView(workflows.WorkflowView):
|
||||
def get_initial(self):
|
||||
initial = super(CreateProjectView, self).get_initial()
|
||||
|
||||
# Set the domain of the project
|
||||
domain = api.keystone.get_default_domain(self.request)
|
||||
initial["domain_id"] = domain.id
|
||||
initial["domain_name"] = domain.name
|
||||
|
||||
# get initial quota defaults
|
||||
try:
|
||||
quota_defaults = quotas.get_default_quota_data(self.request)
|
||||
@ -151,6 +159,17 @@ class UpdateProjectView(workflows.WorkflowView):
|
||||
for field in PROJECT_INFO_FIELDS:
|
||||
initial[field] = getattr(project_info, field, None)
|
||||
|
||||
# Retrieve the domain name where the project belong
|
||||
if keystone.VERSIONS.active >= 3:
|
||||
try:
|
||||
domain = api.keystone.domain_get(self.request,
|
||||
initial["domain_id"])
|
||||
initial["domain_name"] = domain.name
|
||||
except Exception:
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve project domain.'),
|
||||
redirect=reverse(INDEX_URL))
|
||||
|
||||
# get initial project quota
|
||||
quota_data = quotas.get_tenant_quota_data(self.request,
|
||||
tenant_id=project_id)
|
||||
|
@ -94,6 +94,13 @@ class UpdateProjectQuota(workflows.Step):
|
||||
|
||||
|
||||
class CreateProjectInfoAction(workflows.Action):
|
||||
# Hide the domain_id and domain_name by default
|
||||
domain_id = forms.CharField(label=_("Domain ID"),
|
||||
required=False,
|
||||
widget=forms.HiddenInput())
|
||||
domain_name = forms.CharField(label=_("Domain Name"),
|
||||
required=False,
|
||||
widget=forms.HiddenInput())
|
||||
name = forms.CharField(label=_("Name"))
|
||||
description = forms.CharField(widget=forms.widgets.Textarea(),
|
||||
label=_("Description"),
|
||||
@ -102,6 +109,16 @@ class CreateProjectInfoAction(workflows.Action):
|
||||
required=False,
|
||||
initial=True)
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(CreateProjectInfoAction, self).__init__(request,
|
||||
*args,
|
||||
**kwargs)
|
||||
# For keystone V3, display the two fields in read-only
|
||||
if keystone.VERSIONS.active >= 3:
|
||||
readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'})
|
||||
self.fields["domain_id"].widget = readonlyInput
|
||||
self.fields["domain_name"].widget = readonlyInput
|
||||
|
||||
class Meta:
|
||||
name = _("Project Info")
|
||||
help_text = _("From here you can create a new "
|
||||
@ -110,7 +127,9 @@ class CreateProjectInfoAction(workflows.Action):
|
||||
|
||||
class CreateProjectInfo(workflows.Step):
|
||||
action_class = CreateProjectInfoAction
|
||||
contributes = ("project_id",
|
||||
contributes = ("domain_id",
|
||||
"domain_name",
|
||||
"project_id",
|
||||
"name",
|
||||
"description",
|
||||
"enabled")
|
||||
@ -122,9 +141,11 @@ class UpdateProjectMembersAction(workflows.MembershipAction):
|
||||
*args,
|
||||
**kwargs)
|
||||
err_msg = _('Unable to retrieve user list. Please try again later.')
|
||||
# Use the domain_id from the project
|
||||
domain_id = self.initial.get("domain_id", None)
|
||||
project_id = ''
|
||||
if 'project_id' in args[0]:
|
||||
project_id = args[0]['project_id']
|
||||
if 'project_id' in self.initial:
|
||||
project_id = self.initial['project_id']
|
||||
|
||||
# Get the default role
|
||||
try:
|
||||
@ -146,10 +167,9 @@ class UpdateProjectMembersAction(workflows.MembershipAction):
|
||||
|
||||
# Get list of available users
|
||||
all_users = []
|
||||
domain_context = request.session.get('domain_context', None)
|
||||
try:
|
||||
all_users = api.keystone.user_list(request,
|
||||
domain=domain_context)
|
||||
domain=domain_id)
|
||||
except Exception:
|
||||
exceptions.handle(request, err_msg)
|
||||
users_list = [(user.id, user.name) for user in all_users]
|
||||
@ -218,9 +238,11 @@ class UpdateProjectGroupsAction(workflows.MembershipAction):
|
||||
*args,
|
||||
**kwargs)
|
||||
err_msg = _('Unable to retrieve group list. Please try again later.')
|
||||
# Use the domain_id from the project
|
||||
domain_id = self.initial.get("domain_id", None)
|
||||
project_id = ''
|
||||
if 'project_id' in args[0]:
|
||||
project_id = args[0]['project_id']
|
||||
if 'project_id' in self.initial:
|
||||
project_id = self.initial['project_id']
|
||||
|
||||
# Get the default role
|
||||
try:
|
||||
@ -242,10 +264,9 @@ class UpdateProjectGroupsAction(workflows.MembershipAction):
|
||||
|
||||
# Get list of available groups
|
||||
all_groups = []
|
||||
domain_context = request.session.get('domain_context', None)
|
||||
try:
|
||||
all_groups = api.keystone.group_list(request,
|
||||
domain=domain_context)
|
||||
domain=domain_id)
|
||||
except Exception:
|
||||
exceptions.handle(request, err_msg)
|
||||
groups_list = [(group.id, group.name) for group in all_groups]
|
||||
@ -337,14 +358,14 @@ class CreateProject(workflows.Workflow):
|
||||
|
||||
def handle(self, request, data):
|
||||
# create the project
|
||||
domain_context = self.request.session.get('domain_context', None)
|
||||
domain_id = data['domain_id']
|
||||
try:
|
||||
desc = data['description']
|
||||
self.object = api.keystone.tenant_create(request,
|
||||
name=data['name'],
|
||||
description=desc,
|
||||
enabled=data['enabled'],
|
||||
domain=domain_context)
|
||||
domain=domain_id)
|
||||
except Exception:
|
||||
exceptions.handle(request, ignore=True)
|
||||
return False
|
||||
@ -450,7 +471,9 @@ class UpdateProjectInfoAction(CreateProjectInfoAction):
|
||||
class UpdateProjectInfo(workflows.Step):
|
||||
action_class = UpdateProjectInfoAction
|
||||
depends_on = ("project_id",)
|
||||
contributes = ("name",
|
||||
contributes = ("domain_id",
|
||||
"domain_name",
|
||||
"name",
|
||||
"description",
|
||||
"enabled")
|
||||
|
||||
@ -488,15 +511,18 @@ class UpdateProject(workflows.Workflow):
|
||||
# sets and do this all in a single "roles to add" and "roles to remove"
|
||||
# pass instead of the multi-pass thing happening now.
|
||||
|
||||
domain_context = request.session.get('domain_context', None)
|
||||
project_id = data['project_id']
|
||||
domain_id = ''
|
||||
# update project info
|
||||
try:
|
||||
api.keystone.tenant_update(request,
|
||||
project_id,
|
||||
name=data['name'],
|
||||
description=data['description'],
|
||||
enabled=data['enabled'])
|
||||
project = api.keystone.tenant_update(
|
||||
request,
|
||||
project_id,
|
||||
name=data['name'],
|
||||
description=data['description'],
|
||||
enabled=data['enabled'])
|
||||
# Use the domain_id from the project if available
|
||||
domain_id = getattr(project, "domain_id", None)
|
||||
except Exception:
|
||||
exceptions.handle(request, ignore=True)
|
||||
return False
|
||||
@ -605,7 +631,7 @@ class UpdateProject(workflows.Workflow):
|
||||
# Get the groups currently associated with this project so we
|
||||
# can diff against it.
|
||||
project_groups = api.keystone.group_list(request,
|
||||
domain=domain_context,
|
||||
domain=domain_id,
|
||||
project=project_id)
|
||||
groups_to_modify = len(project_groups)
|
||||
for group in project_groups:
|
||||
|
@ -220,17 +220,20 @@ def data(TEST):
|
||||
'name': 'test_tenant',
|
||||
'description': "a test tenant.",
|
||||
'enabled': True,
|
||||
'domain_id': '1'}
|
||||
'domain_id': '1',
|
||||
'domain_name': 'test_domain'}
|
||||
tenant_dict_2 = {'id': "2",
|
||||
'name': 'disabled_tenant',
|
||||
'description': "a disabled test tenant.",
|
||||
'enabled': False,
|
||||
'domain_id': '2'}
|
||||
'domain_id': '2',
|
||||
'domain_name': 'disabled_domain'}
|
||||
tenant_dict_3 = {'id': "3",
|
||||
'name': u'\u4e91\u89c4\u5219',
|
||||
'description': "an unicode-named tenant.",
|
||||
'enabled': True,
|
||||
'domain_id': '2'}
|
||||
'domain_id': '2',
|
||||
'domain_name': 'disabled_domain'}
|
||||
tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
|
||||
disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2)
|
||||
tenant_unicode = tenants.Tenant(tenants.TenantManager, tenant_dict_3)
|
||||
|
Loading…
Reference in New Issue
Block a user