FIX: raise proper error if system message creation fails

FIX: skip validations when creating system messages
This commit is contained in:
Sam 2016-01-19 18:19:35 +11:00
parent 843f93594f
commit dec40ea3cf

View file

@ -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)