<commit_before>from .vars import *
import web

class AccessChecker:
    """An object that checks whether an operation (or request) has the right permission"""
    WARN_ONLY=False # Set to True to give only warnings about missing capabilities, but allow everything nonetheless

    def __init__(self, destination):
        self.destination = destination
        
    def allowed(self, operation, token):
        """Test whether the token (or set of tokens) allows this operation on the element represented by this AccessChecker"""
        if not token:
            print 'access: %s %s: no access allowed for token=None' % (operation, self.destination)
            if self.WARN_ONLY:
                print 'access: allowed anyway because of --warncapabilities mode'
                return True
            return False
        if not operation in ALL_OPERATIONS:
            raise myWebError("500 Access: unknown operation '%s'" % operation)
        ok = token._allows(operation, self)
        if not ok:
            identifiers = token._getIdentifiers()
            print '\taccess: %s %s: no access allowed by %d tokens:' % (operation, self.destination, len(identifiers))
            for i in identifiers:
                print '\t\t%s' % i
            try:
                print '\taccess: On behalf of request to %s' % web.ctx.path
            except AttributeError:
                pass
            try:
                print '\taccess: On behalf of action %s' % web.ctx.original_action
            except AttributeError:
                pass
            try:
                print '\taccess: Representing  %s' % web.ctx.representing
            except AttributeError:
                pass
                <commit_msg>Fixed bug in how action and representing are picked up when reporting access control errors<commit_after>from .vars import *
import web

class AccessChecker:
    """An object that checks whether an operation (or request) has the right permission"""
    WARN_ONLY=False # Set to True to give only warnings about missing capabilities, but allow everything nonetheless

    def __init__(self, destination):
        self.destination = destination
        
    def allowed(self, operation, token):
        """Test whether the token (or set of tokens) allows this operation on the element represented by this AccessChecker"""
        if not token:
            print 'access: %s %s: no access allowed for token=None' % (operation, self.destination)
            if self.WARN_ONLY:
                print 'access: allowed anyway because of --warncapabilities mode'
                return True
            return False
        if not operation in ALL_OPERATIONS:
            raise myWebError("500 Access: unknown operation '%s'" % operation)
        ok = token._allows(operation, self)
        if not ok:
            identifiers = token._getIdentifiers()
            print '\taccess: %s %s: no access allowed by %d tokens:' % (operation, self.destination, len(identifiers))
            for i in identifiers:
                print '\t\t%s' % i
            try:
                print '\taccess: On behalf of request to %s' % web.ctx.path
            except AttributeError:
                pass
            try:
                original_action = web.ctx.env.get('original_action')
                if original_action:
                    print '\taccess: On behalf of action %s' % original_action
            except AttributeError:
                pass
            try:
                representing = web.ctx.env.get('representing')
                if representing:
                    print '\taccess: Representing  %s' % representing
            except AttributeError:
                pass
                
{'fraction_non_alphanumeric': 0.0737550471063257, 'fraction_numerical': 0.0016150740242261105, 'mean_word_length': 1.9099451840250588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5734323', 'n_tokens_mistral': 888, 'n_tokens_neox': 853, 'n_words': 350}