mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add post_id parameter to reset_bump_date route (#25372)
This would allow a theme component (or an API call) to reset the bump date of a topic to a given post's created_at date. I picked `post_id` as the parameter here because it provides a bit of extra protection against accidentally resetting the bump date to a date that doesn't make sense.
This commit is contained in:
@@ -1151,12 +1151,14 @@ class TopicsController < ApplicationController
|
||||
|
||||
def reset_bump_date
|
||||
params.require(:id)
|
||||
params.permit(:post_id)
|
||||
|
||||
guardian.ensure_can_update_bumped_at!
|
||||
|
||||
topic = Topic.find_by(id: params[:id])
|
||||
raise Discourse::NotFound.new unless topic
|
||||
|
||||
topic.reset_bumped_at
|
||||
topic.reset_bumped_at(params[:post_id])
|
||||
render body: nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1858,13 +1858,21 @@ class Topic < ActiveRecord::Base
|
||||
@is_category_topic ||= Category.exists?(topic_id: self.id.to_i)
|
||||
end
|
||||
|
||||
def reset_bumped_at
|
||||
def reset_bumped_at(post_id = nil)
|
||||
post =
|
||||
ordered_posts.where(
|
||||
user_deleted: false,
|
||||
hidden: false,
|
||||
post_type: Post.types[:regular],
|
||||
).last || first_post
|
||||
(
|
||||
if post_id
|
||||
Post.find_by(id: post_id)
|
||||
else
|
||||
ordered_posts.where(
|
||||
user_deleted: false,
|
||||
hidden: false,
|
||||
post_type: Post.types[:regular],
|
||||
).last || first_post
|
||||
end
|
||||
)
|
||||
|
||||
return if !post
|
||||
|
||||
self.bumped_at = post.created_at
|
||||
self.save(validate: false)
|
||||
|
||||
Reference in New Issue
Block a user