mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: User created web hook being enqueued before record has been saved.
* Improve web hook tests as well.
This commit is contained in:
@@ -93,7 +93,6 @@ class User < ActiveRecord::Base
|
||||
after_create :create_user_profile
|
||||
after_create :ensure_in_trust_level_group
|
||||
after_create :set_default_categories_preferences
|
||||
after_create :trigger_user_created_event
|
||||
|
||||
before_save :update_username_lower
|
||||
before_save :ensure_password_is_hashed
|
||||
@@ -105,6 +104,7 @@ class User < ActiveRecord::Base
|
||||
after_save :badge_grant
|
||||
after_save :expire_old_email_tokens
|
||||
after_save :index_search
|
||||
after_save :trigger_user_created_event
|
||||
|
||||
before_destroy do
|
||||
# These tables don't have primary keys, so destroying them with activerecord is tricky:
|
||||
|
||||
@@ -61,6 +61,7 @@ class WebHook < ActiveRecord::Base
|
||||
%i(post_created
|
||||
post_destroyed
|
||||
post_recovered).each do |event|
|
||||
|
||||
DiscourseEvent.on(event) do |post, _, user|
|
||||
WebHook.enqueue_post_hooks(event, post, user)
|
||||
end
|
||||
|
||||
@@ -96,15 +96,16 @@ class UserUpdater
|
||||
user.custom_fields = user.custom_fields.merge(fields)
|
||||
end
|
||||
|
||||
saved = nil
|
||||
|
||||
User.transaction do
|
||||
if attributes.key?(:muted_usernames)
|
||||
update_muted_users(attributes[:muted_usernames])
|
||||
end
|
||||
|
||||
saved = (!save_options || user.user_option.save) && user_profile.save && user.save
|
||||
if saved
|
||||
DiscourseEvent.trigger(:user_updated, user)
|
||||
|
||||
if saved
|
||||
# log name changes
|
||||
if attributes[:name].present? && old_user_name.downcase != attributes.fetch(:name).downcase
|
||||
StaffActionLogger.new(@actor).log_name_change(user.id, old_user_name, attributes.fetch(:name))
|
||||
@@ -112,8 +113,10 @@ class UserUpdater
|
||||
StaffActionLogger.new(@actor).log_name_change(user.id, old_user_name, "")
|
||||
end
|
||||
end
|
||||
saved
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:user_updated, user) if saved
|
||||
saved
|
||||
end
|
||||
|
||||
def update_muted_users(usernames)
|
||||
|
||||
Reference in New Issue
Block a user