FIX: trigger user_updated webhook when avatar changes
This commit is contained in:
parent
497a1d2d9f
commit
7da875f52a
|
@ -130,6 +130,8 @@ class User < ActiveRecord::Base
|
||||||
after_create :ensure_in_trust_level_group
|
after_create :ensure_in_trust_level_group
|
||||||
after_create :set_default_categories_preferences
|
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 :update_usernames
|
||||||
before_save :ensure_password_is_hashed
|
before_save :ensure_password_is_hashed
|
||||||
before_save :match_title_to_primary_group_changes
|
before_save :match_title_to_primary_group_changes
|
||||||
|
@ -1414,6 +1416,11 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def trigger_user_updated_event
|
||||||
|
DiscourseEvent.trigger(:user_updated, self)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def check_if_title_is_badged_granted
|
def check_if_title_is_badged_granted
|
||||||
if title_changed? && !new_record? && user_profile
|
if title_changed? && !new_record? && user_profile
|
||||||
badge_granted_title = title.present? && badges.where(allow_title: true, name: title).exists?
|
badge_granted_title = title.present? && badges.where(allow_title: true, name: title).exists?
|
||||||
|
|
|
@ -1926,10 +1926,13 @@ describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can successfully pick a custom avatar' do
|
it 'can successfully pick a custom avatar' do
|
||||||
|
events = DiscourseEvent.track_events do
|
||||||
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
|
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
|
||||||
upload_id: upload.id, type: "custom"
|
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(response.status).to eq(200)
|
||||||
expect(user.reload.uploaded_avatar_id).to eq(upload.id)
|
expect(user.reload.uploaded_avatar_id).to eq(upload.id)
|
||||||
expect(user.user_avatar.reload.custom_upload_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
|
end
|
||||||
|
|
||||||
it 'can successfully select an avatar' do
|
it 'can successfully select an avatar' do
|
||||||
|
events = DiscourseEvent.track_events do
|
||||||
put "/u/#{user.username}/preferences/avatar/select.json", params: { url: avatar1.url }
|
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(response.status).to eq(200)
|
||||||
expect(user.reload.uploaded_avatar_id).to eq(avatar1.id)
|
expect(user.reload.uploaded_avatar_id).to eq(avatar1.id)
|
||||||
expect(user.user_avatar.reload.custom_upload_id).to eq(avatar1.id)
|
expect(user.user_avatar.reload.custom_upload_id).to eq(avatar1.id)
|
||||||
|
|
Loading…
Reference in New Issue