FEATURE: Allow moderators to change topic timestamps (#7053)

This commit is contained in:
Vinoth Kannan
2019-02-22 14:33:52 +05:30
committed by GitHub
parent 433f07fcb3
commit d1bad881ea
7 changed files with 44 additions and 16 deletions

View File

@ -676,17 +676,22 @@ class TopicsController < ApplicationController
end
def change_timestamps
params.require(:topic_id)
params.require(:timestamp)
topic_id = params.require(:topic_id).to_i
timestamp = params.require(:timestamp).to_f
guardian.ensure_can_change_post_timestamps!
topic = Topic.with_deleted.find(topic_id)
previous_timestamp = topic.first_post.created_at
begin
TopicTimestampChanger.new(
topic_id: params[:topic_id].to_i,
timestamp: params[:timestamp].to_f
topic: topic,
timestamp: timestamp
).change!
StaffActionLogger.new(current_user).log_topic_timestamps_changed(topic, Time.zone.at(timestamp), previous_timestamp)
render json: success_json
rescue ActiveRecord::RecordInvalid, TopicTimestampChanger::InvalidTimestampError
render json: failed_json, status: 422