A platform for community discussion. Free, open, simple.
FIX: Remove all notifications of staged user during sign-up
Gerhard Schlagerb784c1eda463
diff --git a/app/models/user.rb b/app/models/user.rbindex d17a1eb6ec5..1d4283659e6 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -235,6 +235,7 @@ class User < ActiveRecord::Baseuser.staged = falseuser.active = falseuser.custom_fields[FROM_STAGED] = true+ user.notifications.destroy_allDiscourseEvent.trigger(:user_unstaged, user)enddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex eb1fbd6fcf9..164d121848b 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -1600,6 +1600,16 @@ describe User doexpect(User.unstage(email: '[email protected]')).to be_nilend+ it "removes all previous notifications during unstaging" do+ Fabricate(:notification, user: user)+ Fabricate(:private_message_notification, user: user)+ user.reload++ expect(user.total_unread_notifications).to eq(2)+ user = User.unstage(params)+ expect(user.total_unread_notifications).to eq(0)+ end+it "triggers an event" dounstaged_user = nilevent = DiscourseEvent.track_events { unstaged_user = User.unstage(params) }.first