FIX: Anonymizing user didn't replace uploaded avatar in posts

This commit is contained in:
Gerhard Schlager 2018-05-13 16:25:56 +02:00
parent 494fb36c77
commit 49392fb105
2 changed files with 28 additions and 1 deletions

View File

@ -20,6 +20,7 @@ class UserAnonymizer
@prev_email = @user.email
@prev_username = @user.username
@user.update_attribute(:uploaded_avatar_id, nil)
raise "Failed to change username" unless UsernameChanger.change(@user, make_anon_username)
@user.reload
@ -28,7 +29,6 @@ class UserAnonymizer
@user.name = SiteSetting.full_name_required ? @user.username : nil
@user.date_of_birth = nil
@user.title = nil
@user.uploaded_avatar_id = nil
anonymize_ips(@opts[:anonymize_ip]) if @opts.has_key?(:anonymize_ip)

View File

@ -119,6 +119,33 @@ describe UserAnonymizer do
expect(user.uploaded_avatar_id).to eq(nil)
end
it "updates the avatar in posts" do
upload = Fabricate(:upload, user: user)
user.user_avatar = UserAvatar.new(user_id: user.id, custom_upload_id: upload.id)
user.uploaded_avatar_id = upload.id # chosen in user preferences
user.save!
topic = Fabricate(:topic, user: user)
quoted_post = create_post(user: user, topic: topic, post_number: 1, raw: "quoted post")
post = create_post(raw: <<~RAW)
Lorem ipsum
[quote="#{quoted_post.username}, post:1, topic:#{quoted_post.topic.id}"]
quoted post
[/quote]
RAW
old_avatar_url = user.avatar_template.gsub("{size}", "40")
expect(post.cooked).to include(old_avatar_url)
make_anonymous
post.reload
new_avatar_url = user.reload.avatar_template.gsub("{size}", "40")
expect(post.cooked).to_not include(old_avatar_url)
expect(post.cooked).to include(new_avatar_url)
end
it "logs the action with the original details" do
SiteSetting.log_anonymizer_details = true
helper = UserAnonymizer.new(user, admin)