From f37082c4caeba1441711231e6abcac2f9079f90c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 17 Jul 2024 17:07:12 -0700 Subject: [PATCH] models: Switch font size default to non-compact. This is the intended longer-term default, and it's polished enough for testing. --- ...er_realmuserdefault_dense_mode_and_more.py | 42 ++++++++++++++++++ ...557_change_information_density_defaults.py | 44 +++++++++++++++++++ zerver/models/users.py | 12 ++--- zerver/tests/test_events.py | 4 +- zerver/tests/test_realm.py | 16 +++++-- zerver/tests/test_settings.py | 12 ++++- zerver/views/user_settings.py | 4 +- 7 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 zerver/migrations/0556_alter_realmuserdefault_dense_mode_and_more.py create mode 100644 zerver/migrations/0557_change_information_density_defaults.py diff --git a/zerver/migrations/0556_alter_realmuserdefault_dense_mode_and_more.py b/zerver/migrations/0556_alter_realmuserdefault_dense_mode_and_more.py new file mode 100644 index 0000000000..52fcf8d76a --- /dev/null +++ b/zerver/migrations/0556_alter_realmuserdefault_dense_mode_and_more.py @@ -0,0 +1,42 @@ +# Generated by Django 5.0.6 on 2024-07-18 00:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0555_alter_onboardingstep_onboarding_step"), + ] + + operations = [ + migrations.AlterField( + model_name="realmuserdefault", + name="dense_mode", + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name="realmuserdefault", + name="web_font_size_px", + field=models.PositiveSmallIntegerField(default=16), + ), + migrations.AlterField( + model_name="realmuserdefault", + name="web_line_height_percent", + field=models.PositiveSmallIntegerField(default=140), + ), + migrations.AlterField( + model_name="userprofile", + name="dense_mode", + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name="userprofile", + name="web_font_size_px", + field=models.PositiveSmallIntegerField(default=16), + ), + migrations.AlterField( + model_name="userprofile", + name="web_line_height_percent", + field=models.PositiveSmallIntegerField(default=140), + ), + ] diff --git a/zerver/migrations/0557_change_information_density_defaults.py b/zerver/migrations/0557_change_information_density_defaults.py new file mode 100644 index 0000000000..ebfabce185 --- /dev/null +++ b/zerver/migrations/0557_change_information_density_defaults.py @@ -0,0 +1,44 @@ +# Generated by Django 5.0.6 on 2024-07-17 15:10 + + +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from django.db.migrations.state import StateApps + + +def set_default_values_for_information_density_settings( + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor +) -> None: + """Set defaults for information density settings to their intended values.""" + RealmUserDefault = apps.get_model("zerver", "RealmUserDefault") + UserProfile = apps.get_model("zerver", "UserProfile") + + WEB_FONT_SIZE_PX_DEFAULT = 16 + WEB_LINE_HEIGHT_PERCENT_DEFAULT = 140 + + RealmUserDefault.objects.update( + dense_mode=False, + web_font_size_px=WEB_FONT_SIZE_PX_DEFAULT, + web_line_height_percent=WEB_LINE_HEIGHT_PERCENT_DEFAULT, + ) + UserProfile.objects.update( + dense_mode=False, + web_font_size_px=WEB_FONT_SIZE_PX_DEFAULT, + web_line_height_percent=WEB_LINE_HEIGHT_PERCENT_DEFAULT, + ) + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ("zerver", "0556_alter_realmuserdefault_dense_mode_and_more"), + ] + + operations = [ + migrations.RunPython( + set_default_values_for_information_density_settings, + elidable=True, + reverse_code=migrations.RunPython.noop, + ), + ] diff --git a/zerver/models/users.py b/zerver/models/users.py index 17eec0052d..d96f44304a 100644 --- a/zerver/models/users.py +++ b/zerver/models/users.py @@ -65,7 +65,6 @@ class UserBaseSettings(models.Model): # Values for it are URL suffix after `#`. web_home_view = models.TextField(default="inbox") web_escape_navigates_to_home_view = models.BooleanField(default=True) - dense_mode = models.BooleanField(default=True) fluid_layout_width = models.BooleanField(default=False) high_contrast_mode = models.BooleanField(default=False) translate_emoticons = models.BooleanField(default=False) @@ -80,11 +79,14 @@ class UserBaseSettings(models.Model): # Information density is established through # adjustments to the font size and line height. - WEB_FONT_SIZE_PX_LEGACY = 14 - WEB_LINE_HEIGHT_PERCENT_LEGACY = 122 - web_font_size_px = models.PositiveSmallIntegerField(default=WEB_FONT_SIZE_PX_LEGACY) + WEB_FONT_SIZE_PX_COMPACT = 14 + WEB_FONT_SIZE_PX_DEFAULT = 16 + WEB_LINE_HEIGHT_PERCENT_COMPACT = 122 + WEB_LINE_HEIGHT_PERCENT_DEFAULT = 140 + dense_mode = models.BooleanField(default=False) + web_font_size_px = models.PositiveSmallIntegerField(default=WEB_FONT_SIZE_PX_DEFAULT) web_line_height_percent = models.PositiveSmallIntegerField( - default=WEB_LINE_HEIGHT_PERCENT_LEGACY + default=WEB_LINE_HEIGHT_PERCENT_DEFAULT ) # UI setting controlling Zulip's behavior of demoting in the sort diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 947eb7c463..f6d8b7356d 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -3753,8 +3753,8 @@ class RealmPropertyActionTest(BaseAction): def do_set_realm_user_default_setting_test(self, name: str) -> None: bool_tests: list[bool] = [True, False, True] test_values: dict[str, Any] = dict( - web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_LEGACY], - web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_LEGACY], + web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_COMPACT], + web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_COMPACT], color_scheme=UserProfile.COLOR_SCHEME_CHOICES, web_home_view=["recent_topics", "inbox", "all_messages"], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index d774ed1ae9..f73eef68dc 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -1937,8 +1937,8 @@ class RealmAPITest(ZulipTestCase): def do_test_realm_default_setting_update_api(self, name: str) -> None: bool_tests: list[bool] = [False, True] test_values: dict[str, Any] = dict( - web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_LEGACY], - web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_LEGACY], + web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_COMPACT], + web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_COMPACT], color_scheme=UserProfile.COLOR_SCHEME_CHOICES, web_home_view=["recent_topics", "inbox", "all_messages"], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], @@ -1988,12 +1988,22 @@ class RealmAPITest(ZulipTestCase): # settings in RealmUserDefault table will be used. if prop in ["default_language", "enable_login_emails", "enable_marketing_emails"]: continue + if prop in ["dense_mode"]: + # Testing this is complicated, see test_update_default_information_density_settings. + continue self.do_test_realm_default_setting_update_api(prop) def test_update_default_information_density_settings(self) -> None: realm = get_realm("zulip") + + # Start with the legacy settings configuration realm_user_default = RealmUserDefault.objects.get(realm=realm) - self.assertEqual(realm_user_default.dense_mode, True) + realm_user_default.dense_mode = True + realm_user_default.web_font_size_px = RealmUserDefault.WEB_FONT_SIZE_PX_COMPACT + realm_user_default.web_line_height_percent = ( + RealmUserDefault.WEB_LINE_HEIGHT_PERCENT_COMPACT + ) + realm_user_default.save() self.login("iago") data: dict[str, str | int] = {"web_font_size_px": 16} diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py index a825d246f2..0c748654a7 100644 --- a/zerver/tests/test_settings.py +++ b/zerver/tests/test_settings.py @@ -218,7 +218,12 @@ class ChangeSettingsTest(ZulipTestCase): def test_toggling_boolean_user_settings(self) -> None: """Test updating each boolean setting in UserProfile property_types""" boolean_settings = ( - s for s in UserProfile.property_types if UserProfile.property_types[s] is bool + s + for s in UserProfile.property_types + if UserProfile.property_types[s] is bool + # Dense mode can't be toggled without changing other settings too. + # This setting is tested in test_changing_information_density_settings. + and s not in ["dense_mode"] ) for user_setting in boolean_settings: self.check_for_toggle_param_patch("/json/settings", user_setting) @@ -503,7 +508,10 @@ class ChangeSettingsTest(ZulipTestCase): def test_changing_information_density_settings(self) -> None: hamlet = self.example_user("hamlet") - self.assertEqual(hamlet.dense_mode, True) + hamlet.dense_mode = True + hamlet.web_font_size_px = 14 + hamlet.web_line_height_percent = 122 + hamlet.save() self.login("hamlet") data: dict[str, str | int] = {"web_font_size_px": 16} diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index 99fd8dfe76..fc2901f563 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -209,12 +209,12 @@ def check_information_density_setting_values( ) if dense_mode: - if web_font_size_px != UserBaseSettings.WEB_FONT_SIZE_PX_LEGACY: + if web_font_size_px != UserBaseSettings.WEB_FONT_SIZE_PX_COMPACT: raise JsonableError( _("Incompatible values for 'dense_mode' and 'web_font_size_px' settings.") ) - if web_line_height_percent != UserBaseSettings.WEB_LINE_HEIGHT_PERCENT_LEGACY: + if web_line_height_percent != UserBaseSettings.WEB_LINE_HEIGHT_PERCENT_COMPACT: raise JsonableError( _("Incompatible values for 'dense_mode' and 'web_line_height_percent' settings.") )