FEATURE: Add hidden site settings for discobot to skip certain tutorials

Hidden for now because I'm undecided on whether this should be an
exposed interface.
This commit is contained in:
Guo Xiang Tan 2020-07-14 15:16:52 +08:00
parent cb68493e89
commit 75ad071899
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
4 changed files with 21 additions and 1 deletions

View File

@ -6,6 +6,7 @@ en:
discourse_narrative_bot_disable_public_replies: "Disable public replies by Discourse Narrative Bot"
discourse_narrative_bot_welcome_post_type: "Type of welcome post that the Discourse Narrative Bot should send out"
discourse_narrative_bot_welcome_post_delay: "Wait (n) seconds before sending the Discourse Narrative Bot welcome post."
discourse_narrative_bot_skip_tutorials: "Discourse Narrative Bot tutorials to skip"
badges:
certified:

View File

@ -7,6 +7,10 @@ plugins:
discourse_narrative_bot_welcome_post_type:
default: 'new_user_track'
enum: 'DiscourseNarrativeBot::WelcomePostTypeSiteSetting'
discourse_narrative_bot_skip_tutorials:
default: ''
type: list
hidden: true
discourse_narrative_bot_welcome_post_delay:
default: 0
discourse_narrative_bot_ignored_usernames:

View File

@ -30,7 +30,12 @@ module DiscourseNarrativeBot
next_opts = self.class::TRANSITION_TABLE.fetch(next_state)
prerequisite = next_opts[:prerequisite]
break if !prerequisite || instance_eval(&prerequisite)
if (!prerequisite || instance_eval(&prerequisite)) && !(
SiteSetting.discourse_narrative_bot_skip_tutorials.present? &&
SiteSetting.discourse_narrative_bot_skip_tutorials.split("|").include?(next_state.to_s))
break
end
[:next_state, :next_instructions].each do |key|
opts[key] = next_opts[key]

View File

@ -266,6 +266,16 @@ describe DiscourseNarrativeBot::NewUserNarrative do
expect(new_post.raw).to eq(expected_raw.chomp)
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_onebox)
end
it 'should skip tutorials in SiteSetting.discourse_narrative_bot_skip_tutorials' do
SiteSetting.discourse_narrative_bot_skip_tutorials = 'tutorial_onebox'
post.update!(raw: "@#{discobot_username} #{skip_trigger.upcase}")
DiscourseNarrativeBot::TrackSelector.new(:reply, user, post_id: post.id).select
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_emoji)
end
end
describe 'onebox tutorial' do