From fc94d3e551ad57f4b98b3a45a6ae38d16067119c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 26 Mar 2013 23:49:23 -0700 Subject: [PATCH] match the create api with the update api ... so api is more consistent --- app/controllers/posts_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2d420907f90..1bc426c10dc 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -40,11 +40,28 @@ class PostsController < ApplicationController post.image_sizes = params[:image_sizes] if params[:image_sizes].present? guardian.ensure_can_edit!(post) + # to stay consistent with the create api, + # we should allow for title changes and category changes here + # we should also move all of this to a post updater. + if post.post_number == 1 && (params[:title] || params[:post][:category]) + post.topic.title = params[:title] if params[:title] + Topic.transaction do + post.topic.change_category(params[:post][:category]) + post.topic.save + end + + if post.topic.errors.present? + render_json_error(post.topic) + return + end + end + revisor = PostRevisor.new(post) if revisor.revise!(current_user, params[:post][:raw]) TopicLink.extract_from(post) end + if post.errors.present? render_json_error(post) return