Beispiel #1
0
def get_datadoc_schedule_run(id):
    with DBSession() as session:
        assert_can_read(id, session=session)
        verify_data_doc_permission(id, session=session)

        runs, _ = schedule_logic.get_task_run_record_run_by_name(
            name=get_data_doc_schedule_name(id), session=session)
        return runs
Beispiel #2
0
def on_join_room(data_doc_id: str):
    data_doc_id = int(data_doc_id)
    with DBSession() as session:
        assert_can_read(data_doc_id, session=session)
        data_doc = logic.get_data_doc_by_id(data_doc_id, session=session)
        verify_environment_permission([data_doc.environment_id])

        join_room(data_doc_id)
        update_user_list(data_doc_id, add=True)
Beispiel #3
0
def get_datadoc_schedule(id):
    with DBSession() as session:
        assert_can_read(id, session=session)
        verify_data_doc_permission(id, session=session)

        schedule_name = schedule_logic.get_data_doc_schedule_name(id)
        schedule = schedule_logic.get_task_schedule_by_name(schedule_name,
                                                            session=session)
        if not schedule:
            return None

        schedule_dict = schedule.to_dict()
        schedule_dict["kwargs"] = convert_if_legacy_datadoc_schedule(
            schedule_dict["kwargs"])
        return schedule_dict
Beispiel #4
0
def clone_data_doc(id):
    with DBSession() as session:
        assert_can_read(id, session=session)
        try:
            verify_data_doc_permission(id, session=session)
            data_doc = logic.clone_data_doc(id=id,
                                            owner_uid=current_user.id,
                                            session=session)
            doc_dict = data_doc.to_dict(with_cells=True)
        except AssertionError as e:
            LOG.debug("Assert error")
            LOG.debug(e)
            api_assert(False, str(e))

        return doc_dict
Beispiel #5
0
def get_datadoc(doc_id, session=None):
    assert_can_read(doc_id, session=session)
    doc = logic.get_data_doc_by_id(id=doc_id, session=session)
    if doc:
        verify_environment_permission([doc.environment_id])
        return doc.to_dict(with_cells=True)
Beispiel #6
0
def paste_data_cell(cell_id: int,
                    cut: bool,
                    doc_id: int,
                    index: int,
                    sid="",
                    session=None):
    data_cell = logic.get_data_cell_by_id(cell_id, session=session)
    assert data_cell is not None, "Data cell does not exist"

    data_doc = logic.get_data_doc_by_id(doc_id, session=session)
    old_data_doc = data_cell.doc
    same_doc = old_data_doc.id == doc_id
    # Make sure they are in the same environment and have access
    assert (old_data_doc.environment_id == data_doc.environment_id
            ), "Must be in the same environment"
    verify_environment_permission([data_doc.environment_id])

    # Users need to be able to write in the doc copied to
    assert_can_write(doc_id, session=session)
    if not same_doc:
        if cut:
            # To cut the user need to be able to write the original doc
            assert_can_write(old_data_doc.id, session=session)
        else:
            # To copy the user need to be able to read the original doc
            assert_can_read(old_data_doc.id, session=session)

    if cut:
        old_cell_index = logic.get_data_doc_data_cell(
            cell_id, session=session).cell_order
        logic.move_data_doc_cell_to_doc(cell_id,
                                        doc_id,
                                        index,
                                        session=session)
        if same_doc:
            # Account for shift in original index
            # See more details in move_data_doc_cell_to_doc
            if old_cell_index < index:
                index -= 1
            socketio.emit(
                "data_cell_moved",
                # sid, from_index, to_index
                (
                    sid,
                    old_cell_index,
                    index,
                ),
                namespace=DATA_DOC_NAMESPACE,
                room=doc_id,
                broadcast=True,
            )
        else:
            socketio.emit(
                "data_cell_inserted",
                (
                    sid,
                    index,
                    data_cell.to_dict(),
                ),
                namespace=DATA_DOC_NAMESPACE,
                room=doc_id,
                broadcast=True,
            )
            socketio.emit(
                "data_cell_deleted",
                (
                    sid,
                    cell_id,
                ),
                namespace=DATA_DOC_NAMESPACE,
                room=old_data_doc.id,
                broadcast=True,
            )
    else:  # Copy
        new_cell_dict = insert_data_cell(
            doc_id,
            index,
            data_cell.cell_type.name,
            data_cell.context,
            data_cell.meta,
            sid,
            session=session,
        )
        # Copy all query history over
        logic.copy_cell_history(cell_id, new_cell_dict["id"], session=session)

    # To resolve the sender's promise
    socketio.emit(
        "data_cell_pasted",
        (sid),
        namespace=DATA_DOC_NAMESPACE,
        room=doc_id,
        broadcast=False,
    )
Beispiel #7
0
def get_data_doc_id_by_data_cell_id(id):
    with DBSession() as session:
        verify_data_cell_permission(id, session=session)
        data_doc = logic.get_data_doc_by_data_cell_id(id, session=session)
        assert_can_read(data_doc.id, session=session)
        return data_doc.id
Beispiel #8
0
def get_dag_export(id):
    assert_can_read(id)
    verify_data_doc_permission(id)
    return logic.get_dag_export_by_data_doc_id(data_doc_id=id)