Add new welcome message step

This commit is contained in:
Robin Ward
2016-09-20 17:01:54 -04:00
parent ff17950993
commit 2545c2ffa6
8 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
class IntroductionUpdater
def initialize(user)
@user = user
end
def get_summary
summary_from_post(find_welcome_post)
end
def update_summary(new_value)
post = find_welcome_post
return unless post
previous_value = summary_from_post(post).strip
if previous_value != new_value
revisor = PostRevisor.new(post)
remaining = post.raw.split("\n")[1..-1]
revisor.revise!(@user, raw: "#{new_value}\n#{remaining.join("\n")}")
end
end
protected
def summary_from_post(post)
return post ? post.raw.split("\n").first : nil
end
def find_welcome_post
welcome_topic = Topic.where(slug: 'welcome-to-discourse').first
return nil unless welcome_topic.present?
post = welcome_topic.posts.where(post_number: 1).first
return nil unless post.present?
post
end
end

View File

@@ -1,3 +1,5 @@
require_dependency 'introduction_updater'
class Wizard
class Builder
@@ -40,6 +42,22 @@ class Wizard
end
end
@wizard.append_step('introduction') do |step|
introduction = IntroductionUpdater.new(@wizard.user)
step.add_field(id: 'welcome', type: 'textarea', required: true, value: introduction.get_summary)
step.on_update do |updater|
value = updater.fields[:welcome].strip
if value.index("\n")
updater.errors.add(:welcome, I18n.t("wizard.step.introduction.fields.welcome.one_paragraph"))
else
introduction.update_summary(value)
end
end
end
@wizard.append_step('privacy') do |step|
locked = SiteSetting.login_required? && SiteSetting.invite_only?
privacy = step.add_field(id: 'privacy',