def update_datadoc_editor( id, write=None, read=None, originator=None, # Used for websocket to identify sender, optional ): with DBSession() as session: editor = logic.get_data_doc_editor_by_id(id, session=session) if editor: assert_can_write(editor.data_doc_id, session=session) editor = logic.update_data_doc_editor(id, read, write, session=session) if editor: editor_dict = editor.to_dict() socketio.emit( "data_doc_editor", ( originator, editor_dict["data_doc_id"], editor_dict["uid"], editor_dict, ), namespace="/datadoc", room=editor_dict["data_doc_id"], broadcast=True, ) return editor_dict
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
def delete_datadoc_editor( id, originator=None, # Used for websocket to identify sender, optional ): with DBSession() as session: editor = logic.get_data_doc_editor_by_id(id, session=session) if editor: editor_dict = editor.to_dict() assert_can_write(editor.data_doc_id, session=session) logic.delete_data_doc_editor( id=id, doc_id=editor.data_doc_id, session=session ) socketio.emit( "data_doc_editor", (originator, editor_dict["data_doc_id"], editor_dict["uid"], None), namespace="/datadoc", room=editor_dict["data_doc_id"], broadcast=True, )