user_groups: Allow not passing old_setting_api_value.

This commit is contained in:
Sahil Batra 2024-08-09 17:34:35 +05:30 committed by Tim Abbott
parent b1198785be
commit 3f800002be
1 changed files with 7 additions and 1 deletions

View File

@ -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(