FIX: discobot inappropriate flag section

Ensure that the inappropriate flag is used and not some other flag
type. If some other flag is used a message will be posted letting the
user know they used the wrong flag and the original flag will be removed
so that they can try again.

Bug reported on meta: https://meta.discourse.org/t/-/157075
This commit is contained in:
Blake Erickson 2020-08-03 19:38:04 -06:00
parent 8246b611ac
commit 18dad4cfbd
4 changed files with 25 additions and 5 deletions

View File

@ -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 didnt actually write a nasty post :angel:, Ive gone ahead and removed the flag for now.)
not_found: |-
Oh no, my nasty post hasnt 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">? Dont 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 hasnt 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">? Dont 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: |-

View File

@ -474,7 +474,14 @@ module DiscourseNarrativeBot
def missing_flag
return 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
end
fake_delay
reply_to(@post, I18n.t("#{I18N_KEY}.flag.not_found", i18n_post_args)) unless @data[:attempted]

View File

@ -223,8 +223,8 @@ after_initialize do
if 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 : :reply
when PostActionType.types[:like]
:like
when PostActionType.types[:bookmark]

View File

@ -840,7 +840,9 @@ describe DiscourseNarrativeBot::NewUserNarrative do
describe 'flag tutorial' do
let(: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 do
end
end
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 ' do
it 'should not do anything' do
narrative.expects(:enqueue_timeout_job).with(user).never