~ubuntu-branches/ubuntu/vivid/horizon/vivid-proposed

« back to all changes in this revision

Viewing changes to horizon/base.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant, Chuck Short, Corey Bryant, James Page
  • Date: 2015-01-05 16:42:06 UTC
  • mfrom: (0.9.1) (1.2.5)
  • Revision ID: package-import@ubuntu.com-20150105164206-zrt2q64h4weugkur
Tags: 1:2015.1~b1-0ubuntu1
[ Chuck Short ]
* Open for Kilo.
* d/control: Update bzr branches 
* d/patches/embedded-xstatic.patch: Refreshed
* d/patches/add-juju-environment-download.patch: Temporarily disabled.

[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/watch: Update uversionmangle for kilo beta naming.
* d/control: Bumped Standards-Version to 3.9.6.

[ James Page ]
* d/bundle-xstatic.sh: Tweak grep to be case insensitive.
* d/p/add-juju-environment-download.patch: Rebase for kilo-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import os
28
28
 
29
29
from django.conf import settings
30
 
from django.conf.urls import include  # noqa
 
30
from django.conf.urls import include
31
31
from django.conf.urls import patterns
32
32
from django.conf.urls import url
33
33
from django.core.exceptions import ImproperlyConfigured  # noqa
56
56
            _decorate_urlconf(pattern.url_patterns, decorator, *args, **kwargs)
57
57
 
58
58
 
 
59
def access_cached(func):
 
60
    def inner(self, context):
 
61
        session = context['request'].session
 
62
        try:
 
63
            if session['allowed']['valid_for'] != session.get('token'):
 
64
                raise KeyError()
 
65
        except KeyError:
 
66
            session['allowed'] = {"valid_for": session.get('token')}
 
67
 
 
68
        key = "%s.%s" % (self.__class__.__module__, self.__class__.__name__)
 
69
        if key not in session['allowed']:
 
70
            session['allowed'][key] = func(self, context)
 
71
            session.modified = True
 
72
        return session['allowed'][key]
 
73
    return inner
 
74
 
 
75
 
59
76
class NotRegistered(Exception):
60
77
    pass
61
78
 
90
107
                urlpatterns = patterns('')
91
108
        return urlpatterns
92
109
 
 
110
    @access_cached
93
111
    def can_access(self, context):
94
 
        """Checks to see that the user has role based access to this component.
 
112
        """Return whether the user has role based access to this component.
 
113
 
 
114
        This method is not intended to be overridden.
 
115
        The result of the method is stored in per-session cache.
 
116
        """
 
117
        return self.allowed(context)
 
118
 
 
119
    def allowed(self, context):
 
120
        """Checks if the user is allowed to access this component.
95
121
 
96
122
        This method should be overridden to return the result of
97
123
        any policy checks required for the user to access this component
433
459
        return all_panels
434
460
 
435
461
    def get_panel_group(self, slug):
436
 
        return self._panel_groups[slug]
 
462
        """Returns the specified :class:~horizon.PanelGroup
 
463
        or None if not registered
 
464
        """
 
465
        return self._panel_groups.get(slug)
437
466
 
438
467
    def get_panel_groups(self):
439
468
        registered = copy.copy(self._registry)
484
513
                continue
485
514
            url_slug = panel.slug.replace('.', '/')
486
515
            urlpatterns += patterns('',
487
 
                    url(r'^%s/' % url_slug, include(panel._decorated_urls)))
 
516
                                    url(r'^%s/' % url_slug,
 
517
                                        include(panel._decorated_urls)))
488
518
        # Now the default view, which should come last
489
519
        if not default_panel:
490
520
            raise NotRegistered('The default panel "%s" is not registered.'
491
521
                                % self.default_panel)
492
522
        urlpatterns += patterns('',
493
 
                url(r'', include(default_panel._decorated_urls)))
 
523
                                url(r'',
 
524
                                    include(default_panel._decorated_urls)))
494
525
 
495
526
        # Require login if not public.
496
527
        if not self.public:
568
599
                del loaders.panel_template_dirs[key]
569
600
        return success
570
601
 
571
 
    def can_access(self, context):
 
602
    def allowed(self, context):
572
603
        """Checks for role based access for this dashboard.
573
604
 
574
605
        Checks for access to any panels in the dashboard and of the the
809
840
        # Compile the dynamic urlconf.
810
841
        for dash in self._registry.values():
811
842
            urlpatterns += patterns('',
812
 
                    url(r'^%s/' % dash.slug, include(dash._decorated_urls)))
 
843
                                    url(r'^%s/' % dash.slug,
 
844
                                        include(dash._decorated_urls)))
813
845
 
814
846
        # Return the three arguments to django.conf.urls.include
815
847
        return urlpatterns, self.namespace, self.slug