diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 4cb22c896a..0889087f60 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -576,19 +576,25 @@ def do_set_realm_authentication_methods(realm: Realm, ) send_event(event, active_user_ids(realm.id)) - def do_set_realm_message_editing(realm: Realm, allow_message_editing: bool, - message_content_edit_limit_seconds: int) -> None: + message_content_edit_limit_seconds: int, + allow_community_topic_editing: bool) -> None: realm.allow_message_editing = allow_message_editing realm.message_content_edit_limit_seconds = message_content_edit_limit_seconds - realm.save(update_fields=['allow_message_editing', 'message_content_edit_limit_seconds']) + realm.allow_community_topic_editing = allow_community_topic_editing + realm.save(update_fields=['allow_message_editing', + 'allow_community_topic_editing', + 'message_content_edit_limit_seconds', + ] + ) event = dict( type="realm", op="update_dict", property="default", data=dict(allow_message_editing=allow_message_editing, - message_content_edit_limit_seconds=message_content_edit_limit_seconds), + message_content_edit_limit_seconds=message_content_edit_limit_seconds, + allow_community_topic_editing=allow_community_topic_editing), ) send_event(event, active_user_ids(realm.id)) diff --git a/zerver/lib/events.py b/zerver/lib/events.py index e30bb36bd8..0cd7e328b3 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -160,6 +160,7 @@ def fetch_initial_state_data(user_profile: UserProfile, realm = user_profile.realm state['realm_authentication_methods'] = realm.authentication_methods_dict() state['realm_allow_message_editing'] = realm.allow_message_editing + state['realm_allow_community_topic_editing'] = realm.allow_community_topic_editing state['realm_message_content_edit_limit_seconds'] = realm.message_content_edit_limit_seconds state['realm_icon_url'] = realm_icon_url(realm) state['realm_icon_source'] = realm.icon_source diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 61e0ea4fda..36f838106e 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -1335,6 +1335,7 @@ class EventsRegisterTest(ZulipTestCase): ('data', check_dict_only([ ('allow_message_editing', check_bool), ('message_content_edit_limit_seconds', check_int), + ('allow_community_topic_editing', check_bool), ])), ]) # Test every transition among the four possibilities {T,F} x {0, non-0} @@ -1344,7 +1345,8 @@ class EventsRegisterTest(ZulipTestCase): events = self.do_test( lambda: do_set_realm_message_editing(self.user_profile.realm, allow_message_editing, - message_content_edit_limit_seconds)) + message_content_edit_limit_seconds, + False)) error = schema_checker('events[0]', events[0]) self.assert_on_error(error) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 1509322b7c..43b128c81f 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -106,6 +106,7 @@ class HomeTest(ZulipTestCase): "prompt_for_invites", "queue_id", "realm_add_emoji_by_admins_only", + "realm_allow_community_topic_editing", "realm_allow_edit_history", "realm_allow_message_deleting", "realm_allow_message_editing", diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index b34827e556..070dba0548 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -365,13 +365,22 @@ class RealmAPITest(ZulipTestCase): """Tests updating the realm property 'allow_message_editing'.""" self.set_up_db('allow_message_editing', False) self.set_up_db('message_content_edit_limit_seconds', 0) + self.set_up_db('allow_community_topic_editing', False) realm = self.update_with_api('allow_message_editing', True) realm = self.update_with_api('message_content_edit_limit_seconds', 100) + realm = self.update_with_api('allow_community_topic_editing', True) self.assertEqual(realm.allow_message_editing, True) self.assertEqual(realm.message_content_edit_limit_seconds, 100) + self.assertEqual(realm.allow_community_topic_editing, True) realm = self.update_with_api('allow_message_editing', False) self.assertEqual(realm.allow_message_editing, False) self.assertEqual(realm.message_content_edit_limit_seconds, 100) + self.assertEqual(realm.allow_community_topic_editing, True) realm = self.update_with_api('message_content_edit_limit_seconds', 200) self.assertEqual(realm.allow_message_editing, False) self.assertEqual(realm.message_content_edit_limit_seconds, 200) + self.assertEqual(realm.allow_community_topic_editing, True) + realm = self.update_with_api('allow_community_topic_editing', False) + self.assertEqual(realm.allow_message_editing, False) + self.assertEqual(realm.message_content_edit_limit_seconds, 200) + self.assertEqual(realm.allow_community_topic_editing, False) diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 35ed421de0..2f01bdaa37 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -41,6 +41,7 @@ def update_realm( add_emoji_by_admins_only: Optional[bool]=REQ(validator=check_bool, default=None), allow_message_deleting: Optional[bool]=REQ(validator=check_bool, default=None), allow_message_editing: Optional[bool]=REQ(validator=check_bool, default=None), + allow_community_topic_editing: Optional[bool]=REQ(validator=check_bool, default=None), mandatory_topics: Optional[bool]=REQ(validator=check_bool, default=None), message_content_edit_limit_seconds: Optional[int]=REQ(converter=to_non_negative_int, default=None), allow_edit_history: Optional[bool]=REQ(validator=check_bool, default=None), @@ -97,17 +98,23 @@ def update_realm( data['authentication_methods'] = authentication_methods # The message_editing settings are coupled to each other, and thus don't fit # into the do_set_realm_property framework. - if (allow_message_editing is not None and realm.allow_message_editing != allow_message_editing) or \ - (message_content_edit_limit_seconds is not None and - realm.message_content_edit_limit_seconds != message_content_edit_limit_seconds): + if ((allow_message_editing is not None and realm.allow_message_editing != allow_message_editing) or + (message_content_edit_limit_seconds is not None and + realm.message_content_edit_limit_seconds != message_content_edit_limit_seconds) or + (allow_community_topic_editing is not None and + realm.allow_community_topic_editing != allow_community_topic_editing)): if allow_message_editing is None: allow_message_editing = realm.allow_message_editing if message_content_edit_limit_seconds is None: message_content_edit_limit_seconds = realm.message_content_edit_limit_seconds + if allow_community_topic_editing is None: + allow_community_topic_editing = realm.allow_community_topic_editing do_set_realm_message_editing(realm, allow_message_editing, - message_content_edit_limit_seconds) + message_content_edit_limit_seconds, + allow_community_topic_editing) data['allow_message_editing'] = allow_message_editing data['message_content_edit_limit_seconds'] = message_content_edit_limit_seconds + data['allow_community_topic_editing'] = allow_community_topic_editing # Realm.notifications_stream and Realm.signup_notifications_stream are not boolean, # Text or integer field, and thus doesn't fit into the do_set_realm_property framework. if notifications_stream_id is not None: