Display the project name in user detail page
In the user detail page, only display the "Project ID", now display the "Project Name" corresponding to the "Project ID". Change-Id: Id54352a2659146787a913f26df9d49d0ae84261d Closes-Bug: #1479171
This commit is contained in:
parent
fc1244708b
commit
7eae1b69ad
@ -24,6 +24,10 @@
|
||||
<dd>{{ user.enabled|yesno|capfirst }}</dd>
|
||||
<dt>{% trans "Project ID" %}</dt>
|
||||
<dd>{{ user.project_id }}</dd>
|
||||
{% if tenant_name %}
|
||||
<dt>{% trans "Project Name" %}</dt>
|
||||
<dd>{{ tenant_name }}</dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
|
@ -585,11 +585,14 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
u'You are not allowed to delete user: %s'
|
||||
% self.request.user.username)
|
||||
|
||||
@test.create_stubs({api.keystone: ('user_get',)})
|
||||
@test.create_stubs({api.keystone: ('user_get', 'tenant_get')})
|
||||
def test_detail_view(self):
|
||||
user = self.users.get(id="1")
|
||||
tenant = self.tenants.get(id=user.project_id)
|
||||
|
||||
api.keystone.user_get(IsA(http.HttpRequest), '1').AndReturn(user)
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), user.project_id) \
|
||||
.AndReturn(tenant)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(USER_DETAIL_URL, args=[user.id])
|
||||
@ -599,6 +602,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
self.assertEqual(res.context['user'].id, user.id)
|
||||
self.assertContains(res, "<h1>User Details: %s</h1>" % user.name,
|
||||
1, 200)
|
||||
self.assertEqual(res.context['tenant_name'], tenant.name)
|
||||
|
||||
@test.create_stubs({api.keystone: ('user_get',)})
|
||||
def test_detail_view_with_exception(self):
|
||||
|
@ -16,6 +16,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import operator
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
@ -39,6 +40,8 @@ from openstack_dashboard.dashboards.identity.users \
|
||||
from openstack_dashboard.dashboards.identity.users \
|
||||
import tables as project_tables
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IndexView(tables.DataTableView):
|
||||
table_class = project_tables.UsersTable
|
||||
@ -166,6 +169,7 @@ class DetailView(views.HorizonTemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(DetailView, self).get_context_data(**kwargs)
|
||||
user = self.get_data()
|
||||
tenant = self.get_tenant(user.project_id)
|
||||
table = project_tables.UsersTable(self.request)
|
||||
domain_id = getattr(user, "domain_id", None)
|
||||
domain_name = ''
|
||||
@ -178,12 +182,26 @@ class DetailView(views.HorizonTemplateView):
|
||||
_('Unable to retrieve project domain.'))
|
||||
|
||||
context["user"] = user
|
||||
if tenant:
|
||||
context["tenant_name"] = tenant.name
|
||||
context["domain_id"] = domain_id
|
||||
context["domain_name"] = domain_name
|
||||
context["url"] = self.get_redirect_url()
|
||||
context["actions"] = table.render_row_actions(user)
|
||||
return context
|
||||
|
||||
@memoized.memoized_method
|
||||
def get_tenant(self, project_id):
|
||||
tenant = None
|
||||
if project_id:
|
||||
try:
|
||||
tenant = api.keystone.tenant_get(self.request, project_id)
|
||||
except Exception as e:
|
||||
msg = ('Failed to get tenant %(project_id)s: %(reason)s' %
|
||||
{'project_id': project_id, 'reason': e})
|
||||
LOG.error(msg)
|
||||
return tenant
|
||||
|
||||
@memoized.memoized_method
|
||||
def get_data(self):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user