From 5b1f6a696e60f4f618561ff462d7ff1941e6927e Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 23 Dec 2022 19:26:27 +0530 Subject: [PATCH] message: Refactor code for parsing message time limit settings. This commit renames parse_message_content_edit_or_delete_limit to parse_message_time_limit_setting and also renames MESSAGE_CONTENT_EDIT_OR_DELETE_LIMIT_SPECIAL_VALUES_MAP to MESSAGE_TIME_LIMIT_SETTING_SPECIAL_VALUES_MAP. We do this change since this function and object will also be used for message move limit and it makes sense to have a more generic name. --- zerver/actions/realm_settings.py | 9 +++------ zerver/lib/message.py | 2 +- zerver/models.py | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.py index a28e094b44..2e7b87f329 100644 --- a/zerver/actions/realm_settings.py +++ b/zerver/actions/realm_settings.py @@ -15,10 +15,7 @@ from zerver.actions.user_groups import update_users_in_full_members_system_group from zerver.actions.user_settings import do_delete_avatar_image, send_user_email_update_event from zerver.lib.cache import flush_user_profile from zerver.lib.create_user import get_display_email_address -from zerver.lib.message import ( - parse_message_content_edit_or_delete_limit, - update_first_visible_message_id, -) +from zerver.lib.message import parse_message_time_limit_setting, update_first_visible_message_id from zerver.lib.send_email import FromAddress, send_email_to_admins from zerver.lib.sessions import delete_user_sessions from zerver.lib.user_counts import realm_user_count_by_role @@ -124,9 +121,9 @@ def do_set_realm_property( def parse_and_set_setting_value_if_required( realm: Realm, setting_name: str, value: Union[int, str], *, acting_user: Optional[UserProfile] ) -> Tuple[Optional[int], bool]: - parsed_value = parse_message_content_edit_or_delete_limit( + parsed_value = parse_message_time_limit_setting( value, - Realm.MESSAGE_CONTENT_EDIT_OR_DELETE_LIMIT_SPECIAL_VALUES_MAP, + Realm.MESSAGE_TIME_LIMIT_SETTING_SPECIAL_VALUES_MAP, setting_name=setting_name, ) diff --git a/zerver/lib/message.py b/zerver/lib/message.py index d98aacdd61..8f5346768d 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -1614,7 +1614,7 @@ def wildcard_mention_allowed(sender: UserProfile, stream: Stream) -> bool: raise AssertionError("Invalid wildcard mention policy") -def parse_message_content_edit_or_delete_limit( +def parse_message_time_limit_setting( value: Union[int, str], special_values_map: Mapping[str, Optional[int]], *, diff --git a/zerver/models.py b/zerver/models.py index 0229efe55b..fd7e1fd6e2 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -464,7 +464,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub DEFAULT_MESSAGE_CONTENT_DELETE_LIMIT_SECONDS = ( 600 # if changed, also change in admin.js, setting_org.js ) - MESSAGE_CONTENT_EDIT_OR_DELETE_LIMIT_SPECIAL_VALUES_MAP = { + MESSAGE_TIME_LIMIT_SETTING_SPECIAL_VALUES_MAP = { "unlimited": None, } message_content_delete_limit_seconds = models.PositiveIntegerField(