From f8a46c510fcb877af45ddfc42db0118be762b776 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 16 Jun 2017 13:03:34 +0900 Subject: [PATCH] FIX: Recover post tutorial does not work when `SiteSetting.delete_removed_posts_after` is 0. --- .../advanced_user_narrative.rb | 18 +++++++++++++- .../advanced_user_narrative_spec.rb | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb index d20566af6b2..00b9e4366f0 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb @@ -144,7 +144,23 @@ module DiscourseNarrativeBot }) set_state_data(:post_id, post.id) - PostDestroyer.new(@user, post, skip_bot: true).destroy + + opts = { skip_bot: true } + + if SiteSetting.delete_removed_posts_after < 1 + opts[:delete_removed_posts_after] = 1 + + # Flag it and defer so the stub doesn't get destroyed + flag = PostAction.create!( + user: self.discobot_user, + post: post, post_action_type_id: + PostActionType.types[:off_topic] + ) + + PostAction.defer_flags!(post, self.discobot_user) + end + + PostDestroyer.new(@user, post, opts).destroy end def start_advanced_track diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb index eff130184a7..f6af336c206 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb @@ -303,6 +303,30 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do ) end + describe 'when posts are configured to be deleted immediately' do + before do + SiteSetting.delete_removed_posts_after = 0 + end + + it 'should set up the tutorial correctly' do + narrative.set_data(user, + state: :tutorial_delete, + topic_id: topic.id, + track: described_class.to_s + ) + + PostDestroyer.new(user, post).destroy + + post = Post.last + + expect(post.raw).to eq(I18n.t('js.post.deleted_by_author', count: 1)) + + PostDestroyer.destroy_stubs + + expect(post.reload).to be_present + end + end + describe 'when user replies to the topic' do it 'should create the right reply' do narrative.set_data(user, narrative.get_data(user).merge(