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