make sure we pass in the user_id when creating avatar thumbnails

This commit is contained in:
Régis Hanol 2015-05-29 18:10:19 +02:00
parent fe4f8b1519
commit 0483f05154
5 changed files with 15 additions and 6 deletions

View File

@ -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")
});

View File

@ -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',

View File

@ -25,6 +25,7 @@
{{/if}}
</label>
{{avatar-uploader username=username
user_id=id
uploadedAvatarTemplate=uploadedAvatarTemplate
custom_avatar_upload_id=custom_avatar_upload_id
uploading=uploading

View File

@ -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 }

View File

@ -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