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)
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)