def testTraverseRelativeURL(self):
        provideAdapter(DummyPublishTraverse, (Interface, Interface), IPublishTraverse)
        provideAdapter(DummyBrowserPublisher, (Interface,), IBrowserPublisher)
        ob = Content()
        from zope.traversing.publicationtraverse import PublicationTraverser

        t = PublicationTraverser()
        request = TestRequest()
        proxy = t.traverseRelativeURL(request, ob, "foo/bar")
        view = removeSecurityProxy(proxy)
        self.assertTrue(proxy is not view)
        self.assertEqual(view.__class__, View)
        self.assertEqual(view.name, "more")
示例#2
0
 def testTraverseRelativeURL(self):
     provideAdapter(DummyPublishTraverse, (Interface, Interface),
                    IPublishTraverse)
     provideAdapter(DummyBrowserPublisher, (Interface, ), IBrowserPublisher)
     ob = Content()
     from zope.traversing.publicationtraverse import PublicationTraverser
     t = PublicationTraverser()
     request = TestRequest()
     proxy = t.traverseRelativeURL(request, ob, 'foo/bar')
     view = removeSecurityProxy(proxy)
     self.assertTrue(proxy is not view)
     self.assertEqual(view.__class__, View)
     self.assertEqual(view.name, 'more')
示例#3
0
    def available(self):
        # Make sure we have the permission needed to access the menu's action
        if self.permission is not None:
            # If we have an explicit permission, check that we
            # can access it.
            if not checkPermission(self.permission, self.context):
                return False

        elif self.action != _u(''):
            # Otherwise, test access by attempting access
            path = self.action
            l = self.action.find('?')
            if l >= 0:
                path = self.action[:l]

            traverser = PublicationTraverser()
            try:
                view = traverser.traverseRelativeURL(self.request,
                                                     self.context, path)
            except (Unauthorized, Forbidden, LookupError):
                return False
            else:
                # we're assuming that view pages are callable
                # this is a pretty sound assumption
                if not canAccess(view, '__call__'):
                    return False

        # Make sure that we really want to see this menu item
        if self.filter is not None:

            try:
                include = self.filter(
                    Engine.getContext(
                        context=self.context,
                        nothing=None,
                        request=self.request,
                        modules=sys.modules,
                    ))
            except Unauthorized:
                return False
            else:
                if not include:
                    return False

        return True
示例#4
0
    def available(self):
        # Make sure we have the permission needed to access the menu's action
        if self.permission is not None:
            # If we have an explicit permission, check that we
            # can access it.
            if not checkPermission(self.permission, self.context):
                return False

        elif self.action != u'':
            # Otherwise, test access by attempting access
            path = self.action
            l = self.action.find('?')
            if l >= 0:
                path = self.action[:l]

            traverser = PublicationTraverser()
            try:
                view = traverser.traverseRelativeURL(
                    self.request, self.context, path)
            except (Unauthorized, Forbidden, LookupError):
                return False
            else:
                # we're assuming that view pages are callable
                # this is a pretty sound assumption
                if not canAccess(view, '__call__'):
                    return False # pragma: no cover

        # Make sure that we really want to see this menu item
        if self.filter is not None:

            try:
                include = self.filter(Engine.getContext(
                    context=self.context,
                    nothing=None,
                    request=self.request,
                    modules=sys.modules,
                ))
            except Unauthorized:
                return False
            else:
                if not include:
                    return False

        return True