Permalink
Browse files

FIX: always import avatars during SSO if they are missing

  • Loading branch information...
SamSaffron committed Sep 15, 2016
1 parent b9801d2 commit 33578a2c178c955a01ed0a4e4da83ac97a5a1c2e
Showing with 18 additions and 3 deletions.
  1. +8 −3 app/models/discourse_single_sign_on.rb
  2. +10 −0 spec/models/discourse_single_sign_on_spec.rb
@@ -145,10 +145,15 @@ def change_external_attributes_and_override(sso_record, user)
user.name = name || User.suggest_name(username.blank? ? email : username)
end

if (SiteSetting.sso_overrides_avatar && avatar_url.present? && (
sso_record.external_avatar_url != avatar_url)) || avatar_force_update
avatar_missing = user.uploaded_avatar_id.nil? || !Upload.exists?(user.uploaded_avatar_id)

UserAvatar.import_url_for_user(avatar_url, user)
if (avatar_missing || avatar_force_update || SiteSetting.sso_overrides_avatar) && avatar_url.present?

avatar_changed = sso_record.external_avatar_url != avatar_url

if avatar_force_update || avatar_changed || avatar_missing
UserAvatar.import_url_for_user(avatar_url, user)
end
end

# change external attributes for sso record
@@ -294,6 +294,16 @@ def test_parsed(parsed, sso)
# initial creation ...
expect(avatar_id).to_not eq(nil)

# junk avatar id should be updated
old_id = user.uploaded_avatar_id
Upload.destroy(old_id)

user = sso.lookup_or_create_user(ip_address)
avatar_id = user.uploaded_avatar_id

expect(avatar_id).to_not eq(nil)
expect(old_id).to_not eq(avatar_id)

FileHelper.stubs(:download) { raise "should not be called" }
sso.avatar_url = "https://some.new/avatar.png"
user = sso.lookup_or_create_user(ip_address)

0 comments on commit 33578a2

Please sign in to comment.