mirror of https://github.com/zulip/zulip.git
settings: Remove do_change_notification_settings function.
This commit removes the do_change_notification_settings function and we use do_change_user_setting directly to change all the user settings now.
This commit is contained in:
parent
991efaf450
commit
2f61afea9f
|
@ -5021,19 +5021,6 @@ def do_create_realm(
|
|||
return realm
|
||||
|
||||
|
||||
def do_change_notification_settings(
|
||||
user_profile: UserProfile,
|
||||
setting_name: str,
|
||||
setting_value: Union[bool, int, str],
|
||||
*,
|
||||
acting_user: Optional[UserProfile],
|
||||
) -> None:
|
||||
# TODO: Make acting_user a mandatory parameter to
|
||||
# do_change_user_setting, and then delete this function (having
|
||||
# callers access do_change_user_setting directly).
|
||||
do_change_user_setting(user_profile, setting_name, setting_value, acting_user=acting_user)
|
||||
|
||||
|
||||
def do_change_user_setting(
|
||||
user_profile: UserProfile,
|
||||
setting_name: str,
|
||||
|
|
|
@ -16,12 +16,12 @@ from zerver.lib.actions import (
|
|||
do_change_default_events_register_stream,
|
||||
do_change_default_sending_stream,
|
||||
do_change_icon_source,
|
||||
do_change_notification_settings,
|
||||
do_change_password,
|
||||
do_change_subscription_property,
|
||||
do_change_tos_version,
|
||||
do_change_user_delivery_email,
|
||||
do_change_user_role,
|
||||
do_change_user_setting,
|
||||
do_create_user,
|
||||
do_deactivate_realm,
|
||||
do_deactivate_stream,
|
||||
|
@ -639,7 +639,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
now = timezone_now()
|
||||
|
||||
old_value = getattr(user, setting)
|
||||
do_change_notification_settings(user, setting, value, acting_user=user)
|
||||
do_change_user_setting(user, setting, value, acting_user=user)
|
||||
expected_extra_data = {
|
||||
RealmAuditLog.OLD_VALUE: old_value,
|
||||
RealmAuditLog.NEW_VALUE: value,
|
||||
|
|
|
@ -13,7 +13,7 @@ from django.core import mail
|
|||
from django.test import override_settings
|
||||
from django_auth_ldap.config import LDAPSearch
|
||||
|
||||
from zerver.lib.actions import do_change_notification_settings, do_change_user_role
|
||||
from zerver.lib.actions import do_change_user_role, do_change_user_setting
|
||||
from zerver.lib.email_notifications import (
|
||||
enqueue_welcome_emails,
|
||||
fix_emojis,
|
||||
|
@ -867,7 +867,7 @@ class TestMissedMessages(ZulipTestCase):
|
|||
|
||||
def test_message_content_disabled_in_missed_message_notifications(self) -> None:
|
||||
# Test when user disabled message content in email notifications.
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
self.example_user("hamlet"),
|
||||
"message_content_in_email_notifications",
|
||||
False,
|
||||
|
@ -980,14 +980,14 @@ class TestMissedMessages(ZulipTestCase):
|
|||
realm.save(update_fields=["message_content_allowed_in_email_notifications"])
|
||||
|
||||
# Emails have missed message content when message content is enabled by the user
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
user, "message_content_in_email_notifications", True, acting_user=None
|
||||
)
|
||||
mail.outbox = []
|
||||
self._extra_context_in_personal_missed_stream_messages(False, show_message_content=True)
|
||||
|
||||
# Emails don't have missed message content when message content is disabled by the user
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
user, "message_content_in_email_notifications", False, acting_user=None
|
||||
)
|
||||
mail.outbox = []
|
||||
|
@ -1001,7 +1001,7 @@ class TestMissedMessages(ZulipTestCase):
|
|||
realm.message_content_allowed_in_email_notifications = False
|
||||
realm.save(update_fields=["message_content_allowed_in_email_notifications"])
|
||||
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
user, "message_content_in_email_notifications", True, acting_user=None
|
||||
)
|
||||
mail.outbox = []
|
||||
|
@ -1009,7 +1009,7 @@ class TestMissedMessages(ZulipTestCase):
|
|||
False, show_message_content=False, message_content_disabled_by_realm=True
|
||||
)
|
||||
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
user, "message_content_in_email_notifications", False, acting_user=None
|
||||
)
|
||||
mail.outbox = []
|
||||
|
|
|
@ -39,7 +39,6 @@ from zerver.lib.actions import (
|
|||
do_change_full_name,
|
||||
do_change_icon_source,
|
||||
do_change_logo_source,
|
||||
do_change_notification_settings,
|
||||
do_change_plan_type,
|
||||
do_change_realm_domain,
|
||||
do_change_stream_description,
|
||||
|
@ -1422,13 +1421,13 @@ class NormalActionsTest(BaseAction):
|
|||
# These settings are tested in their own tests.
|
||||
continue
|
||||
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
self.user_profile, notification_setting, False, acting_user=self.user_profile
|
||||
)
|
||||
|
||||
for setting_value in [True, False]:
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile,
|
||||
notification_setting,
|
||||
setting_value,
|
||||
|
@ -1441,7 +1440,7 @@ class NormalActionsTest(BaseAction):
|
|||
|
||||
# Also test with notification_settings_null=True
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile,
|
||||
notification_setting,
|
||||
setting_value,
|
||||
|
@ -1458,7 +1457,7 @@ class NormalActionsTest(BaseAction):
|
|||
notification_setting = "notification_sound"
|
||||
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile, notification_setting, "ding", acting_user=self.user_profile
|
||||
),
|
||||
num_events=2,
|
||||
|
@ -1470,7 +1469,7 @@ class NormalActionsTest(BaseAction):
|
|||
notification_setting = "desktop_icon_count_display"
|
||||
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile, notification_setting, 2, acting_user=self.user_profile
|
||||
),
|
||||
num_events=2,
|
||||
|
@ -1479,7 +1478,7 @@ class NormalActionsTest(BaseAction):
|
|||
check_update_global_notifications("events[1]", events[1], 2)
|
||||
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile, notification_setting, 1, acting_user=self.user_profile
|
||||
),
|
||||
num_events=2,
|
||||
|
@ -2074,7 +2073,7 @@ class NormalActionsTest(BaseAction):
|
|||
|
||||
def test_notification_setting_event_not_sent(self) -> None:
|
||||
events = self.verify_action(
|
||||
lambda: do_change_notification_settings(
|
||||
lambda: do_change_user_setting(
|
||||
self.user_profile,
|
||||
"enable_sounds",
|
||||
False,
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.core import mail
|
|||
from django.test import override_settings
|
||||
|
||||
from corporate.lib.stripe import get_latest_seat_count
|
||||
from zerver.lib.actions import do_change_notification_settings, notify_new_user
|
||||
from zerver.lib.actions import do_change_user_setting, notify_new_user
|
||||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.streams import create_stream_if_needed
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
|
@ -109,13 +109,13 @@ class SendLoginEmailTest(ZulipTestCase):
|
|||
user.date_joined = mock_time - datetime.timedelta(seconds=JUST_CREATED_THRESHOLD + 1)
|
||||
user.save()
|
||||
|
||||
do_change_notification_settings(user, "enable_login_emails", False, acting_user=None)
|
||||
do_change_user_setting(user, "enable_login_emails", False, acting_user=None)
|
||||
self.assertFalse(user.enable_login_emails)
|
||||
with mock.patch("zerver.signals.timezone_now", return_value=mock_time):
|
||||
self.login_user(user)
|
||||
self.assert_length(mail.outbox, 0)
|
||||
|
||||
do_change_notification_settings(user, "enable_login_emails", True, acting_user=None)
|
||||
do_change_user_setting(user, "enable_login_emails", True, acting_user=None)
|
||||
self.assertTrue(user.enable_login_emails)
|
||||
with mock.patch("zerver.signals.timezone_now", return_value=mock_time):
|
||||
self.login_user(user)
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|||
|
||||
from confirmation.models import Confirmation, ConfirmationKeyException, get_object_from_key
|
||||
from zerver.context_processors import common_context
|
||||
from zerver.lib.actions import do_change_notification_settings
|
||||
from zerver.lib.actions import do_change_user_setting
|
||||
from zerver.lib.send_email import clear_scheduled_emails
|
||||
from zerver.models import ScheduledEmail, UserProfile
|
||||
|
||||
|
@ -33,7 +33,7 @@ def process_unsubscribe(
|
|||
|
||||
|
||||
def do_missedmessage_unsubscribe(user_profile: UserProfile) -> None:
|
||||
do_change_notification_settings(
|
||||
do_change_user_setting(
|
||||
user_profile, "enable_offline_email_notifications", False, acting_user=user_profile
|
||||
)
|
||||
|
||||
|
@ -43,21 +43,15 @@ def do_welcome_unsubscribe(user_profile: UserProfile) -> None:
|
|||
|
||||
|
||||
def do_digest_unsubscribe(user_profile: UserProfile) -> None:
|
||||
do_change_notification_settings(
|
||||
user_profile, "enable_digest_emails", False, acting_user=user_profile
|
||||
)
|
||||
do_change_user_setting(user_profile, "enable_digest_emails", False, acting_user=user_profile)
|
||||
|
||||
|
||||
def do_login_unsubscribe(user_profile: UserProfile) -> None:
|
||||
do_change_notification_settings(
|
||||
user_profile, "enable_login_emails", False, acting_user=user_profile
|
||||
)
|
||||
do_change_user_setting(user_profile, "enable_login_emails", False, acting_user=user_profile)
|
||||
|
||||
|
||||
def do_marketing_unsubscribe(user_profile: UserProfile) -> None:
|
||||
do_change_notification_settings(
|
||||
user_profile, "enable_marketing_emails", False, acting_user=user_profile
|
||||
)
|
||||
do_change_user_setting(user_profile, "enable_marketing_emails", False, acting_user=user_profile)
|
||||
|
||||
|
||||
# The keys are part of the URL for the unsubscribe link and must be valid
|
||||
|
|
|
@ -21,7 +21,6 @@ from zerver.decorator import human_users_only
|
|||
from zerver.lib.actions import (
|
||||
check_change_full_name,
|
||||
do_change_avatar_fields,
|
||||
do_change_notification_settings,
|
||||
do_change_password,
|
||||
do_change_user_delivery_email,
|
||||
do_change_user_setting,
|
||||
|
@ -259,23 +258,11 @@ def json_change_settings(
|
|||
check_change_full_name(user_profile, full_name, user_profile)
|
||||
|
||||
# Loop over user_profile.property_types
|
||||
request_settings = {
|
||||
k: v
|
||||
for k, v in list(locals().items())
|
||||
if k in user_profile.property_types and k not in user_profile.notification_setting_types
|
||||
}
|
||||
request_settings = {k: v for k, v in list(locals().items()) if k in user_profile.property_types}
|
||||
for k, v in list(request_settings.items()):
|
||||
if v is not None and getattr(user_profile, k) != v:
|
||||
do_change_user_setting(user_profile, k, v, acting_user=user_profile)
|
||||
|
||||
req_vars = {
|
||||
k: v for k, v in list(locals().items()) if k in user_profile.notification_setting_types
|
||||
}
|
||||
|
||||
for k, v in list(req_vars.items()):
|
||||
if v is not None and getattr(user_profile, k) != v:
|
||||
do_change_notification_settings(user_profile, k, v, acting_user=user_profile)
|
||||
|
||||
if timezone is not None and user_profile.timezone != timezone:
|
||||
do_change_user_setting(user_profile, "timezone", timezone, acting_user=user_profile)
|
||||
|
||||
|
|
Loading…
Reference in New Issue