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.

user_groups: Allow not passing old_setting_api_value.

Sahil Batra3f800002be1d
diff --git a/zerver/actions/user_groups.py b/zerver/actions/user_groups.py
index 753f6b3dbab..68a681e8637 100644
--- a/zerver/actions/user_groups.py
+++ b/zerver/actions/user_groups.py
@@ -440,13 +440,19 @@ def do_change_user_group_permission_setting(
setting_name: str,
setting_value_group: UserGroup,
*,
- old_setting_api_value: int | AnonymousSettingGroupDict,
+ old_setting_api_value: int | AnonymousSettingGroupDict | None = None,
acting_user: UserProfile | None,
) -> None:
old_value = getattr(user_group, setting_name)
setattr(user_group, setting_name, setting_value_group)
user_group.save()
+ if old_setting_api_value is None:
+ # Most production callers will have computed this as part of
+ # verifying whether there's an actual change to make, but it
+ # feels quite clumsy to have to pass it from unit tests, so we
+ # compute it here if not provided by the caller.
+ old_setting_api_value = get_group_setting_value_for_api(old_value)
new_setting_api_value = get_group_setting_value_for_api(setting_value_group)
if not hasattr(old_value, "named_user_group") and hasattr(