From 92f4cdd3309d099e9a4f70a5016d138f2c07578e Mon Sep 17 00:00:00 2001 From: Jean Date: Wed, 27 Oct 2021 17:05:10 -0400 Subject: [PATCH] FEATURE: bypass topic bump when disable_category_edit_notifications is enabled (#14754) --- app/controllers/topics_controller.rb | 5 +++- spec/requests/topics_controller_spec.rb | 31 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 099cc16c751..c2d98ae5d0d 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -387,8 +387,11 @@ class TopicsController < ApplicationController success = true if changes.length > 0 + + bypass_bump = changes[:category_id].present? && SiteSetting.disable_category_edit_notifications + first_post = topic.ordered_posts.first - success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false) + success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false, bypass_bump: bypass_bump) if !success && topic.errors.blank? topic.errors.add(:base, :unable_to_update) diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 2aa3b858b2f..0171366710e 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1358,6 +1358,37 @@ RSpec.describe TopicsController do expect(response.status).to eq(200) end + context 'when using SiteSetting.disable_category_edit_notifications' do + it "doesn't bump the topic if the setting is enabled" do + SiteSetting.disable_category_edit_notifications = true + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil + + expect do + put "/t/#{topic.slug}/#{topic.id}.json", params: { + category_id: category.id + } + end.to change { topic.reload.category_id }.to(category.id) + + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).to eq_time(last_bumped_at) + end + + it "bumps the topic if the setting is disabled" do + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil + + expect do + put "/t/#{topic.slug}/#{topic.id}.json", params: { + category_id: category.id + } + end.to change { topic.reload.category_id }.to(category.id) + + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).not_to eq_time(last_bumped_at) + end + end + describe "when first post is locked" do it "blocks non-staff from editing even if 'trusted_users_can_edit_others' is true" do SiteSetting.trusted_users_can_edit_others = true