discourse/lib/topic_publisher.rb
Robin Ward b9abd7dc9e FEATURE: Shared Drafts
This feature can be enabled by choosing a destination for the
`shared drafts category` site setting.

* Staff members can create shared drafts, choosing a destination
category for the topic when it is published.

* Shared Drafts can be viewed in their category, or above the
topic list for the destination category where it will end up.

* When the shared draft is ready, it can be published to the
appropriate category by clicking a button on the topic view.

* When published, Drafts change their timestamps to the current
time, and any edits to the original post are removed.
2018-03-20 17:15:26 -04:00

42 lines
1.0 KiB
Ruby

class TopicPublisher
def initialize(topic, published_by, category_id)
@topic = topic
@published_by = published_by
@category_id = category_id
end
def publish!
TopicTimestampChanger.new(timestamp: Time.zone.now, topic: @topic).change! do
if @topic.private_message?
@topic = TopicConverter.new(@topic, @published_by)
.convert_to_public_topic(@category_id)
else
@topic.change_category_to_id(@category_id)
end
@topic.update_columns(visible: true)
StaffActionLogger.new(@published_by).log_topic_published(@topic)
# Clean up any publishing artifacts
SharedDraft.where(topic: @topic).delete_all
TopicTimer.where(topic: @topic).update_all(
deleted_at: DateTime.now,
deleted_by_id: @published_by.id
)
op = @topic.first_post
if op.present?
op.revisions.delete_all
op.update_column(:version, 1)
end
end
MessageBus.publish("/topic/#{@topic.id}", reload_topic: true, refresh_stream: true)
@topic
end
end