def role_permission_delete():
    """Function to delete permissions by role id.

    :rtype: JSON
    :request args example: `{role_id: 4}`
    :return:
        - If request data is not invalid':
            ``{'status': False, 'error': [list of errors]}``
        - If all ok:
            ``{'msg': 'deleted permission'}``

    """
    data = request.get_json()

    valid = validator.role_permission_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(status='success', deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
def role_delete():
    """Function which deletes role from database.
    :return: If role has permissions:
                 {'error': 'Cannot delete!'}
             If request data is invalid:
                 {'status': False, error: [list of errors]}, 400
             If all ok:
                 {'status': 'success', 'deleted_role': 'role_id'}
    """
    data = request.get_json()

    valid = validator.role_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(msg='success',
                                   deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
def role_delete():
    """Function which deletes role from database by it id.

    :rtype: JSON
    :request args: `{role_id: 5}`
    :return:
        - If role has permissions:
            ``{'error': 'Cannot delete!'}``
        - If request data is invalid:
            ``{'status': False, error: [list of errors]}``
        - If all ok:
            ``{'status': 'success', 'deleted_role': 'role_id'}``

    :statuscode 400: if role has assigned permissions or request invalid
    :statuscode 200: if no errors

    """
    data = request.get_json()

    valid = validator.role_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(msg='success', deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
Exemple #4
0
def role_permission_delete():
    """Function to delete permissions by role id.

    :rtype: JSON
    :request args example: `{role_id: 4}`
    :return:
        - If request data is not invalid':
            ``{'status': False, 'error': [list of errors]}``
        - If all ok:
            ``{'msg': 'deleted permission'}``

    """
    data = request.get_json()

    valid = validator.role_permission_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(status='success',
                               deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
Exemple #5
0
def role_delete():
    """Function which deletes role from database by it id.

    :rtype: JSON
    :request args: `{role_id: 5}`
    :return:
        - If role has permissions:
            ``{'error': 'Cannot delete!'}``
        - If request data is invalid:
            ``{'status': False, error: [list of errors]}``
        - If all ok:
            ``{'status': 'success', 'deleted_role': 'role_id'}``

    :statuscode 400: if role has assigned permissions or request invalid
    :statuscode 200: if no errors

    """
    data = request.get_json()

    valid = validator.role_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(msg='success',
                                   deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
Exemple #6
0
def role_permission_delete():
    """Function to delete permissions."""
    data = request.get_json()

    valid = validator.role_permission_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(status='success', deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
def role_permission_delete():
    """Function to delete permissions."""
    data = request.get_json()

    valid = validator.role_permission_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(status='success',
                               deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response
Exemple #8
0
def role_delete():
    """Function which deletes role from database.
    :return: If role has permissions:
                 {'error': 'Cannot delete!'}
             If request data is invalid:
                 {'status': False, error: [list of errors]}, 400
             If all ok:
                 {'status': 'success', 'deleted_role': 'role_id'}
    """
    data = request.get_json()

    valid = validator.role_delete(data)

    if valid['status']:
        if not db.check_role_deletion(data['role_id']):
            db.delete_role_by_id(data['role_id'])
            response = jsonify(msg='success', deleted_role=data['role_id'])
            session['access_control'] = permission_control.reload_dct()
        else:
            response = jsonify(error='Cannot delete!')
    else:
        response = Response(json.dumps(valid),
                            mimetype='application/json'), 400
    return response