A platform for community discussion. Free, open, simple.
FIX: Show message from discobot when staged user signs up
Gerhard Schlagerd9515c37b3f6
diff --git a/app/models/user.rb b/app/models/user.rbindex 39344eb28f9..d17a1eb6ec5 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -235,6 +235,8 @@ class User < ActiveRecord::Baseuser.staged = falseuser.active = falseuser.custom_fields[FROM_STAGED] = true++ DiscourseEvent.trigger(:user_unstaged, user)enduserend@@ -383,7 +385,7 @@ class User < ActiveRecord::Basedef read_first_notification?if (trust_level > TrustLevel[1] ||- created_at < TRACK_FIRST_NOTIFICATION_READ_DURATION.seconds.ago)+ (first_seen_at.present? && first_seen_at < TRACK_FIRST_NOTIFICATION_READ_DURATION.seconds.ago))return trueenddiff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rbindex cb95d19cba9..22dede0bbc8 100644--- a/plugins/discourse-narrative-bot/plugin.rb+++ b/plugins/discourse-narrative-bot/plugin.rb@@ -112,6 +112,10 @@ after_initialize doendend+ self.on(:user_unstaged) do |user|+ user.enqueue_bot_welcome_post+ end+self.add_to_class(:user, :enqueue_bot_welcome_post) doreturn if SiteSetting.disable_discourse_narrative_bot_welcome_postdiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex a0bcda79d8f..eb1fbd6fcf9 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -1478,7 +1478,7 @@ describe User dodescribe 'when user is an old user' doit 'should return the right value' do- user.update_attributes!(created_at: 1.year.ago)+ user.update_attributes!(first_seen_at: 1.year.ago)expect(user.read_first_notification?).to eq(true)end@@ -1581,9 +1581,10 @@ describe User doenddescribe "#unstage" do+ let!(:staged_user) { Fabricate(:staged, email: '[email protected]', active: true, username: 'staged1', name: 'Stage Name') }+ let(:params) { { email: '[email protected]', active: true, username: 'unstaged1', name: 'Foo Bar' } }+it "correctyl unstages a user" do- staged_user = Fabricate(:staged, email: '[email protected]', active: true, username: 'staged1', name: 'Stage Name')- params = { email: '[email protected]', active: true, username: 'unstaged1', name: 'Foo Bar' }user = User.unstage(params)expect(user.id).to eq(staged_user.id)@@ -1598,6 +1599,14 @@ describe User doexpect(User.unstage(email: '[email protected]')).to be_nilexpect(User.unstage(email: '[email protected]')).to be_nilend++ it "triggers an event" do+ unstaged_user = nil+ event = DiscourseEvent.track_events { unstaged_user = User.unstage(params) }.first++ expect(event[:event_name]).to eq(:user_unstaged)+ expect(event[:params].first).to eq(unstaged_user)+ endendend