示例#1
0
def soft_delete_data_doc(id):
    with DBSession() as session:
        doc = logic.get_data_doc_by_id(id=id, session=session)
        api_assert(doc, "Invalid doc")
        verify_environment_permission([doc.environment_id])
        api_assert(current_user.id == doc.owner_uid,
                   "You can only delete your own data doc")
        logic.update_data_doc(id=id, archived=True, session=session)
def update_datadoc_owner(doc_id, next_owner_id, originator=None):
    with DBSession() as session:
        # Add previous owner as an editor to the doc
        assert_is_owner(doc_id, session=session)
        current_owner_editor = logic.create_data_doc_editor(
            data_doc_id=doc_id,
            uid=current_user.id,
            read=True,
            write=True,
            commit=False,
            session=session,
        )
        current_owner_editor_dict = current_owner_editor.to_dict()
        # Remove next owner as a doc editor
        next_owner_editor = logic.get_data_doc_editor_by_id(
            next_owner_id, session=session
        )
        next_owner_editor_dict = next_owner_editor.to_dict()
        logic.delete_data_doc_editor(
            id=next_owner_id, doc_id=doc_id, session=session, commit=False
        )
        next_owner_uid = next_owner_editor_dict["uid"]
        # Update doc owner to next owner
        doc = logic.update_data_doc(
            id=doc_id, commit=False, session=session, owner_uid=next_owner_uid
        )
        doc_dict = doc.to_dict()
        session.commit()
        socketio.emit(
            "data_doc_editor",
            (originator, doc_id, current_user.id, current_owner_editor_dict),
            namespace="/datadoc",
            room=doc_id,
            broadcast=True,
        )
        socketio.emit(
            "data_doc_editor",
            (
                originator,
                next_owner_editor_dict["data_doc_id"],
                next_owner_editor_dict["uid"],
                None,
            ),
            namespace="/datadoc",
            room=next_owner_editor_dict["data_doc_id"],
            broadcast=True,
        )
        socketio.emit(
            "data_doc_updated",
            (originator, doc_dict,),
            namespace="/datadoc",
            room=next_owner_editor_dict["data_doc_id"],
            broadcast=True,
        )
        logic.update_es_data_doc_by_id(doc_id)
        send_datadoc_transfer_notification(doc_id, next_owner_uid, session)
        return current_owner_editor_dict
示例#3
0
def update_datadoc(doc_id, fields, sid="", session=None):
    # Check to see if author has permission
    assert_can_write(doc_id, session=session)
    verify_data_doc_permission(doc_id, session=session)
    doc = logic.update_data_doc(
        id=doc_id,
        session=session,
        **fields,
    )
    doc_dict = doc.to_dict()

    socketio.emit(
        "data_doc_updated",
        (
            sid,
            doc_dict,
        ),
        namespace=DATA_DOC_NAMESPACE,
        room=doc_id,
        broadcast=True,
    )

    return doc_dict