'Check permission to access a record with method
@param method: the access method (string)
@param c: the controller name (falls back to current request)
@param f: the function name (falls back to current request)
@param t: the table or tablename
@param record: the record or record ID (None for any record)'

def has_permission(self, method, c=None, f=None, t=None, record=None):

    if isinstance(method, (list, tuple)):
        for m in method:
            if self.has_permission(m, c=c, f=f, t=t, record=record):
                return True
        return False
    else:
        method = [method]
    if (record == 0):
        record = None
    auth = self.auth
    if auth.override:
        return True
    sr = auth.get_system_roles()
    logged_in = auth.s3_logged_in()
    self.check_settings()
    racl = self.required_acl(method)
    if (not logged_in):
        realms = Storage({sr.ANONYMOUS: None})
        delegations = Storage()
    else:
        realms = auth.user.realms
        delegations = auth.user.delegations
    if (sr.ADMIN in realms):
        return True
    if (not self.use_cacls):
        if logged_in:
            return True
        else:
            if self.page_restricted(c=c, f=f):
                permitted = (racl == self.READ)
            else:
                permitted = True
            return permitted
    if ((t is not None) and (record is not None)):
        owners = self.get_owners(t, record)
        is_owner = self.is_owner(t, record, owners=owners)
        entity = owners[0]
    else:
        owners = []
        is_owner = True
        entity = None
    c = (c or self.controller)
    f = (f or self.function)
    permission_cache = self.permission_cache
    if (permission_cache is None):
        permission_cache = self.permission_cache = {}
    key = ('%s/%s/%s/%s/%s' % (method, c, f, t, record))
    if (key in permission_cache):
        return permission_cache[key]
    acls = self.applicable_acls(racl, realms=realms, delegations=delegations, c=c, f=f, t=t, entity=entity)
    permitted = None
    if (acls is None):
        permitted = True
    elif (not acls):
        permitted = False
    else:
        if entity:
            if (entity in acls):
                (uacl, oacl) = acls[entity]
            elif ('ANY' in acls):
                (uacl, oacl) = acls['ANY']
            else:
                permitted = False
        else:
            (uacl, oacl) = self.most_permissive(acls.values())
        if (permitted is None):
            if ((uacl & racl) == racl):
                permitted = True
            elif ((oacl & racl) == racl):
                permitted = is_owner
            else:
                permitted = False
    if (permitted is None):
        raise self.error('Cannot    determine    permission.')
    elif (permitted and (t is not None) and (record is not None) and self.requires_approval(t)):
        if (not hasattr(t, '_tablename')):
            table = current.s3db.table(t)
            if (not table):
                raise AttributeError(('undefined    table    %s' % t))
        else:
            table = t
        if ('approved_by' in table.fields):
            approval_methods = ('approve', 'review', 'reject')
            access_approved = (not all([(m in approval_methods) for m in method]))
            access_unapproved = any([(m in method) for m in approval_methods])
            if access_unapproved:
                if (not access_approved):
                    permitted = self.unapproved(table, record)
            else:
                permitted = (self.approved(table, record) or self.is_owner(table, record, owners, strict=True) or self.has_permission('review', t=table, record=record))
        else:
            pass
    permission_cache[key] = permitted
    return permitted
