FEATURE: send message when a user reaches tl1

This commit is contained in:
Jeff Wong 2018-06-22 09:51:07 -07:00
parent 6901e0e043
commit 41f76a74f8
5 changed files with 47 additions and 2 deletions

View File

@ -313,6 +313,11 @@ class User < ActiveRecord::Base
Jobs.enqueue(:send_system_message, user_id: id, message_type: message_type) Jobs.enqueue(:send_system_message, user_id: id, message_type: message_type)
end 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) def change_username(new_username, actor = nil)
UsernameChanger.change(self, new_username, actor) UsernameChanger.change(self, new_username, actor)
end end

View File

@ -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" 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." 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_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_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_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." 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! Enjoy your stay!
welcome_tl1_user:
title: "Welcome TL1 User"
subject_template: "Introduce Yourself"
text_body_template: |
Hey there. We see youve been busy reading, which is fantastic, so weve promoted you up a [trust level!]
Were really glad youre spending time with us and wed love to know more about you. Take a moment to [fill out your profile], or feel free to [start a new topic].
welcome_invite: welcome_invite:
title: "Welcome Invite" title: "Welcome Invite"
subject_template: "Welcome to %{site_name}!" subject_template: "Welcome to %{site_name}!"

View File

@ -990,6 +990,7 @@ trust:
default: 0 default: 0
enum: 'TrustLevelSetting' enum: 'TrustLevelSetting'
allow_flagging_staff: true allow_flagging_staff: true
send_tl1_welcome_message: true
tl1_requires_topics_entered: 5 tl1_requires_topics_entered: 5
tl1_requires_read_posts: tl1_requires_read_posts:
default: 30 default: 30

View File

@ -23,7 +23,11 @@ class Promotion
end end
def review_tl0 def 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
false
end end
def review_tl1 def review_tl1

View File

@ -53,7 +53,7 @@ describe Promotion do
end end
end end
context "that has done the requisite things" do context "that has not done the requisite things" do
it "does not promote the user" do it "does not promote the user" do
user.created_at = 1.minute.ago user.created_at = 1.minute.ago
stat = user.user_stat stat = user.user_stat
@ -66,6 +66,32 @@ describe Promotion do
end end
end end
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
end end
context "basic" do context "basic" do