FEATURE: Add "Reset Bump Date" action to topic admin wrench (#6246)
This commit is contained in:
parent
6db623ef6b
commit
b9072e8292
|
@ -930,6 +930,10 @@ export default Ember.Controller.extend(BufferedContent, {
|
|||
|
||||
removeFeaturedLink() {
|
||||
this.set("buffered.featured_link", null);
|
||||
},
|
||||
|
||||
resetBumpDate() {
|
||||
this.get("content").resetBumpDate();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -565,6 +565,12 @@ const Topic = RestModel.extend({
|
|||
window.location.reload();
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
resetBumpDate() {
|
||||
return ajax(`/t/${this.get("id")}/reset-bump-date`, { type: "PUT" }).catch(
|
||||
popupAjaxError
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
showTopicStatusUpdate=showTopicStatusUpdate
|
||||
showFeatureTopic=showFeatureTopic
|
||||
showChangeTimestamp=showChangeTimestamp
|
||||
resetBumpDate=resetBumpDate
|
||||
convertToPublicTopic=convertToPublicTopic
|
||||
convertToPrivateMessage=convertToPrivateMessage}}
|
||||
{{/if}}
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
showTopicStatusUpdate=(action "topicRouteAction" "showTopicStatusUpdate")
|
||||
showFeatureTopic=(action "topicRouteAction" "showFeatureTopic")
|
||||
showChangeTimestamp=(action "topicRouteAction" "showChangeTimestamp")
|
||||
resetBumpDate=(action "resetBumpDate")
|
||||
convertToPublicTopic=(action "convertToPublicTopic")
|
||||
convertToPrivateMessage=(action "convertToPrivateMessage")}}
|
||||
{{/if}}
|
||||
|
@ -121,6 +122,7 @@
|
|||
showTopicStatusUpdate=(action "topicRouteAction" "showTopicStatusUpdate")
|
||||
showFeatureTopic=(action "topicRouteAction" "showFeatureTopic")
|
||||
showChangeTimestamp=(action "topicRouteAction" "showChangeTimestamp")
|
||||
resetBumpDate=(action "resetBumpDate")
|
||||
convertToPublicTopic=(action "convertToPublicTopic")
|
||||
convertToPrivateMessage=(action "convertToPrivateMessage")}}
|
||||
{{else}}
|
||||
|
@ -144,6 +146,7 @@
|
|||
showTopicStatusUpdate=(action "topicRouteAction" "showTopicStatusUpdate")
|
||||
showFeatureTopic=(action "topicRouteAction" "showFeatureTopic")
|
||||
showChangeTimestamp=(action "topicRouteAction" "showChangeTimestamp")
|
||||
resetBumpDate=(action "resetBumpDate")
|
||||
convertToPublicTopic=(action "convertToPublicTopic")
|
||||
convertToPrivateMessage=(action "convertToPrivateMessage")}}
|
||||
{{/if}}
|
||||
|
@ -256,6 +259,7 @@
|
|||
showTopicStatusUpdate=(action "topicRouteAction" "showTopicStatusUpdate")
|
||||
showFeatureTopic=(action "topicRouteAction" "showFeatureTopic")
|
||||
showChangeTimestamp=(action "topicRouteAction" "showChangeTimestamp")
|
||||
resetBumpDate=(action "resetBumpDate")
|
||||
convertToPublicTopic=(action "convertToPublicTopic")
|
||||
convertToPrivateMessage=(action "convertToPrivateMessage")
|
||||
toggleBookmark=(action "toggleBookmark")
|
||||
|
|
|
@ -203,6 +203,15 @@ export default createWidget("topic-admin-menu", {
|
|||
});
|
||||
}
|
||||
|
||||
if (this.currentUser.get("staff")) {
|
||||
buttons.push({
|
||||
className: "topic-admin-reset-bump-date",
|
||||
action: "resetBumpDate",
|
||||
icon: "anchor",
|
||||
label: "actions.reset_bump_date"
|
||||
});
|
||||
}
|
||||
|
||||
if (!isPrivateMessage) {
|
||||
buttons.push({
|
||||
className: "topic-admin-archive",
|
||||
|
|
|
@ -33,7 +33,8 @@ class TopicsController < ApplicationController
|
|||
:move_to_inbox,
|
||||
:convert_topic,
|
||||
:bookmark,
|
||||
:publish
|
||||
:publish,
|
||||
:reset_bump_date
|
||||
]
|
||||
|
||||
before_action :consider_user_for_promotion, only: :show
|
||||
|
@ -720,6 +721,17 @@ class TopicsController < ApplicationController
|
|||
render_json_error(ex)
|
||||
end
|
||||
|
||||
def reset_bump_date
|
||||
params.require(:id)
|
||||
guardian.ensure_can_update_bumped_at!
|
||||
|
||||
topic = Topic.find_by(id: params[:id])
|
||||
raise Discourse::NotFound.new unless topic
|
||||
|
||||
topic.reset_bumped_at
|
||||
render body: nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_params
|
||||
|
|
|
@ -1381,6 +1381,16 @@ class Topic < ActiveRecord::Base
|
|||
@is_category_topic ||= Category.exists?(topic_id: self.id.to_i)
|
||||
end
|
||||
|
||||
def reset_bumped_at
|
||||
post = ordered_posts.where(
|
||||
user_deleted: false,
|
||||
hidden: false,
|
||||
post_type: Topic.visible_post_types
|
||||
).last
|
||||
|
||||
update!(bumped_at: post.created_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_category_topic_count_by(num)
|
||||
|
|
|
@ -1862,6 +1862,7 @@ en:
|
|||
reset_read: "Reset Read Data"
|
||||
make_public: "Make Public Topic"
|
||||
make_private: "Make Personal Message"
|
||||
reset_bump_date: "Reset Bump Date"
|
||||
|
||||
feature:
|
||||
pin: "Pin Topic"
|
||||
|
|
|
@ -628,6 +628,7 @@ Discourse::Application.routes.draw do
|
|||
put "t/:id/convert-topic/:type" => "topics#convert_topic"
|
||||
put "t/:id/publish" => "topics#publish"
|
||||
put "t/:id/shared-draft" => "topics#update_shared_draft"
|
||||
put "t/:id/reset-bump-date" => "topics#reset_bump_date"
|
||||
put "topics/bulk"
|
||||
put "topics/reset-new" => 'topics#reset_new'
|
||||
post "topics/timings"
|
||||
|
|
|
@ -146,4 +146,8 @@ module TopicGuardian
|
|||
return false unless SiteSetting.topic_featured_link_enabled
|
||||
Category.where(id: category_id || SiteSetting.uncategorized_category_id, topic_featured_link_allowed: true).exists?
|
||||
end
|
||||
|
||||
def can_update_bumped_at?
|
||||
is_staff?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2296,4 +2296,27 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reset_bumped_at" do
|
||||
it "ignores hidden and deleted posts when resetting the topic's bump date" do
|
||||
post = create_post(created_at: 10.hours.ago)
|
||||
topic = post.topic
|
||||
|
||||
expect { topic.reset_bumped_at }.to_not change { topic.bumped_at }
|
||||
|
||||
post = Fabricate(:post, topic: topic, post_number: 2, created_at: 9.hours.ago)
|
||||
Fabricate(:post, topic: topic, post_number: 3, created_at: 8.hours.ago, deleted_at: 1.hour.ago)
|
||||
Fabricate(:post, topic: topic, post_number: 4, created_at: 7.hours.ago, hidden: true)
|
||||
Fabricate(:post, topic: topic, post_number: 5, created_at: 6.hours.ago, user_deleted: true)
|
||||
Fabricate(:post, topic: topic, post_number: 6, created_at: 5.hours.ago, post_type: Post.types[:whisper])
|
||||
|
||||
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
|
||||
|
||||
post = Fabricate(:post, topic: topic, post_number: 7, created_at: 4.hours.ago, post_type: Post.types[:moderator_action])
|
||||
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
|
||||
|
||||
post = Fabricate(:post, topic: topic, post_number: 8, created_at: 3.hours.ago, post_type: Post.types[:small_action])
|
||||
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2266,4 +2266,41 @@ RSpec.describe TopicsController do
|
|||
|
||||
end
|
||||
|
||||
describe "#reset_bump_date" do
|
||||
context "errors" do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
|
||||
it "needs you to be logged in" do
|
||||
put "/t/#{topic.id}/reset-bump-date.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
[:user, :trust_level_4].each do |user|
|
||||
it "denies access for #{user}" do
|
||||
sign_in(Fabricate(user))
|
||||
put "/t/#{topic.id}/reset-bump-date.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
it "should fail for non-existend topic" do
|
||||
sign_in(Fabricate(:admin))
|
||||
put "/t/1/reset-bump-date.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
||||
[:admin, :moderator].each do |user|
|
||||
it "should reset bumped_at as #{user}" do
|
||||
sign_in(Fabricate(user))
|
||||
topic = Fabricate(:topic, bumped_at: 1.hour.ago)
|
||||
timestamp = 1.day.ago
|
||||
Fabricate(:post, topic: topic, created_at: timestamp)
|
||||
|
||||
put "/t/#{topic.id}/reset-bump-date.json"
|
||||
expect(response.status).to eq(200)
|
||||
expect(topic.reload.bumped_at).to be_within_one_second_of(timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue