2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-01 00:58:56 +08:00
|
|
|
class NewPostResult
|
|
|
|
include HasErrors
|
|
|
|
|
|
|
|
attr_reader :action
|
2015-04-29 03:06:27 +08:00
|
|
|
|
|
|
|
attr_accessor :reason
|
2015-04-01 00:58:56 +08:00
|
|
|
attr_accessor :post
|
2019-01-04 01:03:01 +08:00
|
|
|
attr_accessor :reviewable
|
2015-04-25 03:44:59 +08:00
|
|
|
attr_accessor :pending_count
|
2019-11-29 22:30:54 +08:00
|
|
|
attr_accessor :route_to
|
|
|
|
attr_accessor :message
|
2015-04-01 00:58:56 +08:00
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def initialize(action, success = false)
|
2015-04-01 00:58:56 +08:00
|
|
|
@action = action
|
|
|
|
@success = success
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_errors_from(obj)
|
|
|
|
if obj.errors.empty?
|
|
|
|
@success = true
|
|
|
|
else
|
|
|
|
add_errors_from(obj)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def check_errors(arr)
|
|
|
|
if arr.empty?
|
|
|
|
@success = true
|
|
|
|
else
|
2019-04-30 14:58:18 +08:00
|
|
|
arr.each { |e| errors.add(:base, e) unless errors[:base].include?(e) }
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def queued_post
|
|
|
|
Discourse.deprecate(
|
|
|
|
"NewPostManager#queued_post is deprecated. Please use #reviewable instead.",
|
|
|
|
output_in_test: true
|
|
|
|
)
|
|
|
|
|
|
|
|
reviewable
|
|
|
|
end
|
|
|
|
|
2015-04-01 00:58:56 +08:00
|
|
|
def success?
|
|
|
|
@success
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
|
|
|
!@success
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|