mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
org settings: Create backend api for allow_community_topic_editing.
Adds the code for updating the allow_community_topic_editing setting.
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user