mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:31:18 +08:00
FIX: display validation errors when converting topics (#27064)
When converting a PM to a public topic (and vice versa), if there was a validation error (like a topic already used, or a tag required or not allowed) the error message wasn't bubbled up nor shown to the user. This fix ensures we properly stop the conversion whenever a validation error happens and bubble up the errors back to the user so they can be informed. Internal ref - t/128795
This commit is contained in:
@ -1146,18 +1146,18 @@ class TopicsController < ApplicationController
|
||||
def convert_topic
|
||||
params.require(:id)
|
||||
params.require(:type)
|
||||
|
||||
topic = Topic.find_by(id: params[:id])
|
||||
guardian.ensure_can_convert_topic!(topic)
|
||||
|
||||
if params[:type] == "public"
|
||||
converted_topic =
|
||||
topic =
|
||||
if params[:type] == "public"
|
||||
topic.convert_to_public_topic(current_user, category_id: params[:category_id])
|
||||
else
|
||||
converted_topic = topic.convert_to_private_message(current_user)
|
||||
end
|
||||
render_topic_changes(converted_topic)
|
||||
rescue ActiveRecord::RecordInvalid => ex
|
||||
render_json_error(ex)
|
||||
else
|
||||
topic.convert_to_private_message(current_user)
|
||||
end
|
||||
|
||||
topic.valid? ? render_topic_changes(topic) : render_json_error(topic)
|
||||
end
|
||||
|
||||
def reset_bump_date
|
||||
|
Reference in New Issue
Block a user