From dec40ea3cfad691ea2419bdc65308bd517b4834a Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 19 Jan 2016 18:19:35 +1100 Subject: [PATCH] FIX: raise proper error if system message creation fails FIX: skip validations when creating system messages --- lib/system_message.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/system_message.rb b/lib/system_message.rb index 3f19aa485..c60461df3 100644 --- a/lib/system_message.rb +++ b/lib/system_message.rb @@ -23,13 +23,18 @@ class SystemMessage title = I18n.t("system_messages.#{type}.subject_template", params) raw = I18n.t("system_messages.#{type}.text_body_template", params) - post = PostCreator.create(Discourse.site_contact_user, + creator = PostCreator.create(Discourse.site_contact_user, title: title, raw: raw, archetype: Archetype.private_message, target_usernames: @recipient.username, - subtype: TopicSubtype.system_message) + subtype: TopicSubtype.system_message, + skip_validations: true) + post = creator.create + if creator.errors.present? + raise StandardError, creator.errors.to_s + end UserArchivedMessage.create!(user: Discourse.site_contact_user, topic: post.topic)