~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/browser/launchpad.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-22 21:04:00 UTC
  • mfrom: (13261.7.21 bzr-2.4b4)
  • mto: This revision was merged to the branch mainline in revision 13941.
  • Revision ID: jelmer@canonical.com-20110822210400-3hfq31q2wgrtauad
Merge bzr-2.4b4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    'LaunchpadRootNavigation',
16
16
    'LinkView',
17
17
    'LoginStatus',
 
18
    'Macro',
18
19
    'MaintenanceMessage',
19
20
    'NavigationMenuTabs',
20
21
    'SoftTimeoutView',
49
50
from zope.publisher.interfaces.browser import IBrowserPublisher
50
51
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
51
52
from zope.security.interfaces import Unauthorized
 
53
from zope.traversing.interfaces import ITraversable
52
54
 
53
55
from canonical.config import config
54
56
from canonical.launchpad.helpers import intOrZero
342
344
        return len(self.items) > 1 and not has_major_heading
343
345
 
344
346
 
 
347
class Macro:
 
348
    """Keeps templates that are registered as pages from being URL accessable.
 
349
 
 
350
    The standard pattern in LP is to register templates that contain macros as
 
351
    views on all objects:
 
352
 
 
353
    <browser:page
 
354
        for="*"
 
355
        name="+main-template-macros"
 
356
        template="../templates/base-layout-macros.pt"
 
357
        permission="zope.Public"
 
358
        />
 
359
 
 
360
    Without this class, that pattern would make the template URL traversable
 
361
    from any object.  Therefore requests like these would all "work":
 
362
 
 
363
        http://launchpad.net/+main-template-macros
 
364
        http://launchpad.net/ubuntu/+main-template-macros
 
365
        http://launchpad.net/ubuntu/+main-template-macros
 
366
        https://blueprints.launchpad.dev/ubuntu/hoary/+main-template-macros
 
367
 
 
368
    Obviously, those requests wouldn't do anything useful and would instead
 
369
    generate an OOPS.
 
370
 
 
371
    It would be nice to use a different pattern for macros instead, but we've
 
372
    grown dependent on some of the peculiatrities of registering macro
 
373
    templates in this way.
 
374
 
 
375
    This class was created in order to prevent macro templates from being
 
376
    accessable via URL without having to make nontrivial changes to the many,
 
377
    many templates that use macros.  To use the class add a "class" parameter
 
378
    to macro template registrations:
 
379
 
 
380
    <browser:page
 
381
        for="*"
 
382
        name="+main-template-macros"
 
383
        template="../templates/base-layout-macros.pt"
 
384
        class="lp.app.browser.launchpad.Macro"
 
385
        permission="zope.Public"
 
386
        />
 
387
    """
 
388
    implements(IBrowserPublisher, ITraversable)
 
389
 
 
390
    def __init__(self, context, request):
 
391
        self.context = context
 
392
 
 
393
    def traverse(self, name, furtherPath):
 
394
        return self.index.macros[name]
 
395
 
 
396
    def browserDefault(self, request):
 
397
        return self, ()
 
398
 
 
399
    def publishTraverse(self, request, name):
 
400
        raise NotFound(self.context, self.__name__)
 
401
 
 
402
    def __call__(self):
 
403
        raise NotFound(self.context, self.__name__)
 
404
 
 
405
 
345
406
class MaintenanceMessage:
346
407
    """Display a maintenance message if the control file is present and
347
408
    it contains a valid iso format time.