From 190733883413c48ee23864aeb2dbaf1a77a40e9b Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 3 Oct 2018 17:21:53 -0700 Subject: [PATCH] FIX: No longer educate users who are editing A user editing a post will no longer get composer messages that are meant for new users posting replies and threads. These messages don't make sense in an edit context at all -- they're usually discussing making salient replies or topics, or adding avatars. They make even less sense when a user is an admin attempting to change the default topics for the first time. Since these messages actually do make sense for a user when they have a low post count, though, they're still going to occur. They just occur when a user is creating new content (and thus, more likely to read the notice), not during edits. This is in response to this issue: https://meta.discourse.org/t/education-message-for-editing-wiki-topic/66682 --- lib/composer_messages_finder.rb | 7 +++++ .../composer_messages_finder_spec.rb | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb index 23c58c62578..3a8c9f2d62c 100644 --- a/lib/composer_messages_finder.rb +++ b/lib/composer_messages_finder.rb @@ -11,10 +11,13 @@ class ComposerMessagesFinder end def find + return if editing_post? + self.class.check_methods.each do |m| msg = send(m) return msg if msg.present? end + nil end @@ -210,4 +213,8 @@ class ComposerMessagesFinder @details[:composer_action] == "reply" end + def editing_post? + @details[:composer_action] == "edit" + end + end diff --git a/spec/components/composer_messages_finder_spec.rb b/spec/components/composer_messages_finder_spec.rb index 7112e2812d8..538e1a5d8b4 100644 --- a/spec/components/composer_messages_finder_spec.rb +++ b/spec/components/composer_messages_finder_spec.rb @@ -467,4 +467,31 @@ describe ComposerMessagesFinder do end end + context 'when editing a post' do + let(:user) { Fabricate(:user) } + let(:topic) { Fabricate(:post).topic } + + let!(:post) do + post = PostCreator.create!( + user, + topic_id: topic.id, + post_number: 1, + raw: 'omg my first post' + ) + end + + let(:edit_post_finder) do + ComposerMessagesFinder.new(user, composer_action: 'edit') + end + + before do + SiteSetting.disable_avatar_education_message = true + SiteSetting.educate_until_posts = 2 + end + + it "returns nothing even if it normally would" do + expect(edit_post_finder.find).to eq(nil) + end + end + end