FIX: avatar was attached to the user who uploaded it...

This commit is contained in:
Régis Hanol 2013-10-12 10:55:41 +02:00
parent d55dc3dd99
commit 23bf4436f5
3 changed files with 12 additions and 5 deletions

View File

@ -314,7 +314,7 @@ class UsersController < ApplicationController
user.use_uploaded_avatar = true user.use_uploaded_avatar = true
user.save! user.save!
Jobs.enqueue(:generate_avatars, upload_id: upload.id) Jobs.enqueue(:generate_avatars, user_id: user.id, upload_id: upload.id)
render json: { render json: {
url: upload.url, url: upload.url,

View File

@ -5,8 +5,15 @@ module Jobs
class GenerateAvatars < Jobs::Base class GenerateAvatars < Jobs::Base
def execute(args) def execute(args)
upload = Upload.where(id: args[:upload_id]).first upload_id = args[:upload_id]
return unless upload.present? raise Discourse::InvalidParameters.new(:upload_id) unless upload_id.present?
user_id = args[:user_id]
raise Discourse::InvalidParameters.new(:user_id) unless user_id.present?
upload = Upload.where(id: upload_id).first
user = User.where(id: user_id).first
return unless upload.present? || user.present?
external_copy = Discourse.store.download(upload) if Discourse.store.external? external_copy = Discourse.store.download(upload) if Discourse.store.external?
original_path = if Discourse.store.external? original_path = if Discourse.store.external?
@ -37,7 +44,7 @@ module Jobs
# make sure we remove the cached copy from external stores # make sure we remove the cached copy from external stores
external_copy.close! if Discourse.store.external? external_copy.close! if Discourse.store.external?
user = User.where(id: upload.user_id).first # attach the avatar to the user
user.uploaded_avatar_template = Discourse.store.absolute_avatar_template(upload) user.uploaded_avatar_template = Discourse.store.absolute_avatar_template(upload)
user.save! user.save!

View File

@ -970,7 +970,7 @@ describe UsersController do
upload = Fabricate(:upload) upload = Fabricate(:upload)
Upload.expects(:create_for).returns(upload) Upload.expects(:create_for).returns(upload)
# enqueues the avatar generator job # enqueues the avatar generator job
Jobs.expects(:enqueue).with(:generate_avatars, { upload_id: upload.id }) Jobs.expects(:enqueue).with(:generate_avatars, { user_id: user.id, upload_id: upload.id })
xhr :post, :upload_avatar, username: user.username, file: avatar xhr :post, :upload_avatar, username: user.username, file: avatar
user.reload user.reload
# erase the previous template # erase the previous template