user_settings: Create _legacy dicts for existing settings.

Since 84742a0, all settings are sent in the `user_settings` dictionary
which were previously sent inline with other fields in /register
response.

In order to simplify the process of adding new personal settings, we
want to transition to a world where new settings only need to consider
the `property_types` object, and code that needs to reference the
legacy behavior interacts with an object with `legacy` in its name.

This way, contributors working on new settings don't need to think
about the legacy code paths at all.

See https://chat.zulip.org/#narrow/stream/378-api-design/topic/user.20settings.20response.20in.20.2Fregister
to understand this better.
This commit is contained in:
Dinesh
2021-08-11 19:04:25 +05:30
committed by Tim Abbott
parent fd77ebcc2a
commit 430c5cb8e7
7 changed files with 61 additions and 48 deletions

View File

@@ -1362,8 +1362,7 @@ class UserBaseSettings(models.Model):
# Whether or not the user wants to sync their drafts.
enable_drafts_synchronization = models.BooleanField(default=True)
# Define the types of the various automatically managed properties
property_types = dict(
display_settings_legacy = dict(
color_scheme=int,
default_language=str,
default_view=str,
@@ -1380,7 +1379,7 @@ class UserBaseSettings(models.Model):
twenty_four_hour_time=bool,
)
notification_setting_types = dict(
notification_settings_legacy = dict(
enable_desktop_notifications=bool,
enable_digest_emails=bool,
enable_login_emails=bool,
@@ -1403,6 +1402,13 @@ class UserBaseSettings(models.Model):
presence_enabled=bool,
)
notification_setting_types = {
**notification_settings_legacy
} # Add new notifications settings here.
# Define the types of the various automatically managed properties
property_types = {**display_settings_legacy, **notification_setting_types}
class Meta:
abstract = True