Example #1
0
def isallowed(context, operation, resource, authority=None):
    """
    Useful when you want to store ACL result in a variable to be tested with other parameters. For example :

    {% isallowed "my_operation" my_resource as can_do_operation %}
    {% if my_resource.some_boolean or can_do_operation %}
        Display stuff
    {% endif %}
    """
    authorities = [authority] if authority else None
    return is_allowed(context['request'], operation, resource, authorities)
Example #2
0
    def render(self, context):
        for check, nodelist in self.checks_nodelists:
            context['authority'] = None
            if check is not None:           # ifisallowed / elifisallowed clause
                try:
                    operation, resource = check
                    match = is_allowed(context['request'], operation.eval(context), resource.eval(context))

                    # add authority to template context
                    context['authority'] = match.authority
                except VariableDoesNotExist:
                    match = None
            else:                               # else clause
                match = True

            if match:
                return nodelist.render(context)

        return ''