FEATURE Add reset bump dates bulk action (#16885)
This commit is contained in:
parent
20d1f90edf
commit
bf987af3ca
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue