@wraps(func)
def wrapper(*args, **kwargs):
    method = func.__name__
    resource_names = [resource.__tablename__ for resource in resources]
    need_permission = set([((method + '_') + resource_name) for resource_name in resource_names])
    user = getattr(g, 'user', '')
    has_permission_set = set()
    is_clusteradmin = (user.is_clusteradmin if user else 0)
    if is_clusteradmin:
        return func(*args, **kwargs)
    if user:
        for role in user.roles:
            for permission in role.permissions:
                has_permission_set.add(permission.permission_name)
        if (not need_permission.issubset(has_permission_set)):
            return ResponseBase(json.dumps({'status': 403, 'message': u'权限不足，请联系管理员'}), status=403, content_type='application/json')
        else:
            return func(*args, **kwargs)
    else:
        return ResponseBase(json.dumps({'status': 401, 'message': u'请先登录'}), status=401, content_type='application/json')
@wraps(func)
def wrapper(*args, **kwargs):
    method = func.__name__
    resource_names = [resource.__tablename__ for resource in resources]
    need_permission = set([((method + '_') + resource_name) for resource_name in resource_names])
    user = getattr(g, 'user', )
    has_permission_set = set()
    is_clusteradmin = (user.is_clusteradmin if user else 0)
    if is_clusteradmin:
        return func(*args, **kwargs)
    if user:
        for role in user.roles:
            for permission in role.permissions:
                has_permission_set.add(permission.permission_name)
        if (not need_permission.issubset(has_permission_set)):
            return ResponseBase(json.dumps({'status': 403, 'message': u'权限不足，请联系管理员'}), status=403, content_type='application/json')
        else:
            return func(*args, **kwargs)
    else:
        return ResponseBase(json.dumps({'status': 401, 'message': u'请先登录'}), status=401, content_type='application/json')