FIX: Show message from discobot when staged user signs up
This commit is contained in:
parent
eb52c5469e
commit
d9515c37b3
|
@ -235,6 +235,8 @@ class User < ActiveRecord::Base
|
|||
user.staged = false
|
||||
user.active = false
|
||||
user.custom_fields[FROM_STAGED] = true
|
||||
|
||||
DiscourseEvent.trigger(:user_unstaged, user)
|
||||
end
|
||||
user
|
||||
end
|
||||
|
@ -383,7 +385,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
def 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 true
|
||||
end
|
||||
|
|
|
@ -112,6 +112,10 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
self.on(:user_unstaged) do |user|
|
||||
user.enqueue_bot_welcome_post
|
||||
end
|
||||
|
||||
self.add_to_class(:user, :enqueue_bot_welcome_post) do
|
||||
return if SiteSetting.disable_discourse_narrative_bot_welcome_post
|
||||
|
||||
|
|
|
@ -1478,7 +1478,7 @@ describe User do
|
|||
|
||||
describe 'when user is an old user' do
|
||||
it '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 do
|
|||
end
|
||||
|
||||
describe "#unstage" do
|
||||
let!(:staged_user) { Fabricate(:staged, email: 'staged@account.com', active: true, username: 'staged1', name: 'Stage Name') }
|
||||
let(:params) { { email: 'staged@account.com', active: true, username: 'unstaged1', name: 'Foo Bar' } }
|
||||
|
||||
it "correctyl unstages a user" do
|
||||
staged_user = Fabricate(:staged, email: 'staged@account.com', active: true, username: 'staged1', name: 'Stage Name')
|
||||
params = { email: 'staged@account.com', 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 do
|
|||
expect(User.unstage(email: 'jeff@somewhere.com')).to be_nil
|
||||
expect(User.unstage(email: 'no@account.com')).to be_nil
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue