FIX: Wizard tries harder to find existing Welcome Topic
The wizard searches for: * a topic that with the "is_welcome_topic" custom field * a topic with the correct slug for the current default locale * a topic with the correct slug for the English locale * the oldest globally pinned topic It gives up if it didn't find any of the above.
This commit is contained in:
parent
6cf2e64e44
commit
43cfdb1cb9
|
@ -39,9 +39,8 @@ class WizardStepSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
return translate("disabled") if object.disabled
|
key = object.disabled ? "disabled" : "description"
|
||||||
|
translate(key, object.description_vars)
|
||||||
translate("description", base_path: Discourse.base_path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_description?
|
def include_description?
|
||||||
|
|
|
@ -4049,10 +4049,10 @@ en:
|
||||||
|
|
||||||
introduction:
|
introduction:
|
||||||
title: "Introduction"
|
title: "Introduction"
|
||||||
disabled: "<p>We couldn’t find any topic with the title “Welcome to Discourse”.</p>
|
disabled: "<p>We couldn’t find any topic with the title “%{topic_title}”.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>If you have changed the title, edit that topic to modify your site’s introductory text.</li>
|
<li>If you have changed the title, edit that topic to modify your site’s introductory text.</li>
|
||||||
<li>If you have deleted this topic, create another topic with “Welcome to Discourse” as the title. The content of the first post is your site’s introductory text.</li>
|
<li>If you have deleted this topic, create another topic with “%{topic_title}” as the title. The content of the first post is your site’s introductory text.</li>
|
||||||
</ul>"
|
</ul>"
|
||||||
|
|
||||||
fields:
|
fields:
|
||||||
|
|
|
@ -22,25 +22,47 @@ class IntroductionUpdater
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def summary_from_post(post)
|
def summary_from_post(post)
|
||||||
return post ? post.raw.split("\n").first : nil
|
return post ? post.raw.split("\n").first : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_welcome_post
|
def find_welcome_post
|
||||||
topic_id = TopicCustomField.where(name: "is_welcome_topic").where(value: "true").pluck(:topic_id)
|
topic_id = TopicCustomField
|
||||||
unless topic_id.present?
|
.where(name: "is_welcome_topic", value: "true")
|
||||||
topic_id = Topic.listable_topics.where(slug: 'welcome-to-discourse').pluck(:id)
|
.pluck(:topic_id)
|
||||||
|
|
||||||
|
if topic_id.blank?
|
||||||
|
title = I18n.t("discourse_welcome_topic.title")
|
||||||
|
topic_id = find_topic_id(title)
|
||||||
|
end
|
||||||
|
|
||||||
|
if topic_id.blank?
|
||||||
|
title = I18n.t("discourse_welcome_topic.title", locale: :en)
|
||||||
|
topic_id = find_topic_id(title)
|
||||||
|
end
|
||||||
|
|
||||||
|
if topic_id.blank?
|
||||||
|
topic_id = Topic.listable_topics
|
||||||
|
.where(pinned_globally: true)
|
||||||
|
.order(:created_at)
|
||||||
|
.limit(1)
|
||||||
|
.pluck(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
welcome_topic = Topic.where(id: topic_id).first
|
welcome_topic = Topic.where(id: topic_id).first
|
||||||
return nil unless welcome_topic.present?
|
return nil if welcome_topic.blank?
|
||||||
|
|
||||||
post = welcome_topic.posts.where(post_number: 1).first
|
welcome_topic.first_post
|
||||||
return nil unless post.present?
|
|
||||||
|
|
||||||
post
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_topic_id(topic_title)
|
||||||
|
slug = Slug.for(topic_title, nil)
|
||||||
|
return nil if slug.blank?
|
||||||
|
|
||||||
|
Topic.listable_topics
|
||||||
|
.where(slug: slug)
|
||||||
|
.pluck(:id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,6 +48,7 @@ class Wizard
|
||||||
|
|
||||||
if @wizard.completed_steps?('introduction') && !introduction.get_summary
|
if @wizard.completed_steps?('introduction') && !introduction.get_summary
|
||||||
step.disabled = true
|
step.disabled = true
|
||||||
|
step.description_vars = { topic_title: I18n.t("discourse_welcome_topic.title") }
|
||||||
else
|
else
|
||||||
step.add_field(id: 'welcome', type: 'textarea', required: true, value: introduction.get_summary)
|
step.add_field(id: 'welcome', type: 'textarea', required: true, value: introduction.get_summary)
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@ class Wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
@wizard.append_step('corporate') do |step|
|
@wizard.append_step('corporate') do |step|
|
||||||
|
step.description_vars = { base_path: Discourse.base_path }
|
||||||
step.add_field(id: 'company_name', type: 'text', value: SiteSetting.company_name)
|
step.add_field(id: 'company_name', type: 'text', value: SiteSetting.company_name)
|
||||||
step.add_field(id: 'governing_law', type: 'text', value: SiteSetting.governing_law)
|
step.add_field(id: 'governing_law', type: 'text', value: SiteSetting.governing_law)
|
||||||
step.add_field(id: 'city_for_disputes', type: 'text', value: SiteSetting.city_for_disputes)
|
step.add_field(id: 'city_for_disputes', type: 'text', value: SiteSetting.city_for_disputes)
|
||||||
|
@ -263,6 +265,7 @@ class Wizard
|
||||||
|
|
||||||
@wizard.append_step('finished') do |step|
|
@wizard.append_step('finished') do |step|
|
||||||
step.banner = "finished.png"
|
step.banner = "finished.png"
|
||||||
|
step.description_vars = { base_path: Discourse.base_path }
|
||||||
end
|
end
|
||||||
@wizard
|
@wizard
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class Wizard
|
class Wizard
|
||||||
class Step
|
class Step
|
||||||
attr_reader :id, :updater
|
attr_reader :id, :updater
|
||||||
attr_accessor :index, :fields, :next, :previous, :banner, :disabled
|
attr_accessor :index, :fields, :next, :previous, :banner, :disabled, :description_vars
|
||||||
|
|
||||||
def initialize(id)
|
def initialize(id)
|
||||||
@id = id
|
@id = id
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
require 'introduction_updater'
|
||||||
|
|
||||||
|
describe IntroductionUpdater do
|
||||||
|
describe "#get_summary" do
|
||||||
|
subject { IntroductionUpdater.new(Fabricate(:admin)) }
|
||||||
|
|
||||||
|
let(:welcome_post_raw) { "lorem ipsum" }
|
||||||
|
let(:welcome_topic) do
|
||||||
|
topic = Fabricate(:topic)
|
||||||
|
Fabricate(:post, topic: topic, raw: welcome_post_raw, post_number: 1)
|
||||||
|
topic
|
||||||
|
end
|
||||||
|
|
||||||
|
it "finds the welcome topic by custom field" do
|
||||||
|
TopicCustomField.create(topic_id: welcome_topic.id, name: "is_welcome_topic", value: "true")
|
||||||
|
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "without custom field" do
|
||||||
|
it "finds the welcome topic by slug using the default locale" do
|
||||||
|
I18n.locale = :de
|
||||||
|
welcome_topic.title = I18n.t("discourse_welcome_topic.title")
|
||||||
|
welcome_topic.save!
|
||||||
|
|
||||||
|
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "finds the welcome topic by slug using the English locale" do
|
||||||
|
welcome_topic.title = I18n.t("discourse_welcome_topic.title", locale: :en)
|
||||||
|
welcome_topic.save!
|
||||||
|
I18n.locale = :de
|
||||||
|
|
||||||
|
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't find the topic when slug_generation_method is set to 'none'" do
|
||||||
|
SiteSetting.slug_generation_method = :none
|
||||||
|
welcome_topic.title = I18n.t("discourse_welcome_topic.title")
|
||||||
|
welcome_topic.save!
|
||||||
|
|
||||||
|
expect(subject.get_summary).to be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
it "finds the oldest globally pinned topic" do
|
||||||
|
welcome_topic.update_columns(pinned_at: Time.zone.now, pinned_globally: true)
|
||||||
|
|
||||||
|
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't find the topic when there is no globally pinned topic or a topic with the correct slug" do
|
||||||
|
expect(subject.get_summary).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue