def test_site(self): self.assertEqual(unicode(Horizon), "Horizon") self.assertEqual(repr(Horizon), "<Site: Horizon>") dash = Horizon.get_dashboard('nova') self.assertEqual(Horizon.get_default_dashboard(), dash) user = users.User() self.assertEqual(Horizon.get_user_home(user), dash.get_absolute_url())
def horizon_all_nav(context): """ Generates top-level dashboard navigation entries. """ if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard') paneldashboard = context['request'].horizon['dashboard'] panel_groups = paneldashboard.get_panel_groups() non_empty_groups = [] dashboards = [] allowed_panels = [] for dash in Horizon.get_dashboards(): if callable(dash.nav) and dash.nav(context): dashboards.append(dash) elif dash.nav: dashboards.append(dash) for group in panel_groups.values(): allowed_panels = [] for panel in group: if callable(panel.nav) and panel.nav(context): allowed_panels.append(panel) elif not callable(panel.nav) and panel.nav: allowed_panels.append(panel) if allowed_panels: non_empty_groups.append((paneldashboard.name, allowed_panels)) return {'components': dashboards, 'groups':SortedDict(non_empty_groups), 'user': context['request'].user, 'current': current_dashboard, 'request': context['request']}
def switch_tenants(request, tenant_id): """ Swaps a user from one tenant to another using the unscoped token from Keystone to exchange scoped tokens for the new tenant. """ form, handled = LoginWithTenant.maybe_handle( request, initial={'tenant': tenant_id, 'username': request.user.username}) if handled: return handled unscoped_token = request.session.get('unscoped_token', None) if unscoped_token: try: token = api.token_create_scoped(request, tenant_id, unscoped_token) _set_session_data(request, token) user = users.User(users.get_user_from_request(request)) return shortcuts.redirect(Horizon.get_user_home(user)) except: exceptions.handle(request, _("You are not authorized for that tenant.")) return shortcuts.redirect("horizon:auth_login")
def switch_tenants(request, tenant_id): """ Swaps a user from one tenant to another using the unscoped token from Keystone to exchange scoped tokens for the new tenant. """ form, handled = LoginWithTenant.maybe_handle( request, initial={'tenant': tenant_id, 'username': request.user.username}) if handled: return handled unscoped_token = request.session.get('unscoped_token', None) if unscoped_token: try: token = api.token_create_scoped(request, tenant_id, unscoped_token) _set_session_data(request, token) user = users.User(users.get_user_from_request(request)) return shortcuts.redirect(Horizon.get_user_home(user)) except exceptions.Unauthorized as e: messages.error(_("You are not authorized for that tenant.")) # FIXME(gabriel): we don't ship switch_tenants.html return shortcuts.render(request, 'switch_tenants.html', { 'to_tenant': tenant_id, 'form': form})
def horizon_nav(context): if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard', None) current_panel = context['request'].horizon.get('panel', None) dashboards = [] for dash in Horizon.get_dashboards(): panel_groups = dash.get_panel_groups() non_empty_groups = [] for group in panel_groups.values(): allowed_panels = [] for panel in group: if callable(panel.nav) and panel.nav(context) and \ panel.can_access(context): allowed_panels.append(panel) elif not callable(panel.nav) and panel.nav and \ panel.can_access(context): allowed_panels.append(panel) if allowed_panels: non_empty_groups.append((group.name, allowed_panels)) if callable(dash.nav) and dash.nav(context) and \ dash.can_access(context): dashboards.append((dash, SortedDict(non_empty_groups))) elif not callable(dash.nav) and dash.nav and \ dash.can_access(context): dashboards.append((dash, SortedDict(non_empty_groups))) return { 'components': dashboards, 'user': context['request'].user, 'current': current_dashboard, 'current_panel': current_panel.slug if current_panel else '', 'request': context['request'] }
def switch_tenants(request, tenant_id): """ Swaps a user from one tenant to another using the unscoped token from Keystone to exchange scoped tokens for the new tenant. """ form, handled = LoginWithTenant.maybe_handle(request, initial={ 'tenant': tenant_id, 'username': request.user.username }) if handled: return handled unscoped_token = request.session.get('unscoped_token', None) if unscoped_token: try: token = api.token_create_scoped(request, tenant_id, unscoped_token) _set_session_data(request, token) user = users.User(users.get_user_from_request(request)) return shortcuts.redirect(Horizon.get_user_home(user)) except exceptions.Unauthorized as e: messages.error(_("You are not authorized for that tenant.")) # FIXME(gabriel): we don't ship switch_tenants.html return shortcuts.render(request, 'switch_tenants.html', { 'to_tenant': tenant_id, 'form': form })
def horizon_nav(context): if "request" not in context: return {} current_dashboard = context["request"].horizon.get("dashboard", None) current_panel = context["request"].horizon.get("panel", None) dashboards = [] for dash in Horizon.get_dashboards(): panel_groups = dash.get_panel_groups() non_empty_groups = [] for group in panel_groups.values(): allowed_panels = [] for panel in group: if callable(panel.nav) and panel.nav(context): allowed_panels.append(panel) elif not callable(panel.nav) and panel.nav: allowed_panels.append(panel) if allowed_panels: non_empty_groups.append((group.name, allowed_panels)) if callable(dash.nav) and dash.nav(context): dashboards.append((dash, SortedDict(non_empty_groups))) elif not callable(dash.nav) and dash.nav: dashboards.append((dash, SortedDict(non_empty_groups))) return { "components": dashboards, "user": context["request"].user, "current": current_dashboard, "current_panel": current_panel.slug if current_panel else "", "request": context["request"], }
def horizon_nav(context): if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard', None) current_panel = context['request'].horizon.get('panel', None) dashboards = [] for dash in Horizon.get_dashboards(): panel_groups = dash.get_panel_groups() non_empty_groups = [] for group in panel_groups.values(): allowed_panels = [] for panel in group: if callable(panel.nav) and panel.nav(context): allowed_panels.append(panel) elif not callable(panel.nav) and panel.nav: allowed_panels.append(panel) if allowed_panels: non_empty_groups.append((group.name, allowed_panels)) if callable(dash.nav) and dash.nav(context): dashboards.append((dash, SortedDict(non_empty_groups))) elif not callable(dash.nav) and dash.nav: dashboards.append((dash, SortedDict(non_empty_groups))) return {'components': dashboards, 'user': context['request'].user, 'current': current_dashboard, 'current_panel': current_panel.slug if current_panel else '', 'request': context['request']}
def switch_tenants(request, tenant_id): """ Swaps a user from one tenant to another using the unscoped token from Keystone to exchange scoped tokens for the new tenant. """ form, handled = LoginWithTenant.maybe_handle(request, initial={ 'tenant': tenant_id, 'username': request.user.username }) if handled: return handled unscoped_token = request.session.get('unscoped_token', None) if unscoped_token: try: token = api.token_create_scoped(request, tenant_id, unscoped_token) _set_session_data(request, token) user = users.User(users.get_user_from_request(request)) return shortcuts.redirect(Horizon.get_user_home(user)) except: exceptions.handle(request, _("You are not authorized for that tenant.")) return shortcuts.redirect("horizon:auth_login")
def dashboard_register_mock(cls, panel): dashboard = horizon.get_dashboard(cls.slug) panel_policy_rules = [] # apply common rules if cls.slug in policy_rules: if '*' in policy_rules[cls.slug]: panel_policy_rules.extend(policy_rules[cls.slug]['*']) # apply required permissions/policy_rules if cls.slug in policy_rules and panel.slug in policy_rules[cls.slug]: panel_policy_rules.extend(policy_rules[cls.slug][panel.slug]) if len(panel_policy_rules) > 0: panel.policy_rules = panel_policy_rules # apply dashboard default panel if cls.slug in default_panel: dashboard.default_panel = default_panel[cls.slug] # register panel (original code) '''Registers a :class:`~horizon.Panel` with this dashboard.''' panel_class = Horizon.register_panel(cls, panel) # Support template loading from panel template directories. panel_mod = import_module(panel.__module__) panel_dir = os.path.dirname(panel_mod.__file__) template_dir = os.path.join(panel_dir, 'templates') if os.path.exists(template_dir): key = os.path.join(cls.slug, panel.slug) loaders.panel_template_dirs[key] = template_dir return panel_class
def process_exception(self, request, exception): """Catches internal Horizon exception classes. Exception classes such as NotAuthorized, NotFound and Http302 are caught and handles them gracefully. """ if isinstance(exception, exceptions.NotAuthenticated) or not \ request.user.is_authenticated(): auth_url = settings.LOGIN_URL next_url = iri_to_uri(request.get_full_path()) if next_url != auth_url: field_name = REDIRECT_FIELD_NAME else: field_name = None login_url = request.build_absolute_uri(auth_url) response = redirect_to_login(next_url, login_url=login_url, redirect_field_name=field_name) if request.is_ajax(): response_401 = http.HttpResponse(status=401) response_401['X-Horizon-Location'] = response['location'] response = response_401 login_user = request.COOKIES.get("login_user") if login_user: LOG.info("process_exception logout user %s", login_user) auth_utils.handle_user_logout(login_user) response.set_cookie("login_user") return response if isinstance(exception, exceptions.NotAuthorized): """ Not authorized could be a result of project context switching. redirect to dashboard page if it is possible or to homepage """ if hasattr(request.horizon, 'dashboard'): url = request.horizon.dashboard.get_absolute_url() else: # go home if there isn't dashboard url = Horizon.get_user_home(request.user) response = shortcuts.redirect(url) if request.is_ajax(): response_403 = http.HttpResponse(status=403) response_403['X-Horizon-Location'] = response['location'] return response_403 LOG.info('Access is not authorized, redirect to: %s', url) return response # If an internal "NotFound" error gets this far, return a real 404. if isinstance(exception, exceptions.NotFound): raise http.Http404(exception) if isinstance(exception, exceptions.Http302): # TODO(gabriel): Find a way to display an appropriate message to # the user *on* the login form... return shortcuts.redirect(exception.location)
def horizon_nav(context): if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard', None) current_panel_group = None current_panel = context['request'].horizon.get('panel', None) dashboards = [] try: Horizon.get_project_id(context) except: pass for dash in Horizon.get_dashboards(): panel_groups = dash.get_panel_groups() non_empty_groups = [] for group in panel_groups.values(): allowed_panels = [] for panel in group: if (callable(panel.nav) and panel.nav(context) and panel.can_access(context)): allowed_panels.append(panel) elif (not callable(panel.nav) and panel.nav and panel.can_access(context)): allowed_panels.append(panel) if panel == current_panel: current_panel_group = group.slug if allowed_panels: non_empty_groups.append((group, allowed_panels)) if (callable(dash.nav) and dash.nav(context) and dash.can_access(context)): dashboards.append((dash, OrderedDict(non_empty_groups))) elif (not callable(dash.nav) and dash.nav and dash.can_access(context)): dashboards.append((dash, OrderedDict(non_empty_groups))) return { 'components': dashboards, 'user': context['request'].user, 'current': current_dashboard, 'current_panel_group': current_panel_group, 'current_panel': current_panel.slug if current_panel else '', 'request': context['request'] }
def horizon_main_nav(context): """ Generates top-level dashboard navigation entries. """ if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard', None) dashboards = [] for dash in Horizon.get_dashboards(): if callable(dash.nav) and dash.nav(context): dashboards.append(dash) elif dash.nav: dashboards.append(dash) return {'components': dashboards, 'user': context['request'].user, 'current': getattr(current_dashboard, 'slug', None)}
def login(request): """ Logs in a user and redirects them to the URL specified by :func:`horizon.get_user_home`. """ if request.user.is_authenticated(): user = users.User(users.get_user_from_request(request)) return shortcuts.redirect(Horizon.get_user_home(user)) form, handled = Login.maybe_handle(request) if handled: return handled # FIXME(gabriel): we don't ship a view named splash return shortcuts.render(request, 'splash.html', {'form': form})
def horizon_main_nav(context): """ Generates top-level dashboard navigation entries. """ if 'request' not in context: return {} current_dashboard = context['request'].horizon.get('dashboard', None) dashboards = [] for dash in Horizon.get_dashboards(): if callable(dash.nav) and dash.nav(context): dashboards.append(dash) elif dash.nav: dashboards.append(dash) return {'components': dashboards, 'user': context['request'].user, 'current': current_dashboard, 'request': context['request']}
def horizon_main_nav(context): """ Generates top-level dashboard navigation entries. """ if "request" not in context: return {} current_dashboard = context["request"].horizon.get("dashboard", None) dashboards = [] for dash in Horizon.get_dashboards(): if callable(dash.nav) and dash.nav(context): dashboards.append(dash) elif dash.nav: dashboards.append(dash) return { "components": dashboards, "user": context["request"].user, "current": getattr(current_dashboard, "slug", None), }
# Author: DreamHost, LLC # # 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 horizon.base import Horizon nova_dashboard = Horizon.get_dashboard("project") compute_panel_group = nova_dashboard.get_panel_group("network") compute_panel_group.panels.append("networking") # # Manually override the definition of the router detail view method # to properly look up port data w/ akanda. May God have mercy on my soul. # from openstack_dashboard.dashboards.project.routers import views from akanda.horizon.routers.views import get_interfaces_data views.DetailView.get_interfaces_data = get_interfaces_data
from horizon.base import Horizon nova_dashboard = Horizon.get_dashboard('nova') compute_panel_group = nova_dashboard.get_panel_group('compute') compute_panel_group.panels.append('networking')
from horizon.base import Horizon nova_dashboard = Horizon.get_dashboard('project') compute_panel_group = nova_dashboard.get_panel_group('network') compute_panel_group.panels.append('networking')