forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user_settings: Automate 'Include realm name in message email subject'.
Currently, there is a checkbox setting for whether to "Include realm name in subject of message notification emails". This commit replaces the checkbox setting with a dropdown having values: Automatic [default], Yes, No. The Automatic option includes the realm name if, and only if, there are multiple Zulip realms associated with the user's email. Tests are added and(or) modified. Fixes: zulip#19905.
- Loading branch information
1 parent
04cf68b
commit 6389c11
Showing
18 changed files
with
293 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
zerver/migrations/0423_alter_and_migrate_realm_name_in_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Generated by Django 4.1.5 on 2023-01-11 20:21 | ||
|
||
from django.db import migrations, models | ||
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor | ||
from django.db.migrations.state import StateApps | ||
|
||
# We include a copy of this structure as it was at the time this | ||
# migration was merged, since future should not impact the migration. | ||
REALM_NAME_IN_NOTIFICATIONS_AUTOMATIC = 1 | ||
REALM_NAME_IN_NOTIFICATIONS_YES = 2 | ||
REALM_NAME_IN_NOTIFICATIONS_NO = 3 | ||
|
||
# The value of 'realm_name_in_notifications' for those users | ||
# who have manually changed the value of 'realm_name_in_notifications' as 'true' | ||
# should be updated as 'Yes', not 'Automatic' | ||
def update_realm_name_in_notifications_new_values( | ||
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
UserProfile = apps.get_model("zerver", "UserProfile") | ||
userprofiles = UserProfile.objects.filter(realm_name_in_notifications=True) | ||
userprofiles.update(realm_name_in_notifications_new=REALM_NAME_IN_NOTIFICATIONS_YES) | ||
|
||
|
||
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
UserProfile = apps.get_model("zerver", "UserProfile") | ||
userprofiles = UserProfile.objects.filter( | ||
realm_name_in_notifications_new=REALM_NAME_IN_NOTIFICATIONS_YES | ||
) | ||
userprofiles.update(realm_name_in_notifications=True) | ||
|
||
def update_realm_name_in_notifications_new_values_for_realm_user_default( | ||
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault") | ||
realmuserdefaults = RealmUserDefault.objects.filter(realm_name_in_notifications=True) | ||
realmuserdefaults.update(realm_name_in_notifications_new=REALM_NAME_IN_NOTIFICATIONS_YES) | ||
|
||
|
||
def reverse_code_for_realm_user_default(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault") | ||
realmuserdefaults = RealmUserDefault.objects.filter( | ||
realm_name_in_notifications_new=REALM_NAME_IN_NOTIFICATIONS_YES | ||
) | ||
realmuserdefaults.update(realm_name_in_notifications=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zerver", "0422_multiuseinvite_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="realmuserdefault", | ||
name="realm_name_in_notifications_new", | ||
field=models.PositiveSmallIntegerField(default=REALM_NAME_IN_NOTIFICATIONS_AUTOMATIC), | ||
), | ||
migrations.RunPython( | ||
update_realm_name_in_notifications_new_values_for_realm_user_default, | ||
reverse_code=reverse_code_for_realm_user_default, | ||
elidable=True, | ||
), | ||
migrations.RemoveField( | ||
model_name="realmuserdefault", | ||
name="realm_name_in_notifications", | ||
), | ||
migrations.RenameField( | ||
model_name="realmuserdefault", | ||
old_name="realm_name_in_notifications_new", | ||
new_name="realm_name_in_notifications", | ||
), | ||
migrations.AddField( | ||
model_name="userprofile", | ||
name="realm_name_in_notifications_new", | ||
field=models.PositiveSmallIntegerField(default=REALM_NAME_IN_NOTIFICATIONS_AUTOMATIC), | ||
), | ||
migrations.RunPython( | ||
update_realm_name_in_notifications_new_values, | ||
reverse_code=reverse_code, | ||
elidable=True, | ||
), | ||
migrations.RemoveField( | ||
model_name="userprofile", | ||
name="realm_name_in_notifications", | ||
), | ||
migrations.RenameField( | ||
model_name="userprofile", | ||
old_name="realm_name_in_notifications_new", | ||
new_name="realm_name_in_notifications", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.