From 7f6fe128f676637f64d085539d8cac0781c9595b Mon Sep 17 00:00:00 2001 From: Sumanth V Rao Date: Thu, 11 Mar 2021 21:49:49 +0530 Subject: [PATCH] hotspots: Add TUTORIAL_ENABLED setting to toggle INTRO_HOTSPOTS. We add a TUTORIAL_ENABLED setting for self-hosters who want to disable the tutorial entirely on their system. For this, the default value (True) is placed in default_settings.py, which can be overwritten by adding an entry in /etc/zulip/settings.py. --- zerver/lib/hotspots.py | 4 ++++ zerver/tests/test_hotspots.py | 15 ++++++++++----- zproject/default_settings.py | 4 ++++ zproject/prod_settings_template.py | 3 +++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/zerver/lib/hotspots.py b/zerver/lib/hotspots.py index 317b79ee41..dbbc85b12c 100644 --- a/zerver/lib/hotspots.py +++ b/zerver/lib/hotspots.py @@ -71,6 +71,10 @@ def get_next_hotspots(user: UserProfile) -> List[Dict[str, object]]: for hotspot in ALL_HOTSPOTS ] + # If a Zulip server has disabled the tutorial, never send hotspots. + if not settings.TUTORIAL_ENABLED: + return [] + if user.tutorial_status == UserProfile.TUTORIAL_FINISHED: return [] diff --git a/zerver/tests/test_hotspots.py b/zerver/tests/test_hotspots.py index 8b0c4b83eb..a46a623436 100644 --- a/zerver/tests/test_hotspots.py +++ b/zerver/tests/test_hotspots.py @@ -28,16 +28,21 @@ class TestGetNextHotspots(ZulipTestCase): self.assertEqual(hotspots[0]["name"], "intro_streams") def test_all_intro_hotspots_done(self) -> None: - self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED) - for hotspot in INTRO_HOTSPOTS: - do_mark_hotspot_as_read(self.user, hotspot) - self.assertEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED) - self.assertEqual(get_next_hotspots(self.user), []) + with self.settings(TUTORIAL_ENABLED=True): + self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED) + for hotspot in INTRO_HOTSPOTS: + do_mark_hotspot_as_read(self.user, hotspot) + self.assertEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED) + self.assertEqual(get_next_hotspots(self.user), []) def test_send_all(self) -> None: with self.settings(DEVELOPMENT=True, ALWAYS_SEND_ALL_HOTSPOTS=True): self.assertEqual(len(ALL_HOTSPOTS), len(get_next_hotspots(self.user))) + def test_tutorial_disabled(self) -> None: + with self.settings(TUTORIAL_ENABLED=False): + self.assertEqual(get_next_hotspots(self.user), []) + class TestHotspots(ZulipTestCase): def test_do_mark_hotspot_as_read(self) -> None: diff --git a/zproject/default_settings.py b/zproject/default_settings.py index d05e203a25..1dcd6e89ea 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -190,6 +190,10 @@ TWO_FACTOR_AUTHENTICATION_ENABLED = False # in development mode. ALWAYS_SEND_ALL_HOTSPOTS = False +# The new user tutorial is enabled by default, but can be disabled for +# self-hosters who want to disable the tutorial entirely on their system. +TUTORIAL_ENABLED = True + # In-development search pills feature. SEARCH_PILLS_ENABLED = False diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py index 76237766bf..2e444c0adc 100644 --- a/zproject/prod_settings_template.py +++ b/zproject/prod_settings_template.py @@ -672,6 +672,9 @@ ENABLE_GRAVATAR = True ## to '' will disable the Camo integration. CAMO_URI = "/external_content/" +## Controls the tutorial popups for new users. +# TUTORIAL_ENABLED = True + ## Controls whether Zulip will rate-limit user requests. # RATE_LIMITING = True