예제 #1
0
def check_availability(menu_item):
    """check availability of a menu against its permission and filter"""
    available = True
    if menu_item.permission is not None:
        available = checkPermission(menu_item.permission, menu_item.context)
    if available and menu_item.filter is not None:
        try:
            available = menu_item.filter(Engine.getContext(
                context = menu_item.context,
                nothing = None,
                request = menu_item.request,
                modules = sys.modules,
                ))
        except Unauthorized:
            available = False
    return available
예제 #2
0
def check_availability(menu_item):
    """check availability of a menu against its permission and filter"""
    available = True
    if menu_item.permission is not None:
        available = checkPermission(menu_item.permission, menu_item.context)
    if available and menu_item.filter is not None:
        try:
            available = menu_item.filter(
                Engine.getContext(
                    context=menu_item.context,
                    nothing=None,
                    request=menu_item.request,
                    modules=sys.modules,
                ))
        except Unauthorized:
            available = False
    return available
예제 #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