A platform for community discussion. Free, open, simple.
FEATURE: send message when a user reaches tl1
Jeff Wong41f76a74f83e
diff --git a/app/models/user.rb b/app/models/user.rbindex 9d87ccfd38b..40cc4e15ea8 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -313,6 +313,11 @@ class User < ActiveRecord::BaseJobs.enqueue(:send_system_message, user_id: id, message_type: message_type)end+ def enqueue_member_welcome_message+ return unless SiteSetting.send_tl1_welcome_message?+ Jobs.enqueue(:send_system_message, user_id: id, message_type: "welcome_tl1_user")+ end+def change_username(new_username, actor = nil)UsernameChanger.change(self, new_username, actor)enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex f3d7cd20334..adc1d763589 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1183,6 +1183,7 @@ en:track_external_right_clicks: "Track external links that are right clicked (eg: open in new tab) disabled by default because it rewrites URLs"site_contact_username: "A valid staff username to send all automated messages from. If left blank the default System account will be used."send_welcome_message: "Send all new users a welcome message with a quick start guide."+ send_tl1_welcome_message: "Send new trust level 1 users a welcome message."suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post."suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post."suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply."@@ -2196,6 +2197,14 @@ en:Enjoy your stay!+ welcome_tl1_user:+ title: "Welcome TL1 User"+ subject_template: "Introduce Yourself"+ text_body_template: |+ Hey there. We see you’ve been busy reading, which is fantastic, so we’ve promoted you up a [trust level!]++ We’re really glad you’re spending time with us and we’d love to know more about you. Take a moment to [fill out your profile], or feel free to [start a new topic].+welcome_invite:title: "Welcome Invite"subject_template: "Welcome to %{site_name}!"diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 68dded8cace..16d9e29cbaa 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -990,6 +990,7 @@ trust:default: 0enum: 'TrustLevelSetting'allow_flagging_staff: true+ send_tl1_welcome_message: truetl1_requires_topics_entered: 5tl1_requires_read_posts:default: 30diff --git a/lib/promotion.rb b/lib/promotion.rbindex d1d16b5e914..c6527b47dea 100644--- a/lib/promotion.rb+++ b/lib/promotion.rb@@ -23,7 +23,11 @@ class Promotionenddef review_tl0- Promotion.tl1_met?(@user) && change_trust_level!(TrustLevel[1])+ if Promotion.tl1_met?(@user) && change_trust_level!(TrustLevel[1])+ @user.enqueue_member_welcome_message+ return true+ end+ falseenddef review_tl1diff --git a/spec/components/promotion_spec.rb b/spec/components/promotion_spec.rbindex 716e4b16845..b8824335725 100644--- a/spec/components/promotion_spec.rb+++ b/spec/components/promotion_spec.rb@@ -53,7 +53,7 @@ describe Promotion doendend- context "that has done the requisite things" do+ context "that has not done the requisite things" doit "does not promote the user" douser.created_at = 1.minute.agostat = user.user_stat@@ -66,6 +66,32 @@ describe Promotion doendend+ context "may send tl1 promotion messages" do+ before do+ stat = user.user_stat+ stat.topics_entered = SiteSetting.tl1_requires_topics_entered+ stat.posts_read_count = SiteSetting.tl1_requires_read_posts+ stat.time_read = SiteSetting.tl1_requires_time_spent_mins * 60+ end+ it "sends promotion message by default" do+ SiteSetting.send_tl1_welcome_message = true+ Jobs.expects(:enqueue).with(+ :send_system_message,+ user_id: user.id, message_type: "welcome_tl1_user"+ ).once+ @result = promotion.review+ end++ it "can be turned off" do+ SiteSetting.send_tl1_welcome_message = false+ Jobs.expects(:enqueue).with(+ :send_system_message,+ user_id: user.id, message_type: "welcome_tl1_user"+ ).never+ @result = promotion.review+ end+ end+endcontext "basic" do