def notifiy_on_execution_completion(query_execution_id, session=None): query_execution = qe_logic.get_query_execution_by_id(query_execution_id, session=session) notifications = query_execution.notifications if len(notifications): data_cell = next(iter(query_execution.cells), None) # TODO: this should be determined by the notification.user? # Come up with a more efficient way to determine env per user env_name = getattr( qe_perm_logic.get_default_user_environment_by_execution_id( execution_id=query_execution_id, uid=query_execution.uid, session=session, ), "name", None, ) # If the query execution is not associated with any environment # then no notification can be done if not env_name: return for notification in notifications: uid = notification.user user = user_logic.get_user_by_id(uid, session=session) doc_id = None cell_id = None query_title = "Untitled" if data_cell is not None: cell_id = data_cell.id doc_id = data_cell.doc.id query_title = data_cell.meta.get("title", query_title) notify_user( user=user, template_name="query_completion_notification", template_params=dict( query_execution=query_execution, doc_id=doc_id, cell_id=cell_id, query_title=query_title, public_url=QuerybookSettings.PUBLIC_URL, env_name=env_name, ), session=session, )
def send_query_execution_invitation_notification(execution_id, uid, session=None): inviting_user = user_logic.get_user_by_id(current_user.id, session=session) invited_user = user_logic.get_user_by_id(uid, session=session) environment = get_default_user_environment_by_execution_id( execution_id=execution_id, uid=uid, session=session ) execution_url = f"{QuerybookSettings.PUBLIC_URL}/{environment.name}/query_execution/{execution_id}/" notify_user( user=invited_user, template_name="query_execution_invitation", template_params=dict( inviting_username=inviting_user.get_name(), execution_id=execution_id, execution_url=execution_url, ), session=session, )
def send_query_execution_access_request_notification(execution_id, uid, session=None): requestor = user_logic.get_user_by_id(uid, session=session) query_execution = logic.get_query_execution_by_id(execution_id, session=session) environment = get_default_user_environment_by_execution_id( execution_id=execution_id, uid=uid, session=session ) execution_url = f"{QuerybookSettings.PUBLIC_URL}/{environment.name}/query_execution/{execution_id}/" owner = user_logic.get_user_by_id(query_execution.uid, session=session) requestor_username = requestor.get_name() notify_user( user=owner, template_name="query_execution_access_request", template_params=dict( username=requestor_username, execution_id=execution_id, execution_url=execution_url, ), )