code: def has_permission(user, *permissions, **role_kwargs):
      
      Role = get_model('role')
      Perm = get_model('permission')
      if isinstance(user, (unicode, str)):
          User = get_model('user')
          user = User.get(User.c.username==user)
          
      for name in permissions:
          perm = Perm.get(Perm.c.name==name)
          if not perm:
              continue
          
          flag = has_role(user, *list(perm.perm_roles.with_relation().all()), **role_kwargs)
          if flag:
              return flag
          
      return False
docs: Judge if an user has permission, and if it does return role object, and if it doesn't
      return False. role_kwargs will be passed to role functions.
      With role object, you can use role.relation to get Role_Perm_Rel object.