def get_organization_scope_from_slug(slug: str) -> SessionLocal: """Iterate all organizations looking for a relevant channel_id.""" db_session = SessionLocal() organization = organization_service.get_by_slug(db_session=db_session, slug=slug) db_session.close() if organization: schema_engine = engine.execution_options( schema_translate_map={ None: f"dispatch_organization_{slug}", }) return sessionmaker(bind=schema_engine)() raise ValidationError( [ ErrorWrapper( NotFoundError( msg= f"Organization slug '{slug}' not found. Check your spelling." ), loc="organization", ) ], model=BaseModel, )
def get_default_organization_scope() -> str: """Iterate all organizations looking for matching organization.""" db_session = SessionLocal() organization = organization_service.get_default(db_session=db_session) db_session.close() schema_engine = engine.execution_options( schema_translate_map={ None: f"dispatch_organization_{organization.slug}", }) return sessionmaker(bind=schema_engine)()
def get_organization_scope_from_channel_id(channel_id: str) -> SessionLocal: """Iterate all organizations looking for a relevant channel_id.""" db_session = SessionLocal() organization_slugs = [ o.slug for o in organization_service.get_all(db_session=db_session) ] db_session.close() for slug in organization_slugs: schema_engine = engine.execution_options( schema_translate_map={ None: f"dispatch_organization_{slug}", }) scoped_db_session = sessionmaker(bind=schema_engine)() conversation = conversation_service.get_by_channel_id_ignoring_channel_type( db_session=scoped_db_session, channel_id=channel_id) if conversation: return scoped_db_session scoped_db_session.close()
def list_tasks(client: Any, file_id: str): """Returns all tasks in file.""" doc = get_file(client, file_id) document_meta = {"document": {"id": file_id, "name": doc["name"]}} all_comments = list_comments(client, file_id) task_comments = filter_comments(all_comments) tasks = [] for t in task_comments: status = get_task_status(t) assignees = [{ "individual": { "email": x } } for x in get_assignees(t["content"])] description = t.get("quotedFileContent", {}).get("value", "") tickets = get_tickets(t["replies"]) task_meta = { "task": { "resource_id": t["id"], "description": description, "created_at": t["createdTime"], "assignees": assignees, "tickets": tickets, "weblink": f'https://docs.google.com/a/{GOOGLE_DOMAIN}/document/d/{file_id}/edit?disco={t["id"]}', } } # this is a dirty hack because google doesn't return emailAddresses for comments # complete with conflicting docs # https://developers.google.com/drive/api/v2/reference/comments#resource from dispatch.database.core import SessionLocal from dispatch.individual.models import IndividualContact db_session = SessionLocal() owner = (db_session.query(IndividualContact).filter( IndividualContact.name == t["author"]["displayName"]).first()) if owner: task_meta["task"].update( {"owner": { "individual": { "email": owner.email } }}) db_session.close() task_meta["task"].update(status) tasks.append({**document_meta, **task_meta}) return tasks