diff --git a/inspirehep/modules/editor/views.py b/inspirehep/modules/editor/views.py index 0d2c6a3fdd..0017123d53 100644 --- a/inspirehep/modules/editor/views.py +++ b/inspirehep/modules/editor/views.py @@ -33,6 +33,7 @@ from inspirehep.modules.pidstore.utils import get_pid_type_from_endpoint from inspirehep.modules.tools import authorlist +from inspirehep.modules.workflows.workflows.manual_merge import start_merger from inspirehep.utils.record_getter import get_db_record from inspirehep.utils.references import ( get_refextract_kbs_path, @@ -216,6 +217,17 @@ def get_rt_queues(): return jsonify(tickets.get_queues()) +@blueprint.route('/manual_merge', methods=['POST']) +@editor_use_api_permission.require(http_exception=403) +def start_manual_merge(): + """Initiate manual merge on two records.""" + assert request.json['head_recid'] + assert request.json['update_recid'] + + workflow_id = start_merger(request.json['head_recid'], request.json['update_recid'], current_user.get_id()) + return jsonify(workflow_object_id=workflow_id) + + def _simplify_ticket_response(ticket): return dict( id=ticket['Id'], diff --git a/tests/integration/editor/test_editor_views.py b/tests/integration/editor/test_editor_views.py index c67c9bff36..735adc6d27 100644 --- a/tests/integration/editor/test_editor_views.py +++ b/tests/integration/editor/test_editor_views.py @@ -426,3 +426,21 @@ def test_refextract_url(log_in_as_cataloger, api_client): assert response.status_code == 200 assert validate(references, subschema) is None assert get_value({'references': references}, 'references.reference.publication_info.journal_title') + + +@patch('inspirehep.modules.editor.views.start_merger') +def test_manual_merge(mock_start_merger, log_in_as_cataloger, api_client): + mock_start_merger.return_value = 100 + + response = api_client.post( + '/editor/manual_merge', + content_type='application/json', + data=json.dumps({ + 'head_recid': 1000, + 'update_recid': 1001, + }) + ) + assert response.status_code == 200 + + response_json = json.loads(response.data) + assert response_json['workflow_object_id'] == 100