Ejemplo n.º 1
0
def update_annotation(id):
    annotation = Annotation.fetch(id)
    if not annotation:
        return jsonify('Annotation not found! No update performed.',
                       status=404)

    failure = _check_action(annotation, 'update')
    if failure:
        return failure

    if request.json is not None:
        updated = _filter_input(request.json, UPDATE_FILTER_FIELDS)
        updated[
            'id'] = id  # use id from URL, regardless of what arrives in JSON payload

        if 'permissions' in updated and updated[
                'permissions'] != annotation.get('permissions', {}):
            failure = _check_action(annotation,
                                    'admin',
                                    message='permissions update')
            if failure:
                return failure

        annotation.update(updated)

        if hasattr(g, 'before_annotation_update'):
            g.before_annotation_update(annotation)

        refresh = request.args.get('refresh') != 'false'
        annotation.save(refresh=refresh)

    return jsonify(annotation)
Ejemplo n.º 2
0
def update_annotation(id):
    annotation = Annotation.fetch(id)
    if not annotation:
        return jsonify('Annotation not found! No update performed.', status=404)

    failure = _check_action(annotation, 'update')
    if failure:
        return failure

    if request.json:
        updated = _filter_input(request.json, UPDATE_FILTER_FIELDS)
        updated['id'] = id # use id from URL, regardless of what arrives in JSON payload

        if 'permissions' in updated and updated['permissions'] != annotation.get('permissions', {}):
            failure = _check_action(annotation, 'admin', message='permissions update')
            if failure:
                return failure

        annotation.update(updated)

        if hasattr(g, 'before_annotation_update'):
            g.before_annotation_update(annotation)

        annotation.save()

    return jsonify(annotation)
Ejemplo n.º 3
0
def update_annotation(id):
    annotation = Annotation.fetch(id)
    if not annotation:
        return jsonify("Annotation not found! No update performed.", status=404)

    failure = _check_action(annotation, "update")
    if failure:
        return failure

    if request.json is not None:
        updated = _filter_input(request.json, UPDATE_FILTER_FIELDS)
        updated["id"] = id  # use id from URL, regardless of what arrives in
        # JSON payload

        changing_permissions = "permissions" in updated and updated["permissions"] != annotation.get("permissions", {})

        if changing_permissions:
            failure = _check_action(annotation, "admin", message="permissions update")
            if failure:
                return failure

        annotation.update(updated)

        if hasattr(g, "before_annotation_update"):
            g.before_annotation_update(annotation)

        refresh = request.args.get("refresh") != "false"
        annotation.save(refresh=refresh)

        if hasattr(g, "after_annotation_update"):
            g.after_annotation_update(annotation)

    return jsonify(annotation)
Ejemplo n.º 4
0
def update_annotation(id):
    annotation = g.annotation_class.fetch(id)
    if not annotation:
        return jsonify('Annotation not found! No update performed.',
                       status=404)

    failure = _check_action(annotation, 'update')
    if failure:
        return failure

    if request.json is not None:
        updated = _filter_input(request.json, UPDATE_FILTER_FIELDS)
        updated['id'] = id  # use id from URL, regardless of what arrives in
                            # JSON payload

        changing_permissions = (
            'permissions' in updated and
            updated['permissions'] != annotation.get('permissions', {}))

        if changing_permissions:
            failure = _check_action(annotation,
                                    'admin',
                                    message='permissions update')
            if failure:
                return failure

        annotation.update(updated)

        if hasattr(g, 'before_annotation_update'):
            g.before_annotation_update(annotation)

        refresh = request.args.get('refresh') != 'false'
        annotation.save(refresh=refresh)

        if hasattr(g, 'after_annotation_update'):
            g.after_annotation_update(annotation)

    return jsonify(annotation)