UX: better rejection message when reply via email is too short

This commit is contained in:
OsamaSayegh
2018-08-02 22:43:53 +03:00
parent 3dbaaf0d74
commit a157dfd418
5 changed files with 69 additions and 2 deletions
+5
View File
@@ -52,6 +52,7 @@ module Email
when Email::Receiver::TopicNotFoundError then :email_reject_topic_not_found
when Email::Receiver::TopicClosedError then :email_reject_topic_closed
when Email::Receiver::InvalidPost then :email_reject_invalid_post
when Email::Receiver::TooShortPost then :email_reject_post_too_short
when Email::Receiver::UnsubscribeNotAllowed then :email_reject_invalid_post
when ActiveRecord::Rollback then :email_reject_invalid_post
when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action
@@ -69,6 +70,10 @@ module Email
template_args[:post_error] = e.message
end
if message_template == :email_reject_post_too_short
template_args[:count] = SiteSetting.min_post_length
end
if message_template == :email_reject_unrecognized_error
msg = "Unrecognized error type (#{e.class}: #{e.message}) when processing incoming email"
msg += "\n\nBacktrace:\n#{e.backtrace.map { |l| " #{l}" }.join("\n")}"
+9 -1
View File
@@ -31,6 +31,7 @@ module Email
class TopicNotFoundError < ProcessingError; end
class TopicClosedError < ProcessingError; end
class InvalidPost < ProcessingError; end
class TooShortPost < ProcessingError; end
class InvalidPostAction < ProcessingError; end
class UnsubscribeNotAllowed < ProcessingError; end
class EmailNotAllowed < ProcessingError; end
@@ -932,7 +933,14 @@ module Email
user = options.delete(:user)
result = NewPostManager.new(user, options).perform
raise InvalidPost, result.errors.full_messages.join("\n") if result.errors.any?
errors = result.errors.full_messages
if errors.any? do |message|
message.include?(I18n.t("activerecord.attributes.post.raw").strip) &&
message.include?(I18n.t("errors.messages.too_short", count: SiteSetting.min_post_length).strip)
end
raise TooShortPost
end
raise InvalidPost, errors.join("\n") if result.errors.any?
if result.post
@incoming_email.update_columns(topic_id: result.post.topic_id, post_id: result.post.id)