mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
FIX: post mover validation color and message (#15688)
When the record is not saved, we should display a proper message. One potential reason can be plugins for example discourse-calendar is specifying that only first post can contain event
This commit is contained in:

committed by
GitHub

parent
3da6f6b717
commit
bb01563682
@ -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);
|
||||
|
@ -839,7 +839,7 @@ class TopicsController < ApplicationController
|
||||
|
||||
destination_topic = move_posts_to_destination(topic)
|
||||
render_topic_changes(destination_topic)
|
||||
rescue ActiveRecord::RecordInvalid => ex
|
||||
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => ex
|
||||
render_json_error(ex)
|
||||
end
|
||||
|
||||
|
@ -165,7 +165,7 @@ class PostMover
|
||||
guardian: Guardian.new(user),
|
||||
skip_jobs: true
|
||||
)
|
||||
new_post = @post_creator.create
|
||||
new_post = @post_creator.create!
|
||||
|
||||
move_email_logs(post, new_post)
|
||||
|
||||
|
@ -326,6 +326,21 @@ RSpec.describe TopicsController do
|
||||
expect(result['success']).to eq(false)
|
||||
expect(result['url']).to be_blank
|
||||
end
|
||||
|
||||
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?"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user