Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

refactor: Make acting_user a mandatory kwarg for do_change_notification_settings.

shanukundd0a8738a3c8
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 216d6f21649..66d22af01cb 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -4512,7 +4512,8 @@ def do_change_notification_settings(
user_profile: UserProfile,
name: str,
value: Union[bool, int, str],
- acting_user: Optional[UserProfile] = None,
+ *,
+ acting_user: Optional[UserProfile],
) -> None:
"""Takes in a UserProfile object, the name of a global notification
preference to update, and the value to update to
diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.py
index 74f646bbb7b..811ea5993a1 100644
--- a/zerver/tests/test_email_notifications.py
+++ b/zerver/tests/test_email_notifications.py
@@ -672,7 +672,10 @@ 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(
- self.example_user("hamlet"), "message_content_in_email_notifications", False
+ self.example_user("hamlet"),
+ "message_content_in_email_notifications",
+ False,
+ acting_user=None,
)
self._extra_context_in_missed_stream_messages_mention(False, show_message_content=False)
mail.outbox = []
@@ -781,12 +784,16 @@ 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(user, "message_content_in_email_notifications", True)
+ do_change_notification_settings(
+ 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(user, "message_content_in_email_notifications", False)
+ do_change_notification_settings(
+ user, "message_content_in_email_notifications", False, acting_user=None
+ )
mail.outbox = []
self._extra_context_in_personal_missed_stream_messages(
False, show_message_content=False, message_content_disabled_by_user=True
@@ -798,13 +805,17 @@ 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(user, "message_content_in_email_notifications", True)
+ do_change_notification_settings(
+ user, "message_content_in_email_notifications", True, acting_user=None
+ )
mail.outbox = []
self._extra_context_in_personal_missed_stream_messages(
False, show_message_content=False, message_content_disabled_by_realm=True
)
- do_change_notification_settings(user, "message_content_in_email_notifications", False)
+ do_change_notification_settings(
+ user, "message_content_in_email_notifications", False, acting_user=None
+ )
mail.outbox = []
self._extra_context_in_personal_missed_stream_messages(
False,
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 172b51a528e..cca73ee0a1b 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -1281,7 +1281,9 @@ class NormalActionsTest(BaseAction):
notification_setting = "notification_sound"
events = self.verify_action(
- lambda: do_change_notification_settings(self.user_profile, notification_setting, "ding")
+ lambda: do_change_notification_settings(
+ self.user_profile, notification_setting, "ding", acting_user=self.user_profile
+ )
)
check_update_global_notifications("events[0]", events[0], "ding")
diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py
index 8a52117b1ef..25fb08a51da 100644
--- a/zerver/tests/test_new_users.py
+++ b/zerver/tests/test_new_users.py
@@ -105,13 +105,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)
+ do_change_notification_settings(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.assertEqual(len(mail.outbox), 0)
- do_change_notification_settings(user, "enable_login_emails", True)
+ do_change_notification_settings(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)