A platform for community discussion. Free, open, simple.
FIX: Disallow featuring hidden topics (#8814)
Mark VanLandingham089d38e9d3bc
diff --git a/app/services/topic_status_updater.rb b/app/services/topic_status_updater.rbindex 8c7489d8c22..f3aa541199c 100644--- a/app/services/topic_status_updater.rb+++ b/app/services/topic_status_updater.rb@@ -42,6 +42,10 @@ TopicStatusUpdater = Struct.new(:topic, :user) doDiscourseEvent.trigger(:topic_closed, topic)end+ if status.visible? && status.disabled?+ UserProfile.remove_featured_topic_from_all_profiles(topic)+ end+if @topic_status_updateif status.manually_closing_topic? || status.closing_topic?topic.delete_topic_timer(TopicTimer.types[:close])diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rbindex 6b28d5d8f3f..776d536ef10 100644--- a/lib/guardian/user_guardian.rb+++ b/lib/guardian/user_guardian.rb@@ -127,6 +127,7 @@ module UserGuardiandef can_feature_topic?(user, topic)return false if !SiteSetting.allow_featured_topic_on_user_profiles?return false if !is_me?(user) && !is_staff?+ return false if !topic.visiblereturn false if topic.read_restricted_category? || topic.private_message?trueenddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex b6494b209ec..73bfdc330b5 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -986,16 +986,21 @@ describe Topic docontext 'visibility' docontext 'disable' do- before do+ it 'should not be visible and have correct counts' dotopic.update_status('visible', false, @user)topic.reload- end-- it 'should not be visible and have correct counts' doexpect(topic).not_to be_visibleexpect(topic.moderator_posts_count).to eq(1)expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)end++ it 'removes itself as featured topic on user profiles' do+ user.user_profile.update(featured_topic_id: topic.id)+ expect(user.user_profile.featured_topic).to eq(topic)++ topic.update_status('visible', false, @user)+ expect(user.user_profile.reload.featured_topic).to eq(nil)+ endendcontext 'enable' dodiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 7e487b649e2..2a692fa159e 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -3923,6 +3923,13 @@ describe UsersController doexpect(response.status).to eq(403)end+ it "returns an error if the topic is not visible" do+ sign_in(user)+ topic.update_status('visible', false, user)+ put "/u/#{user.username}/feature-topic.json", params: { topic_id: topic.id }+ expect(response.status).to eq(403)+ end+it "returns an error if the topic's category is read_restricted" dosign_in(user)category.set_permissions({})