A platform for community discussion. Free, open, simple.
FIX: discobot inappropriate flag section
Blake Erickson18dad4cfbd8b
diff --git a/plugins/discourse-narrative-bot/config/locales/server.en.yml b/plugins/discourse-narrative-bot/config/locales/server.en.ymlindex 76efd5aa6d0..33bd9b72ea7 100644--- a/plugins/discourse-narrative-bot/config/locales/server.en.yml+++ b/plugins/discourse-narrative-bot/config/locales/server.en.yml@@ -291,7 +291,7 @@ en:reply: |-[Our staff](%{base_uri}/groups/staff) will be privately notified about your flag. If enough community members flag a post, it will also be automatically hidden as a precaution. (Since I didn’t actually write a nasty post :angel:, I’ve gone ahead and removed the flag for now.)not_found: |-- Oh no, my nasty post hasn’t been flagged yet. :worried: Can you flag it as inappropriate using the **flag** <img src="%{base_uri}/plugins/discourse-narrative-bot/images/font-awesome-flag.png" width="16" height="16">? Don’t forget to use the show more button <img src="%{base_uri}/plugins/discourse-narrative-bot/images/font-awesome-ellipsis.png" width="16" height="16"> to reveal more actions for each post.+ Oh no, my nasty post hasn’t been flagged as inappropriate yet. :worried: Can you flag it as inappropriate using the **flag** <img src="%{base_uri}/plugins/discourse-narrative-bot/images/font-awesome-flag.png" width="16" height="16">? Don’t forget to use the show more button <img src="%{base_uri}/plugins/discourse-narrative-bot/images/font-awesome-ellipsis.png" width="16" height="16"> to reveal more actions for each post.search:instructions: |-diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rbindex f9d1b639daf..8a9ed39cb49 100644--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb@@ -474,7 +474,14 @@ module DiscourseNarrativeBotdef missing_flagreturn unless valid_topic?(@post.topic_id)- return if @post.user_id == -2++ # Remove any incorrect flags so that they can try again+ if @post.user_id == -2+ @post.post_actions+ .where(user_id: @user.id)+ .where("post_action_type_id IN (?)", (PostActionType.flag_types.values - [PostActionType.types[:inappropriate]]))+ .destroy_all+ endfake_delayreply_to(@post, I18n.t("#{I18N_KEY}.flag.not_found", i18n_post_args)) unless @data[:attempted]diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rbindex 61047c0e8b2..55e765522fc 100644--- a/plugins/discourse-narrative-bot/plugin.rb+++ b/plugins/discourse-narrative-bot/plugin.rb@@ -223,8 +223,8 @@ after_initialize doif self.post && self.user.enqueue_narrative_bot_job?input =case self.post_action_type_id- when *PostActionType.flag_types_without_custom.values- :flag+ when *PostActionType.flag_types.values+ self.post_action_type_id == PostActionType.types[:inappropriate] ? :flag : :replywhen PostActionType.types[:like]:likewhen PostActionType.types[:bookmark]diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rbindex 9c3b5b73b8f..89d644c0335 100644--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb@@ -840,7 +840,9 @@ describe DiscourseNarrativeBot::NewUserNarrative dodescribe 'flag tutorial' dolet(:post) { Fabricate(:post, user: discobot_user, topic: topic) }- let(:flag) { Fabricate(:flag, post: post, user: user) }+ let(:another_post) { Fabricate(:post, user: discobot_user, topic: topic) }+ let(:flag) { Fabricate(:flag, post: post, user: user, post_action_type_id: PostActionType.types[:inappropriate]) }+ let(:other_flag) { Fabricate(:flag, post: another_post, user: user, post_action_type_id: PostActionType.types[:spam]) }let(:other_post) { Fabricate(:post, user: user, topic: topic) }before do@@ -858,6 +860,17 @@ describe DiscourseNarrativeBot::NewUserNarrative doendend+ describe 'when post is flagged incorrectly' do+ it 'should create the right reply and stay on the same step' do+ narrative.expects(:enqueue_timeout_job).with(user).never+ other_flag.update!(post: another_post)+ new_post = Post.last++ expect(new_post.raw).to eq(I18n.t('discourse_narrative_bot.new_user_narrative.flag.not_found', base_uri: ''))+ expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_flag)+ end+ end+describe 'when post being flagged does not belong to discobot ' doit 'should not do anything' donarrative.expects(:enqueue_timeout_job).with(user).never