diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index c0bd2c77c9..ed75733400 100755 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -321,6 +321,17 @@ This example sorts flavors by vcpus in descending order:: 'reverse': True, } +``DROPDOWN_MAX_ITEMS`` +---------------------- + +.. versionadded:: 2015.1(Kilo) + +Default: ``30`` + +This setting sets the maximum number of items displayed in a dropdown. +Dropdowns that limit based on this value need to support a way to observe +the entire list. + ``IMAGES_LIST_FILTER_TENANTS`` ------------------------------ diff --git a/openstack_dashboard/dashboards/identity/projects/tables.py b/openstack_dashboard/dashboards/identity/projects/tables.py index f7e604fa64..8445b184de 100644 --- a/openstack_dashboard/dashboards/identity/projects/tables.py +++ b/openstack_dashboard/dashboards/identity/projects/tables.py @@ -25,6 +25,27 @@ from openstack_dashboard import api from openstack_dashboard import policy +class RescopeTokenToProject(tables.LinkAction): + name = "rescope" + verbose_name = _("Set as Active Project") + url = "switch_tenants" + + def allowed(self, request, project): + # allow rescoping token to any project the user has a role on, + # authorized_tenants, and that they are not currently scoped to + return next((True for proj in request.user.authorized_tenants + if proj.id == project.id and + project.id != request.user.project_id), False) + + def get_link_url(self, project): + # redirects to the switch_tenants url which then will redirect + # back to this page + dash_url = reverse("horizon:identity:projects:index") + base_url = reverse(self.url, args=[project.id]) + param = urlencode({"next": dash_url}) + return "?".join([base_url, param]) + + class UpdateMembersLink(tables.LinkAction): name = "users" verbose_name = _("Modify Users") @@ -211,7 +232,8 @@ class TenantsTable(tables.DataTable): verbose_name = _("Projects") row_class = UpdateRow row_actions = (UpdateMembersLink, UpdateGroupsLink, UpdateProject, - UsageLink, ModifyQuotas, DeleteTenantsAction) + UsageLink, ModifyQuotas, DeleteTenantsAction, + RescopeTokenToProject) table_actions = (TenantFilterAction, CreateProject, DeleteTenantsAction) pagination_param = "tenant_marker" diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index 049f8cccf9..a4bb3643d6 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -248,6 +248,9 @@ IMAGE_RESERVED_CUSTOM_PROPERTIES = [] API_RESULT_LIMIT = 1000 API_RESULT_PAGE_SIZE = 20 +# Specify a maximum number of items to display in a dropdown. +DROPDOWN_MAX_ITEMS = 30 + # The timezone of the server. This should correspond with the timezone # of your entire OpenStack installation, and hopefully be in UTC. TIME_ZONE = "UTC" diff --git a/openstack_dashboard/templates/_header.html b/openstack_dashboard/templates/_header.html index 759a77f8d2..ef52fc0c4c 100644 --- a/openstack_dashboard/templates/_header.html +++ b/openstack_dashboard/templates/_header.html @@ -15,9 +15,9 @@ {% show_project_list %} {% show_region_list %} - diff --git a/openstack_dashboard/templatetags/context_selection.py b/openstack_dashboard/templatetags/context_selection.py index 2014617a27..5befc5d98c 100644 --- a/openstack_dashboard/templatetags/context_selection.py +++ b/openstack_dashboard/templatetags/context_selection.py @@ -63,11 +63,14 @@ def show_domain_list(context): @register.inclusion_tag('context_selection/_project_list.html', takes_context=True) def show_project_list(context): + max_proj = getattr(settings, + 'DROPDOWN_MAX_ITEMS', + 30) if 'request' not in context: return {} request = context['request'] context = {'projects': sorted(context['authorized_tenants'], - key=lambda project: project.name), + key=lambda project: project.name)[:max_proj], 'project_id': request.user.project_id, 'request': request} return context