mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:41:25 +08:00
Extensibility for tracking changes to a topic
This commit is contained in:
@ -126,18 +126,19 @@ class TopicsController < ApplicationController
|
||||
guardian.ensure_can_edit!(topic)
|
||||
|
||||
changes = {}
|
||||
changes[:title] = params[:title] if params[:title] && topic.title != params[:title]
|
||||
changes[:category_id] = params[:category_id] if params[:category_id] && topic.category_id != params[:category_id].to_i
|
||||
PostRevisor.tracked_fields.keys.each do |f|
|
||||
changes[f] = params[f] if params.has_key?(f)
|
||||
end
|
||||
|
||||
changes.delete(:title) if topic.title == changes[:title]
|
||||
changes.delete(:category_id) if topic.category_id == changes[:category_id].to_i
|
||||
|
||||
success = true
|
||||
|
||||
if changes.length > 0
|
||||
first_post = topic.ordered_posts.first
|
||||
success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false)
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:topic_saved, topic, params, current_user)
|
||||
|
||||
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
||||
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
|
||||
end
|
||||
|
Reference in New Issue
Block a user