settings: Require clients to pass dense_mode value when needed.

Previously, if someone changed the font-size or line height
settings to some value other than the legacy values, we set
dense_mode to False if it was True. This commit changes the
code to require clients to pass dense_mode as False in such
cases and raise an error otherwise.
This commit is contained in:
Sahil Batra
2024-07-18 14:35:37 +05:30
committed by Tim Abbott
parent 0ea5daece8
commit c1c4c95ce7
6 changed files with 178 additions and 73 deletions

View File

@@ -506,41 +506,101 @@ class ChangeSettingsTest(ZulipTestCase):
self.assertEqual(hamlet.dense_mode, True)
self.login("hamlet")
data = {"web_font_size_px": 16}
data: dict[str, str | int] = {"web_font_size_px": 16}
result = self.client_patch("/json/settings", data)
self.assert_json_error(
result,
"Incompatible values for 'dense_mode' and 'web_font_size_px' settings.",
)
data = {"web_font_size_px": 16, "dense_mode": orjson.dumps(False).decode()}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 16)
self.assertEqual(hamlet.dense_mode, False)
data = {"web_font_size_px": 20}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 20)
self.assertEqual(hamlet.dense_mode, False)
# Check dense_mode is still false when both the
# settings are set to legacy values.
data = {"web_font_size_px": 14}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 14)
self.assertEqual(hamlet.web_line_height_percent, 122)
self.assertEqual(hamlet.dense_mode, False)
data = {"dense_mode": orjson.dumps(True).decode()}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 14)
self.assertEqual(hamlet.dense_mode, True)
data = {"web_line_height_percent": 140}
result = self.client_patch("/json/settings", data)
self.assert_json_error(
result,
"Incompatible values for 'dense_mode' and 'web_line_height_percent' settings.",
)
data = {"web_line_height_percent": 140, "dense_mode": orjson.dumps(False).decode()}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_line_height_percent, 140)
self.assertEqual(hamlet.dense_mode, False)
invalid_data = {"dense_mode": orjson.dumps(True).decode(), "web_font_size_px": 16}
result = self.client_patch("/json/settings", invalid_data)
data = {"web_line_height_percent": 130}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_line_height_percent, 130)
self.assertEqual(hamlet.dense_mode, False)
# Check dense_mode is still false when both the
# settings are set to legacy values.
data = {"web_line_height_percent": 122}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 14)
self.assertEqual(hamlet.web_line_height_percent, 122)
self.assertEqual(hamlet.dense_mode, False)
data = {"dense_mode": orjson.dumps(True).decode(), "web_font_size_px": 16}
result = self.client_patch("/json/settings", data)
self.assert_json_error(
result,
"Incompatible values for 'dense_mode' and 'web_font_size_px' settings.",
)
invalid_data = {"dense_mode": orjson.dumps(True).decode(), "web_line_height_percent": 140}
result = self.client_patch("/json/settings", invalid_data)
data = {"dense_mode": orjson.dumps(True).decode(), "web_line_height_percent": 140}
result = self.client_patch("/json/settings", data)
self.assert_json_error(
result,
"Incompatible values for 'dense_mode' and 'web_line_height_percent' settings.",
)
data = {
"dense_mode": orjson.dumps(True).decode(),
"web_font_size_px": 14,
"web_line_height_percent": 122,
}
result = self.client_patch("/json/settings", data)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.web_font_size_px, 14)
self.assertEqual(hamlet.web_line_height_percent, 122)
self.assertEqual(hamlet.dense_mode, True)
class UserChangesTest(ZulipTestCase):
def test_update_api_key(self) -> None: