Fetch user's projects from request.user

Instead of hitting the backend api, the user's projects
can be fetched from request.user.

Change-Id: I9cbdeded40d4cc4f54ff0c52f5fd8ea7280ef7cf
Closes-Bug: #1439338
This commit is contained in:
lin-hua-cheng 2015-03-31 15:59:20 -07:00 committed by Lin Hua Cheng
parent 8b6952e1bc
commit ca5736a2dc
2 changed files with 8 additions and 4 deletions

View File

@ -264,7 +264,13 @@ def tenant_list(request, paginate=False, marker=None, domain=None, user=None,
limit = page_size + 1
has_more_data = False
if VERSIONS.active < 3:
# if requesting the projects for the current user,
# return the list from the cache
if user == request.user.id:
tenants = request.user.authorized_tenants
elif VERSIONS.active < 3:
tenants = manager.list(limit, marker)
if paginate and len(tenants) > page_size:
tenants.pop(-1)

View File

@ -78,6 +78,7 @@ class IndexView(tables.DataTableView):
marker = self.request.GET.get(
project_tables.TenantsTable._meta.pagination_param, None)
domain_context = self.request.session.get('domain_context', None)
self._more = False
if policy.check((("identity", "identity:list_projects"),),
self.request):
try:
@ -87,7 +88,6 @@ class IndexView(tables.DataTableView):
paginate=True,
marker=marker)
except Exception:
self._more = False
exceptions.handle(self.request,
_("Unable to retrieve project list."))
elif policy.check((("identity", "identity:list_user_projects"),),
@ -100,11 +100,9 @@ class IndexView(tables.DataTableView):
marker=marker,
admin=False)
except Exception:
self._more = False
exceptions.handle(self.request,
_("Unable to retrieve project information."))
else:
self._more = False
msg = \
_("Insufficient privilege level to view project information.")
messages.info(self.request, msg)