Revert "Extract logic to save external avatar url"

This reverts commit 18b8df3f32.
This commit is contained in:
Robin Ward 2015-06-23 15:45:34 -04:00
parent 18b8df3f32
commit 2d20e4c692
2 changed files with 22 additions and 24 deletions

View File

@ -127,7 +127,28 @@ class DiscourseSingleSignOn < SingleSignOn
avatar_force_update ||
sso_record.external_avatar_url != avatar_url)
UserAvatar.import_url_for_user(avatar_url, user)
begin
tempfile = FileHelper.download(avatar_url, SiteSetting.max_image_size_kb.kilobytes, "sso-avatar", true)
ext = FastImage.type(tempfile).to_s
tempfile.rewind
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, tempfile.size, { origin: avatar_url })
user.uploaded_avatar_id = upload.id
unless user.user_avatar
user.build_user_avatar
end
if !user.user_avatar.contains_upload?(upload.id)
user.user_avatar.custom_upload_id = upload.id
end
rescue => e
# skip saving, we are not connected to the net
Rails.logger.warn "#{e}: Failed to download external avatar: #{avatar_url}, user id #{ user.id }"
ensure
tempfile.close! if tempfile && tempfile.respond_to?(:close!)
end
end
# change external attributes for sso record

View File

@ -62,29 +62,6 @@ class UserAvatar < ActiveRecord::Base
"#{upload_id}_#{OptimizedImage::VERSION}"
end
def self.import_url_for_user(avatar_url, user)
tempfile = FileHelper.download(avatar_url, SiteSetting.max_image_size_kb.kilobytes, "sso-avatar", true)
ext = FastImage.type(tempfile).to_s
tempfile.rewind
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, tempfile.size, { origin: avatar_url })
user.uploaded_avatar_id = upload.id
unless user.user_avatar
user.build_user_avatar
end
if !user.user_avatar.contains_upload?(upload.id)
user.user_avatar.custom_upload_id = upload.id
end
rescue => e
# skip saving, we are not connected to the net
Rails.logger.warn "#{e}: Failed to download external avatar: #{avatar_url}, user id #{ user.id }"
ensure
tempfile.close! if tempfile && tempfile.respond_to?(:close!)
end
end
# == Schema Information