mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:22 +08:00
FIX: avatar was attached to the user who uploaded it...
This commit is contained in:
parent
d55dc3dd99
commit
23bf4436f5
|
@ -314,7 +314,7 @@ class UsersController < ApplicationController
|
|||
user.use_uploaded_avatar = true
|
||||
user.save!
|
||||
|
||||
Jobs.enqueue(:generate_avatars, upload_id: upload.id)
|
||||
Jobs.enqueue(:generate_avatars, user_id: user.id, upload_id: upload.id)
|
||||
|
||||
render json: {
|
||||
url: upload.url,
|
||||
|
|
|
@ -5,8 +5,15 @@ module Jobs
|
|||
class GenerateAvatars < Jobs::Base
|
||||
|
||||
def execute(args)
|
||||
upload = Upload.where(id: args[:upload_id]).first
|
||||
return unless upload.present?
|
||||
upload_id = args[:upload_id]
|
||||
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?
|
||||
original_path = if Discourse.store.external?
|
||||
|
@ -37,7 +44,7 @@ module Jobs
|
|||
# make sure we remove the cached copy from external stores
|
||||
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.save!
|
||||
|
||||
|
|
|
@ -970,7 +970,7 @@ describe UsersController do
|
|||
upload = Fabricate(:upload)
|
||||
Upload.expects(:create_for).returns(upload)
|
||||
# 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
|
||||
user.reload
|
||||
# erase the previous template
|
||||
|
|
Loading…
Reference in New Issue
Block a user