Exemple #1
0
def start_edit_article_workflow(recid):
    try:
        record = get_db_record('lit', recid)
    except RecordGetterError:
        raise CallbackRecordNotFoundError(recid)

    record_permission = RecordPermission.create(action='update', record=record)
    if not record_permission.can():
        abort(403, record_permission)
    # has to be done before start() since, it is deattaching this session
    user_id = current_user.get_id()
    eng_uuid = start('edit_article', data=record)
    workflow_id = WorkflowEngine.from_uuid(eng_uuid).objects[0].id
    workflow = workflow_object_class.get(workflow_id)
    workflow.id_user = user_id
    if request.referrer:
        base_rt_url = get_rt_link_for_ticket('').replace('?', '\?')
        ticket_match = re.match(base_rt_url + '(?P<ticket_id>\d+)',
                                request.referrer)
        if ticket_match:
            ticket_id = int(ticket_match.group('ticket_id'))
            workflow.extra_data['curation_ticket_id'] = ticket_id

    workflow.save()
    db.session.commit()
    url = "{}{}".format(current_app.config['WORKFLOWS_EDITOR_API_URL'],
                        workflow_id)
    return redirect(location=url, code=302)
Exemple #2
0
    def put(self):
        """Handle callback for merge conflicts."""
        workflow_data = workflow_loader()
        workflow_id = workflow_data['id']

        try:
            workflow = workflow_object_class.get(workflow_id)
        except WorkflowsMissingObject:
            raise CallbackWorkflowNotFoundError(workflow_id)

        if workflow.status != ObjectStatus.WAITING or \
           'callback_url' not in workflow.extra_data:
            raise CallbackWorkflowNotInWaitingEditState(workflow.id)

        recid = workflow_data['metadata'].get('control_number')
        try:
            record = get_db_record('lit', recid)
        except RecordGetterError:
            raise CallbackRecordNotFoundError(recid)

        record_permission = RecordPermission.create(action='update',
                                                    record=record)
        if not record_permission.can():
            abort(403, record_permission)

        workflow_id = workflow.id
        workflow.data = workflow_data['metadata']
        workflow.status = ObjectStatus.RUNNING
        workflow.extra_data.pop('callback_url', None)
        workflow.save()
        db.session.commit()
        workflow.continue_workflow(delayed=True)

        ticket_id = workflow_data['_extra_data'].get('curation_ticket_id')
        if ticket_id:
            redirect_url = get_rt_link_for_ticket(ticket_id)
        else:
            redirect_url = '%s://%s/' % (request.scheme, request.host)

        data = {
            'message': 'Workflow {} is continuing.'.format(workflow_id),
            'redirect_url': redirect_url,
        }
        return jsonify(data), 200