FIX: trigger user_updated webhook when avatar changes

This commit is contained in:
Maja Komel 2019-05-27 18:12:26 +02:00 committed by Guo Xiang Tan
parent 497a1d2d9f
commit 7da875f52a
2 changed files with 17 additions and 4 deletions

View File

@ -130,6 +130,8 @@ class User < ActiveRecord::Base
after_create :ensure_in_trust_level_group
after_create :set_default_categories_preferences
after_update :trigger_user_updated_event, if: :saved_change_to_uploaded_avatar_id?
before_save :update_usernames
before_save :ensure_password_is_hashed
before_save :match_title_to_primary_group_changes
@ -1414,6 +1416,11 @@ class User < ActiveRecord::Base
private
def trigger_user_updated_event
DiscourseEvent.trigger(:user_updated, self)
true
end
def check_if_title_is_badged_granted
if title_changed? && !new_record? && user_profile
badge_granted_title = title.present? && badges.where(allow_title: true, name: title).exists?

View File

@ -1926,10 +1926,13 @@ describe UsersController do
end
it 'can successfully pick a custom avatar' do
events = DiscourseEvent.track_events do
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
upload_id: upload.id, type: "custom"
}
end
expect(events.map { |event| event[:event_name] }).to include(:user_updated)
expect(response.status).to eq(200)
expect(user.reload.uploaded_avatar_id).to eq(upload.id)
expect(user.user_avatar.reload.custom_upload_id).to eq(upload.id)
@ -1981,8 +1984,11 @@ describe UsersController do
end
it 'can successfully select an avatar' do
events = DiscourseEvent.track_events do
put "/u/#{user.username}/preferences/avatar/select.json", params: { url: avatar1.url }
end
expect(events.map { |event| event[:event_name] }).to include(:user_updated)
expect(response.status).to eq(200)
expect(user.reload.uploaded_avatar_id).to eq(avatar1.id)
expect(user.user_avatar.reload.custom_upload_id).to eq(avatar1.id)