From eb4d279bbc4e7816be486d74faff5b112d43e4db Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 11 Nov 2018 19:35:31 +0000 Subject: [PATCH] Extract get_turtle_message(). This seems like kind of a silly function to extract to topic.py, but it will theoretically help us sweep "subject" if we change the DB. It had test coverage. --- tools/linter_lib/custom_check.py | 1 - zerver/lib/onboarding.py | 6 ++---- zerver/lib/topic.py | 9 +++++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index f1e2ede4ca..c097398a92 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -40,7 +40,6 @@ FILES_WITH_LEGACY_SUBJECT = { # TRY TO FIX THESE! If you can't fix them, try to # add comments here and/or in the file itself about # why sweeping subject is tricky. - 'zerver/lib/onboarding.py', 'zerver/lib/stream_topic.py', # This has lots of query data embedded, so it's hard diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.py index 3a81c28722..893d6a97e1 100644 --- a/zerver/lib/onboarding.py +++ b/zerver/lib/onboarding.py @@ -5,6 +5,7 @@ from zerver.lib.actions import set_default_streams, bulk_add_subscriptions, \ internal_prep_stream_message, internal_send_private_message, \ create_stream_if_needed, create_streams_if_needed, do_send_messages, \ do_add_reaction_legacy, create_users, missing_any_realm_internal_bots +from zerver.lib.topic import get_turtle_message from zerver.models import Realm, UserProfile, Message, Reaction, get_system_bot from typing import Any, Dict, List, Mapping @@ -114,8 +115,5 @@ def send_initial_realm_messages(realm: Realm) -> None: # We find the one of our just-sent messages with turtle.png in it, # and react to it. This is a bit hacky, but works and is kinda a # 1-off thing. - turtle_message = Message.objects.get( - id__in=message_ids, - subject='topic demonstration', - content__icontains='cute/turtle.png') + turtle_message = get_turtle_message(message_ids=message_ids) do_add_reaction_legacy(welcome_bot, turtle_message, 'turtle') diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index 52fe75dd3b..bef5e3543e 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -227,3 +227,12 @@ def get_topic_history_for_web_public_stream(recipient: Recipient) -> List[Dict[s cursor.close() return generate_topic_history_from_db_rows(rows) + +def get_turtle_message(message_ids: List[int]) -> Message: + # This is used for onboarding, and it's only extracted + # here to make subject -> topic sweeping easier. + turtle_message = Message.objects.get( # nolint + id__in=message_ids, + subject='topic demonstration', + content__icontains='cute/turtle.png') + return turtle_message