2015-03-26 16:57:50 -04:00
|
|
|
require_dependency 'topic_creator'
|
|
|
|
require_dependency 'queued_post'
|
|
|
|
require_dependency 'has_errors'
|
|
|
|
|
|
|
|
class PostEnqueuer
|
|
|
|
include HasErrors
|
|
|
|
|
|
|
|
def initialize(user, queue)
|
|
|
|
@user = user
|
|
|
|
@queue = queue
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue(args)
|
|
|
|
queued_post = QueuedPost.new(queue: @queue,
|
|
|
|
state: QueuedPost.states[:new],
|
|
|
|
user_id: @user.id,
|
|
|
|
topic_id: args[:topic_id],
|
|
|
|
raw: args[:raw],
|
|
|
|
post_options: args[:post_options] || {})
|
|
|
|
|
|
|
|
validate_method = :"validate_#{@queue}"
|
|
|
|
if respond_to?(validate_method)
|
|
|
|
return unless send(validate_method, queued_post.create_options)
|
|
|
|
end
|
|
|
|
|
2015-04-21 14:36:46 -04:00
|
|
|
if queued_post.save
|
2015-04-24 15:25:47 -04:00
|
|
|
queued_post.create_pending_action
|
2015-04-21 14:36:46 -04:00
|
|
|
else
|
|
|
|
add_errors_from(queued_post)
|
|
|
|
end
|
|
|
|
|
2015-03-26 16:57:50 -04:00
|
|
|
queued_post
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_new_topic(create_options)
|
|
|
|
topic_creator = TopicCreator.new(@user, Guardian.new(@user), create_options)
|
|
|
|
validate_child(topic_creator)
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_new_post(create_options)
|
|
|
|
post_creator = PostCreator.new(@user, create_options)
|
|
|
|
validate_child(post_creator)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|