A platform for community discussion. Free, open, simple.
FIX: post mover validation color and message (#15688)
Krzysztof Kotlarekbb015636822b
diff --git a/app/assets/javascripts/discourse/app/controllers/move-to-topic.js b/app/assets/javascripts/discourse/app/controllers/move-to-topic.jsindex d5e87095416..c5f80bcab28 100644--- a/app/assets/javascripts/discourse/app/controllers/move-to-topic.js+++ b/app/assets/javascripts/discourse/app/controllers/move-to-topic.js@@ -169,7 +169,7 @@ export default Controller.extend(ModalFunctionality, {DiscourseURL.routeTo(result.url);}).catch((xhr) => {- this.flash(extractError(xhr, I18n.t("topic.move_to.error")));+ this.flash(extractError(xhr, I18n.t("topic.move_to.error")), "error");}).finally(() => {this.set("saving", false);diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex baeef8c3887..a7b758e20f4 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -839,7 +839,7 @@ class TopicsController < ApplicationControllerdestination_topic = move_posts_to_destination(topic)render_topic_changes(destination_topic)- rescue ActiveRecord::RecordInvalid => ex+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => exrender_json_error(ex)enddiff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex e24b9827d86..945d5473774 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -165,7 +165,7 @@ class PostMoverguardian: Guardian.new(user),skip_jobs: true)- new_post = @post_creator.create+ new_post = @post_creator.create!move_email_logs(post, new_post)diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex e1dfc7acd16..7328b2eb934 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -326,6 +326,21 @@ RSpec.describe TopicsController doexpect(result['success']).to eq(false)expect(result['url']).to be_blankend++ it 'returns plugin validation error' do+ # stub here is to simulate validation added by plugin which would be triggered when post is moved+ PostCreator.any_instance.stubs(:skip_validations?).returns(false)++ p1.update_columns(raw: "i", cooked: "")+ post "/t/#{topic.id}/move-posts.json", params: {+ post_ids: [p1.id],+ destination_topic_id: dest_topic.id+ }++ expect(response.status).to eq(422)+ result = response.parsed_body+ expect(result['errors']).to eq(["Body is too short (minimum is 5 characters) and Body seems unclear, is it a complete sentence?"])+ endendend