From 19f3b8116150c3692e8bd4349cdb3708621a2ddd Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 23 Oct 2017 11:31:04 +0800 Subject: [PATCH] Revert "FIX: always trigger the ':user_updated' event" This reverts commit 519b70ea4692834638e4b95c92b81a2160621681. https://meta.discourse.org/t/creating-a-topic-or-a-post-sends-the-user-updated-webhook/71643 --- app/models/user.rb | 6 ------ app/services/user_updater.rb | 1 + spec/models/user_spec.rb | 11 ++++------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index c52b456ce45..2895c212321 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -108,7 +108,6 @@ class User < ActiveRecord::Base after_save :expire_old_email_tokens after_save :index_search after_commit :trigger_user_created_event, on: :create - after_commit :trigger_user_updated_event, on: :update before_destroy do # These tables don't have primary keys, so destroying them with activerecord is tricky: @@ -1098,11 +1097,6 @@ class User < ActiveRecord::Base true end - def trigger_user_updated_event - DiscourseEvent.trigger(:user_updated, self) - true - end - def set_should_validate_email if self.primary_email self.primary_email.should_validate_email = should_validate_email_address? diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index e2d3c703a7a..591a50a966f 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -122,6 +122,7 @@ class UserUpdater end end + DiscourseEvent.trigger(:user_updated, user) if saved saved end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cd075118343..ee0b4405a2f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -91,15 +91,12 @@ describe User do user.approve(admin) end - it 'triggers extensibility events' do + it 'triggers a extensibility event' do user && admin # bypass the user_created event - user_updated_event, user_approved_event = DiscourseEvent.track_events { user.approve(admin) } + event = DiscourseEvent.track_events { user.approve(admin) }.first - expect(user_updated_event[:event_name]).to eq(:user_updated) - expect(user_updated_event[:params].first).to eq(user) - - expect(user_approved_event[:event_name]).to eq(:user_approved) - expect(user_approved_event[:params].first).to eq(user) + expect(event[:event_name]).to eq(:user_approved) + expect(event[:params].first).to eq(user) end context 'after approval' do