def role_permission_get(): """Function which gets all permissions from database and all actual permissions for current role. :return: {'actual': [list of actual permissions for role], 'all_permissions': [list of all permissions]} """ role_id = request.args.get('role_id') permissions_of_role = db.get_role_permission(role_id) all_permissions = db.get_all_permissions() parsed_json = {} if all_permissions: parsed_json['all_permissions'] = [] parsed_json['actual'] = [] for res in all_permissions: parsed_json['all_permissions'].append({'resource_id': res[0], 'action': res[2], 'modifier': res[3], 'description': res[4]}) parsed_json['actual'] = [({'permission_id': x[0], 'action': x[1], 'modifier': x[2], 'description': x[3]}) for x in permissions_of_role] return Response(json.dumps(parsed_json), mimetype='application/json')
def role_permission_get(): """Function which gets all permissions from database and all actual permissions for current role. :return: {'actual': [list of actual permissions for role], 'all_permissions': [list of all permissions]} """ role_id = request.args.get('role_id') permissions_of_role = db.get_role_permission(role_id) all_permissions = db.get_all_permissions() parsed_json = {} if all_permissions: parsed_json['all_permissions'] = [] parsed_json['actual'] = [] for res in all_permissions: parsed_json['all_permissions'].append({ 'resource_id': res[0], 'action': res[2], 'modifier': res[3], 'description': res[4] }) parsed_json['actual'] = [({ 'permission_id': x[0], 'action': x[1], 'modifier': x[2], 'description': x[3] }) for x in permissions_of_role] return Response(json.dumps(parsed_json), mimetype='application/json')
def get_all_permissions(): """Handler for sending all created permissions to frontend. :return: list of json """ all_permissions = db.get_all_permissions() perms_list = [] if all_permissions: for perm in all_permissions: perms_list.append({ 'permission_id': perm[0], 'resource_name': perm[1], 'action': perm[2], 'modifier': perm[3], 'description': perm[4] }) return Response(json.dumps(perms_list), mimetype='application/json')
def get_all_permissions(): """Function sends all created permissions to frontend. Handles with pagination options defined in query arguments. :rtype: JSON :query offset: pgination offset number. default is 0 :query limit: pagination limit number. default is 5 :return: - If permission tuple from DB is not empty: ``[[{"action": "POST", "permission_id": 6, "resource_name": "/api/register", "modifier": "Any", "description": "register user into app"}], [{"total_perm_count": 46}]]`` - If there are no permissions: ``{}`` :statuscode 200: no errors """ offset = request.args.get('offset') or 0 per_page = request.args.get('per_page') or 5 count = db.count_permissions() all_permissions = db.get_all_permissions(offset, per_page) permissions = [] total_count = {} if all_permissions: for perm in all_permissions: permissions.append({ 'permission_id': perm[0], 'resource_name': perm[1], 'action': perm[2], 'modifier': perm[3], 'description': perm[4] }) if count: total_count = {'total_perm_count': count[0]} return Response(json.dumps([permissions, [total_count]]), mimetype='application/json')
def get_all_permissions(): """Function sends all created permissions to frontend. Handles with pagination options defined in query arguments. :rtype: JSON :query offset: pgination offset number. default is 0 :query limit: pagination limit number. default is 5 :return: - If permission tuple from DB is not empty: ``[[{"action": "POST", "permission_id": 6, "resource_name": "/api/register", "modifier": "Any", "description": "register user into app"}], [{"total_perm_count": 46}]]`` - If there are no permissions: ``{}`` :statuscode 200: no errors """ offset = request.args.get('offset') or 0 per_page = request.args.get('per_page') or 5 count = db.count_permissions() all_permissions = db.get_all_permissions(offset, per_page) permissions = [] total_count = {} if all_permissions: for perm in all_permissions: permissions.append({ 'permission_id': perm[0], 'resource_name': perm[1], 'action': perm[2], 'modifier': perm[3], 'description': perm[4]}) if count: total_count = {'total_perm_count': count[0]} return Response(json.dumps([permissions, [total_count]]), mimetype='application/json')