def copy_user_settings(source_profile: UserProfile, target_profile: UserProfile) -> None: # Important note: Code run from here to configure the user's # settings should not call send_event, as that would cause clients # to throw an exception (we haven't sent the realm_user/add event # yet, so that event will include the updated details of target_profile). # # Note that this function will do at least one save() on target_profile. for settings_name in UserProfile.property_types: value = getattr(source_profile, settings_name) setattr(target_profile, settings_name, value) for settings_name in UserProfile.notification_setting_types: value = getattr(source_profile, settings_name) setattr(target_profile, settings_name, value) setattr(target_profile, "full_name", source_profile.full_name) setattr(target_profile, "enter_sends", source_profile.enter_sends) target_profile.save() if source_profile.avatar_source == UserProfile.AVATAR_FROM_USER: from zerver.lib.actions import do_change_avatar_fields do_change_avatar_fields( target_profile, UserProfile.AVATAR_FROM_USER, skip_notify=True, acting_user=target_profile, ) copy_avatar(source_profile, target_profile) copy_hotpots(source_profile, target_profile)
def copy_user_settings(source_profile: UserProfile, target_profile: UserProfile) -> None: """Warning: Does not save, to avoid extra database queries""" for settings_name in UserProfile.property_types: value = getattr(source_profile, settings_name) setattr(target_profile, settings_name, value) for settings_name in UserProfile.notification_setting_types: value = getattr(source_profile, settings_name) setattr(target_profile, settings_name, value) setattr(target_profile, "full_name", source_profile.full_name) setattr(target_profile, "enter_sends", source_profile.enter_sends) target_profile.save() if source_profile.avatar_source == UserProfile.AVATAR_FROM_USER: from zerver.lib.actions import do_change_avatar_fields do_change_avatar_fields(target_profile, UserProfile.AVATAR_FROM_USER) copy_avatar(source_profile, target_profile) copy_hotpots(source_profile, target_profile)