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.

realm: Fix type-checking for message_retention_days.

Tim Abbottb7b173d2aeb3
diff --git a/tools/linter_lib/pyflakes.py b/tools/linter_lib/pyflakes.py
index ff630b3a38f..5029dfe838f 100644
--- a/tools/linter_lib/pyflakes.py
+++ b/tools/linter_lib/pyflakes.py
@@ -15,6 +15,7 @@ def check_pyflakes(files: List[str], options: argparse.Namespace) -> bool:
("scripts/lib/pythonrc.py",
" import *' used; unable to detect undefined names"),
+ ("zerver/views/realm.py", "local variable 'message_retention_days' is assigned to but never used"),
("settings.py", "settings import *' used; unable to detect undefined names"),
("settings.py", "'from .prod_settings_template import *' used; unable to detect undefined names"),
("settings.py", "settings.*' imported but unused"),
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
index 46e10c024c3..843ac17874a 100644
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union
from django.core.exceptions import ValidationError
from django.http import HttpRequest, HttpResponse
@@ -65,7 +65,8 @@ def update_realm(
authentication_methods: Optional[Dict[str, Any]]=REQ(validator=check_dict([]), default=None),
notifications_stream_id: Optional[int]=REQ(validator=check_int, default=None),
signup_notifications_stream_id: Optional[int]=REQ(validator=check_int, default=None),
- message_retention_days: Optional[int] = REQ(validator=check_string_or_int, default=None),
+ message_retention_days_raw: Optional[Union[int, str]] = REQ(
+ "message_retention_days", validator=check_string_or_int, default=None),
send_welcome_emails: Optional[bool]=REQ(validator=check_bool, default=None),
digest_emails_enabled: Optional[bool]=REQ(validator=check_bool, default=None),
message_content_allowed_in_email_notifications: Optional[bool]=REQ(
@@ -106,12 +107,13 @@ def update_realm(
video_chat_provider not in {p['id'] for p in Realm.VIDEO_CHAT_PROVIDERS.values()}):
return json_error(_("Invalid video_chat_provider {}").format(video_chat_provider))
- if message_retention_days is not None:
+ message_retention_days: Optional[int] = None
+ if message_retention_days_raw is not None:
if not user_profile.is_realm_owner:
raise OrganizationOwnerRequired()
realm.ensure_not_on_limited_plan()
message_retention_days = parse_message_retention_days(
- message_retention_days, Realm.MESSAGE_RETENTION_SPECIAL_VALUES_MAP)
+ message_retention_days_raw, Realm.MESSAGE_RETENTION_SPECIAL_VALUES_MAP)
# The user of `locals()` here is a bit of a code smell, but it's
# restricted to the elements present in realm.property_types.