mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
avatars: Fix gravatar URLs with EMAIL_ADDRESS_VISIBILITY_ADMINS.
Previously, we were using user_profile.email rather than user_profile.delivery_email in all calculations involving Gravatar URLs, which meant that all organizations with the new EMAIL_ADDRESS_VISIBILITY_ADMINS setting enabled had useless gravatars not based on the `user15@host.domain` type fake email addresses we generate for the API to refer to users. The fix is to convert these calculations to use the user's delivery_email. Some refactoring is required to ensure the data is passed through to the parts of the codebase that do the check; fortunately, our automated tests of schemas are effective in verifying that the new `sender_delivery_email` field isn't visible to the API. Fixes #13369.
This commit is contained in:
@@ -884,6 +884,12 @@ def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) ->
|
||||
event = dict(type='realm_user', op='update', person=payload)
|
||||
send_event(user_profile.realm, event, [user_profile.id])
|
||||
|
||||
if user_profile.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR:
|
||||
# If the user is using Gravatar to manage their email address,
|
||||
# their Gravatar just changed, and we need to notify other
|
||||
# clients.
|
||||
notify_avatar_url_change(user_profile)
|
||||
|
||||
if user_profile.email_address_is_realm_public():
|
||||
# Additionally, if we're also changing the publicly visible
|
||||
# email, we send a new_email event as well.
|
||||
@@ -3330,16 +3336,7 @@ def do_regenerate_api_key(user_profile: UserProfile, acting_user: UserProfile) -
|
||||
|
||||
return new_api_key
|
||||
|
||||
def do_change_avatar_fields(user_profile: UserProfile, avatar_source: str) -> None:
|
||||
user_profile.avatar_source = avatar_source
|
||||
user_profile.avatar_version += 1
|
||||
user_profile.save(update_fields=["avatar_source", "avatar_version"])
|
||||
event_time = timezone_now()
|
||||
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
|
||||
event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
|
||||
extra_data={'avatar_source': avatar_source},
|
||||
event_time=event_time)
|
||||
|
||||
def notify_avatar_url_change(user_profile: UserProfile) -> None:
|
||||
if user_profile.is_bot:
|
||||
send_event(user_profile.realm,
|
||||
dict(type='realm_bot',
|
||||
@@ -3364,6 +3361,18 @@ def do_change_avatar_fields(user_profile: UserProfile, avatar_source: str) -> No
|
||||
person=payload),
|
||||
active_user_ids(user_profile.realm_id))
|
||||
|
||||
def do_change_avatar_fields(user_profile: UserProfile, avatar_source: str) -> None:
|
||||
user_profile.avatar_source = avatar_source
|
||||
user_profile.avatar_version += 1
|
||||
user_profile.save(update_fields=["avatar_source", "avatar_version"])
|
||||
event_time = timezone_now()
|
||||
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
|
||||
event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
|
||||
extra_data={'avatar_source': avatar_source},
|
||||
event_time=event_time)
|
||||
|
||||
notify_avatar_url_change(user_profile)
|
||||
|
||||
def do_delete_avatar_image(user: UserProfile) -> None:
|
||||
do_change_avatar_fields(user, UserProfile.AVATAR_FROM_GRAVATAR)
|
||||
delete_avatar_image(user)
|
||||
|
||||
Reference in New Issue
Block a user