diff --git a/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 b/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 index 69b2f94fe1e..8379606460b 100644 --- a/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 +++ b/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 @@ -17,5 +17,9 @@ export default Em.Component.extend(UploadMixin, { }); this.sendAction("done"); - } + }, + + data: function() { + return { user_id: this.get("user_id") }; + }.property("user_id") }); diff --git a/app/assets/javascripts/discourse/routes/preferences.js.es6 b/app/assets/javascripts/discourse/routes/preferences.js.es6 index 4fde634e0f7..67fd1b923e3 100644 --- a/app/assets/javascripts/discourse/routes/preferences.js.es6 +++ b/app/assets/javascripts/discourse/routes/preferences.js.es6 @@ -21,6 +21,7 @@ export default RestrictedUserRoute.extend(ShowFooter, { // all the properties needed for displaying the avatar selector modal const controller = this.controllerFor('avatar-selector'), props = this.modelFor('user').getProperties( + 'id', 'email', 'username', 'uploaded_avatar_id', diff --git a/app/assets/javascripts/discourse/templates/modal/avatar_selector.hbs b/app/assets/javascripts/discourse/templates/modal/avatar_selector.hbs index 6ca5b61037e..be857517d06 100644 --- a/app/assets/javascripts/discourse/templates/modal/avatar_selector.hbs +++ b/app/assets/javascripts/discourse/templates/modal/avatar_selector.hbs @@ -25,6 +25,7 @@ {{/if}} {{avatar-uploader username=username + user_id=id uploadedAvatarTemplate=uploadedAvatarTemplate custom_avatar_upload_id=custom_avatar_upload_id uploading=uploading diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index b40a87d0bd5..5f8921a6797 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -34,7 +34,7 @@ class UploadsController < ApplicationController end if upload.errors.empty? && FileHelper.is_image?(filename) - Jobs.enqueue(:create_thumbnails, upload_id: upload.id, type: type) + Jobs.enqueue(:create_thumbnails, upload_id: upload.id, type: type, user_id: params[:user_id]) end data = upload.errors.empty? ? upload : { errors: upload.errors.values.flatten } diff --git a/app/jobs/regular/create_thumbnails.rb b/app/jobs/regular/create_thumbnails.rb index 390aab8c67a..742d74877f6 100644 --- a/app/jobs/regular/create_thumbnails.rb +++ b/app/jobs/regular/create_thumbnails.rb @@ -3,21 +3,24 @@ module Jobs class CreateThumbnails < Jobs::Base def execute(args) - upload_id = args[:upload_id] type = args[:type] + upload_id = args[:upload_id] - raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank? raise Discourse::InvalidParameters.new(:type) if type.blank? + raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank? # only need to generate thumbnails for avatars return if type != "avatar" upload = Upload.find(upload_id) - self.send("create_thumbnails_for_#{type}", upload) + user_id = args[:user_id] || upload.user_id + user = User.find(user_id) + + self.send("create_thumbnails_for_#{type}", upload, user) end - def create_thumbnails_for_avatar(upload) + def create_thumbnails_for_avatar(upload, user) Discourse.avatar_sizes.each do |size| OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars) end