Skip to content

A platform for community discussion. Free, open, simple.

FEATURE Add reset bump dates bulk action (#16885)

Johannes Faiglebf987af3ca66
diff --git a/app/assets/javascripts/discourse/app/controllers/topic-bulk-actions.js b/app/assets/javascripts/discourse/app/controllers/topic-bulk-actions.js
index 50399e35c64..dc4283c407d 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic-bulk-actions.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic-bulk-actions.js
@@ -76,6 +76,13 @@ addBulkButton("relistTopics", "relist_topics", {
buttonVisible: (topics) =>
topics.some((t) => !t.visible) && !topics.some((t) => t.isPrivateMessage),
});
+addBulkButton("resetBumpDateTopics", "reset_bump_dates", {
+ icon: "anchor",
+ class: "btn-default",
+ buttonVisible() {
+ return this.currentUser.canManageTopic;
+ },
+});
addBulkButton("showTagTopics", "change_tags", {
icon: "tag",
class: "btn-default",
@@ -290,6 +297,10 @@ export default Controller.extend(ModalFunctionality, {
this.forEachPerformed({ type: "relist" }, (t) => t.set("visible", true));
},
+ resetBumpDateTopics() {
+ this.performAndRefresh({ type: "reset_bump_dates" });
+ },
+
changeCategory() {
const categoryId = parseInt(this.newCategoryId, 10) || 0;
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-bulk-actions-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-bulk-actions-test.js
index 95565ad9dc0..dc41baeeb72 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-bulk-actions-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-bulk-actions-test.js
@@ -76,6 +76,13 @@ acceptance("Topic - Bulk Actions", function (needs) {
"it shows an option to unlist topics"
);
+ assert.ok(
+ queryAll(".bulk-buttons")
+ .html()
+ .includes(I18n.t("topics.bulk.reset_bump_dates")),
+ "it shows an option to reset bump dates"
+ );
+
assert.ok(
queryAll(".bulk-buttons")
.html()
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 2f56bf698ba..6ab1f975723 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2538,6 +2538,7 @@ en:
clear_all: "Clear All"
unlist_topics: "Unlist Topics"
relist_topics: "Relist Topics"
+ reset_bump_dates: "Reset bump dates"
defer: "Defer"
delete: "Delete Topics"
dismiss: "Dismiss"
diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb
index 4939b792fec..8326d5c7999 100644
--- a/lib/topics_bulk_action.rb
+++ b/lib/topics_bulk_action.rb
@@ -14,7 +14,7 @@ class TopicsBulkAction
@operations ||= %w(change_category close archive change_notification_level
destroy_post_timing dismiss_posts delete unlist archive_messages
move_messages_to_inbox change_tags append_tags remove_tags
- relist dismiss_topics)
+ relist dismiss_topics reset_bump_dates)
end
def self.register_operation(name, &block)
@@ -166,6 +166,15 @@ class TopicsBulkAction
end
end
+ def reset_bump_dates
+ if guardian.can_update_bumped_at?
+ topics.each do |t|
+ t.reset_bumped_at
+ @changed_ids << t.id
+ end
+ end
+ end
+
def archive
topics.each do |t|
if guardian.can_moderate?(t)
diff --git a/spec/lib/topics_bulk_action_spec.rb b/spec/lib/topics_bulk_action_spec.rb
index 9e20569ffcd..523473f44e0 100644
--- a/spec/lib/topics_bulk_action_spec.rb
+++ b/spec/lib/topics_bulk_action_spec.rb
@@ -318,6 +318,34 @@ describe TopicsBulkAction do
end
end
+ describe "reset_bump_dates" do
+ context "when the user can update bumped at" do
+ it "does reset the topic bump date" do
+ post_created_at = 1.day.ago
+ create_post(topic_id: topic.id, created_at: post_created_at)
+ topic.update!(bumped_at: 1.hour.ago)
+ Guardian.any_instance.expects(:can_update_bumped_at?).returns(true)
+ tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_bump_dates')
+ topic_ids = tba.perform!
+ expect(topic_ids).to eq([topic.id])
+ expect(topic.reload.bumped_at).to eq_time(post_created_at)
+ end
+ end
+
+ context "when the user can't update bumped at" do
+ it "doesn't reset the topic bump date" do
+ create_post(topic_id: topic.id, created_at: 1.day.ago)
+ bumped_at = 1.hour.ago
+ topic.update!(bumped_at: bumped_at)
+ Guardian.any_instance.expects(:can_update_bumped_at?).returns(false)
+ tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_bump_dates')
+ topic_ids = tba.perform!
+ expect(topic_ids).to eq([])
+ expect(topic.reload.bumped_at).to eq_time(bumped_at)
+ end
+ end
+ end
+
describe "change_tags" do
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) }