Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add Concord and chat as homepage options to design wizard (#45109)

Penar Musaraj0e5b6a56a3b0
diff --git a/app/assets/stylesheets/common/components/design-wizard.scss b/app/assets/stylesheets/common/components/design-wizard.scss
index 69551bd42fd..8ce45c11be1 100644
--- a/app/assets/stylesheets/common/components/design-wizard.scss
+++ b/app/assets/stylesheets/common/components/design-wizard.scss
@@ -280,6 +280,25 @@ $dw-button-default-border: #d3d3d3;
color: inherit;
cursor: pointer;
+ &.--without-screenshot {
+ box-sizing: border-box;
+ padding: var(--space-3);
+ border: 1px solid var(--content-border-color);
+ border-radius: var(--d-border-radius);
+
+ &.--selected,
+ &:focus-within,
+ html.discourse-no-touch &:hover {
+ border-color: var(--tertiary);
+ box-shadow: 0 0 0 1px var(--tertiary);
+ }
+
+ .design-wizard__theme-enabled-badge {
+ position: static;
+ align-self: flex-start;
+ }
+ }
+
&.--selected .design-wizard__theme-screenshot {
border-color: var(--tertiary);
box-shadow: 0 0 0 1px var(--tertiary);
@@ -548,6 +567,16 @@ $dw-button-default-border: #d3d3d3;
border: 1px solid var(--content-border-color);
border-radius: var(--token-radius-small);
+ &.--icon {
+ align-items: center;
+ justify-content: center;
+
+ .d-icon {
+ width: 2em;
+ height: 2em;
+ }
+ }
+
&.--topics.--horizon {
background: var(--primary-very-low);
}
@@ -557,6 +586,10 @@ $dw-button-default-border: #d3d3d3;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 1fr;
}
+
+ &.--conversation .design-wizard__mock-line {
+ margin-block-end: 0;
+ }
}
&__detail-group {
@@ -599,6 +632,29 @@ $dw-button-default-border: #d3d3d3;
}
}
+ &__mock-message {
+ display: flex;
+ align-items: flex-start;
+ gap: var(--space-1);
+ flex: 1;
+ }
+
+ &__mock-message-body {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ gap: var(--space-1);
+ }
+
+ &__mock-composer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: var(--space-1);
+ border: 1px solid var(--content-border-color);
+ border-radius: var(--token-radius-small);
+ }
+
&__mock-card {
position: relative;
display: block;
diff --git a/app/controllers/admin/config/design_wizard_controller.rb b/app/controllers/admin/config/design_wizard_controller.rb
index 9895d9708d7..f13974a08ae 100644
--- a/app/controllers/admin/config/design_wizard_controller.rb
+++ b/app/controllers/admin/config/design_wizard_controller.rb
@@ -2,13 +2,13 @@
class Admin::Config::DesignWizardController < Admin::AdminController
def index
- core_themes =
- Theme
- .where(id: Theme::CORE_THEMES.values)
- .includes(:locale_fields, theme_fields: :upload)
+ themes =
+ DesignWizard::Themes
+ .selectable
+ .includes(:remote_theme, :locale_fields, theme_fields: :upload)
.order(:id)
- render_serialized(Theme.find_default, DesignWizardSerializer, root: false, themes: core_themes)
+ render_serialized(Theme.find_default, DesignWizardSerializer, root: false, themes:)
end
def update
diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb
index 21bcac963d1..7bb7c212608 100644
--- a/app/serializers/current_user_serializer.rb
+++ b/app/serializers/current_user_serializer.rb
@@ -177,12 +177,11 @@ class CurrentUserSerializer < BasicUserSerializer
scope.can_send_private_messages?
end
- # The wizard only offers the core themes and rewrites the site's design in one
- # pass, so it stops being useful once a site has been customized past what it
- # covers.
def include_can_run_design_wizard?
- object.admin? && Theme::CORE_THEMES.value?(SiteSetting.default_theme_id) &&
- !Theme.where.not(id: Theme::CORE_THEMES.values).exists?
+ return false if !object.admin?
+
+ theme_ids = DesignWizard::Themes.ids
+ theme_ids.include?(SiteSetting.default_theme_id) && !Theme.where.not(id: theme_ids).exists?
end
def can_run_design_wizard
diff --git a/app/serializers/design_wizard_serializer.rb b/app/serializers/design_wizard_serializer.rb
index ab6dafc08d8..e4915199715 100644
--- a/app/serializers/design_wizard_serializer.rb
+++ b/app/serializers/design_wizard_serializer.rb
@@ -3,14 +3,25 @@
class DesignWizardSerializer < ApplicationSerializer
attributes :current_theme, :base_font, :heading_font, :homepage, :palettes_user_selectable
- has_many :themes, serializer: DesignWizardThemeSerializer, embed: :objects
+ attributes :themes
+ attributes :additional_homepages, :homepage_settings
+
+ def additional_homepages
+ DesignWizard::Homepages.additional_options
+ end
+
+ def homepage_settings
+ DesignWizard::Homepages.current_settings
+ end
def themes
- @options[:themes]
+ @options[:themes].map do |theme|
+ DesignWizardThemeSerializer.new(theme, scope:, root: false).as_json
+ end + DesignWizard::Themes.available_to_install(@options[:themes], guardian: scope)
end
def current_theme
- return if object.nil? || Theme::CORE_THEMES.value?(object.id)
+ return if object.nil? || @options[:themes].any? { |theme| theme.id == object.id }
{ id: object.id, name: object.name }
end
@@ -35,9 +46,8 @@ class DesignWizardSerializer < ApplicationSerializer
private
- # The wizard offers Horizon when the current default is not a core theme.
def preselected_theme
- return object if Theme::CORE_THEMES.value?(object&.id)
+ return object if @options[:themes].any? { |theme| theme.id == object&.id }
Theme.horizon_theme
end
diff --git a/app/serializers/design_wizard_theme_serializer.rb b/app/serializers/design_wizard_theme_serializer.rb
index fa327b06e75..d5b047019f5 100644
--- a/app/serializers/design_wizard_theme_serializer.rb
+++ b/app/serializers/design_wizard_theme_serializer.rb
@@ -9,7 +9,17 @@ class DesignWizardThemeSerializer < ApplicationSerializer
:dark_color_scheme_id,
:screenshot_light_url,
:screenshot_dark_url,
- :palette_pairs
+ :palette_pairs,
+ :supports_welcome_banner,
+ :supports_search
+
+ def supports_welcome_banner
+ definition.fetch(:supports_welcome_banner, true)
+ end
+
+ def supports_search
+ definition.fetch(:supports_search, true)
+ end
def description
object.description(preloaded_locale_fields: object.locale_fields)
@@ -20,14 +30,26 @@ class DesignWizardThemeSerializer < ApplicationSerializer
end
def screenshot_light_url
- ThemeScreenshotThumbnails.url_for(object, "screenshot_light") || object.screenshot_light_url
+ ThemeScreenshotThumbnails.url_for(object, "screenshot_light") || object.screenshot_light_url ||
+ fallback_screenshot_url(:screenshot_light_url)
end
def screenshot_dark_url
- ThemeScreenshotThumbnails.url_for(object, "screenshot_dark") || object.screenshot_dark_url
+ ThemeScreenshotThumbnails.url_for(object, "screenshot_dark") || object.screenshot_dark_url ||
+ fallback_screenshot_url(:screenshot_dark_url)
end
def palette_pairs
DesignWizard::PalettePairs.for_theme(object)
end
+
+ private
+
+ def definition
+ @definition ||= DesignWizard::Themes.definition_for(object) || {}
+ end
+
+ def fallback_screenshot_url(name)
+ Discourse.base_path + definition[name] if definition[name]
+ end
end
diff --git a/app/services/design_wizard/apply.rb b/app/services/design_wizard/apply.rb
index 2f0aeac0cf5..57a4abb103c 100644
--- a/app/services/design_wizard/apply.rb
+++ b/app/services/design_wizard/apply.rb
@@ -22,6 +22,7 @@ class DesignWizard::Apply
attribute :base_font, :string
attribute :heading_font, :string
attribute :homepage, :string
+ attribute :homepage_settings, default: -> { {} }
attribute :category_page_style, :string
attribute :enable_welcome_banner, :boolean
attribute :welcome_banner_location, :string
@@ -35,14 +36,14 @@ class DesignWizard::Apply
self.search_experience = search_experience.presence
end
- validates :theme_id, presence: true, inclusion: { in: Theme::CORE_THEMES.values }
+ validates :theme_id, presence: true, inclusion: { in: ->(_) { DesignWizard::Themes.ids } }
validates :base_font,
:heading_font,
inclusion: {
in: BaseFontSetting.values.map { |font| font[:value] },
},
allow_blank: true
- validates :homepage, inclusion: { in: %w[latest new hot categories] }, allow_blank: true
+ validates :homepage, inclusion: { in: ->(_) { DesignWizard::Homepages.ids } }, allow_blank: true
validates :category_page_style,
inclusion: {
in: CategoryPageStyle.values.map { |style| style[:value] },
@@ -59,16 +60,23 @@ class DesignWizard::Apply
},
allow_blank: true
validate :built_in_palettes_exist
+ validate :homepage_settings_are_available
def site_settings(theme_id:)
- {
- default_theme_id: theme_id,
- base_font: base_font.presence,
- heading_font: heading_font.presence,
- default_homepage: homepage.presence,
- desktop_category_page_style: category_page_style.presence,
- welcome_banner_location: welcome_banner_location.presence,
- }.compact.map { |setting_name, value| { setting_name:, value: } }
+ DesignWizard::Homepages
+ .settings_for(homepage, overrides: homepage_settings)
+ .merge(
+ {
+ default_theme_id: theme_id,
+ base_font: base_font.presence,
+ heading_font: heading_font.presence,
+ default_homepage: homepage.presence,
+ desktop_category_page_style: category_page_style.presence,
+ welcome_banner_location: welcome_banner_location.presence,
+ },
+ )
+ .compact
+ .map { |setting_name, value| { setting_name:, value: } }
end
# the wizard re-sends every selection on each step, so skip the settings
@@ -83,6 +91,20 @@ class DesignWizard::Apply
private
+ def homepage_settings_are_available
+ if !homepage_settings.is_a?(Hash) ||
+ (homepage_settings.keys - DesignWizard::Homepages.current_settings.keys).any?
+ errors.add(:homepage_settings, :invalid)
+ return
+ end
+
+ homepage_settings.each do |name, value|
+ SiteSetting.type_supervisor.to_db_value(name, value)
+ rescue Discourse::InvalidParameters, ArgumentError
+ errors.add(:homepage_settings, :invalid)
+ end
+ end
+
def built_in_palettes_exist
%i[light_palette_id dark_palette_id].each do |attribute|
palette_id = public_send(attribute)
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 125ec66ba63..5de81bdadfc 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3193,6 +3193,7 @@ en:
suggest_weekends_in_date_pickers: "Include weekends (Saturday and Sunday) in date picker suggestions (disable this if you use Discourse only on weekdays, Monday through Friday)."
show_bottom_topic_map: "Shows the topic map at the bottom of the topic when it has 10 replies or more."
show_topic_map_in_topics_without_replies: "Shows the topic map even if the topic has no replies."
+ concord_in_wizard: "Offer Concord and the General chat homepage in the design wizard."
enable_site_owner_onboarding: "Shows a panel on the homepage to new admins to help them get started. Re-enable this setting to see the onboarding steps again."
site_owner_onboarding_max_days: "Maximum number of days after site creation to show the onboarding banner."
enable_welcome_banner: "Display a banner on your main topic list pages to welcome members and allow them to search site content"
@@ -6351,6 +6352,9 @@ en:
enable_rack_mini_profiler: "Enable Rack Mini Profiler to persist across session changes for 1 hour"
enter: "Enter Developer Mode"
design_wizard:
+ themes:
+ concord:
+ description: "A channel-based layout for categories, chat channels, and voice/video rooms."
errors:
palette_unavailable: "One of the selected color palettes is not available for the selected theme."
site_settings_update_failed: "The site settings could not be updated."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index e96cccde343..f71b6e1aee1 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4299,6 +4299,9 @@ uncategorized:
default: true
area: "posts_and_topics"
+ concord_in_wizard:
+ default: false
+ hidden: true
enable_site_owner_onboarding:
client: true
default: true
diff --git a/frontend/discourse/app/components/admin-onboarding/banner.gjs b/frontend/discourse/app/components/admin-onboarding/banner.gjs
index 35454b8b1f8..48ad4ce0aa7 100644
--- a/frontend/discourse/app/components/admin-onboarding/banner.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/banner.gjs
@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";
import { hash } from "@ember/helper";
import { action } from "@ember/object";
import { trackedArray, trackedSet } from "@ember/reactive/collections";
+import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
import { service } from "@ember/service";
import SiteSetting from "discourse/admin/models/site-setting";
import PredefinedTopicsOptionsModal from "discourse/components/admin-onboarding/modal/predefined-topics-options";
@@ -10,11 +11,13 @@ import StartPostingOptions from "discourse/components/admin-onboarding/modal/sta
import PredefinedTopicOption from "discourse/components/admin-onboarding/predefined-topics-option";
import OnboardingStep from "discourse/components/admin-onboarding/step";
import { logOnboardingEvent } from "discourse/lib/admin-onboarding";
+import { homepagePath } from "discourse/lib/homepage-router-overrides";
import { showCreateInviteModal } from "discourse/lib/invite-modal";
import { applyValueTransformer } from "discourse/lib/transformer";
import { defaultHomepage } from "discourse/lib/utilities";
import DButton from "discourse/ui-kit/d-button";
import dIcon from "discourse/ui-kit/helpers/d-icon";
+import dOnResize from "discourse/ui-kit/modifiers/d-on-resize";
import { i18n } from "discourse-i18n";
const STEPS = [
@@ -152,6 +155,8 @@ export default class AdminOnboardingBanner extends Component {
).map((Step) => Step.name)
);
+ #heightContainer;
+
constructor() {
super(...arguments);
this.appEvents.on(
@@ -179,8 +184,13 @@ export default class AdminOnboardingBanner extends Component {
return false;
}
- const { currentRouteName } = this.router;
- return currentRouteName === `discovery.${defaultHomepage()}`;
+ const { currentRouteName, currentURL } = this.router;
+ const path = currentURL?.split(/[?#]/)[0];
+ return (
+ currentRouteName === `discovery.${defaultHomepage()}` ||
+ path === "/" ||
+ path === homepagePath()
+ );
}
get completedSteps() {
@@ -208,6 +218,24 @@ export default class AdminOnboardingBanner extends Component {
this.minimized = !this.minimized;
}
+ @action
+ updateHeight(entries) {
+ const element = entries[0].target;
+ this.#heightContainer = element.parentElement;
+ this.#heightContainer.style.setProperty(
+ "--admin-onboarding-banner-height",
+ `${element.getBoundingClientRect().height}px`
+ );
+ }
+
+ @action
+ clearHeight() {
+ this.#heightContainer?.style.removeProperty(
+ "--admin-onboarding-banner-height"
+ );
+ this.#heightContainer = undefined;
+ }
+
@action
async endOnboarding({ skipped = true } = {}) {
await SiteSetting.update("enable_site_owner_onboarding", false);
@@ -229,7 +257,11 @@ export default class AdminOnboardingBanner extends Component {
<template>
{{#if this.shouldDisplay}}
- <div class="admin-onboarding-banner">
+ <div
+ class="admin-onboarding-banner"
+ {{dOnResize this.updateHeight}}
+ {{willDestroy this.clearHeight}}
+ >
<div class="admin-onboarding-banner__wrap">
<div class="admin-onboarding-banner__header">
<div class="admin-onboarding-banner__header-text">
diff --git a/frontend/discourse/app/components/design-wizard/controls.gjs b/frontend/discourse/app/components/design-wizard/controls.gjs
index 0940efa4133..4ced8c6b34b 100644
--- a/frontend/discourse/app/components/design-wizard/controls.gjs
+++ b/frontend/discourse/app/components/design-wizard/controls.gjs
@@ -205,6 +205,7 @@ export default class DesignWizardControls extends Component {
{{else}}
<Section @title={{i18n "design_wizard.sections.homepage"}}>
<HomepageSection
+ @additionalHomepages={{this.designWizard.additionalHomepages}}
@categoryPageStyle={{this.designWizard.categoryPageStyle}}
@homepage={{this.designWizard.homepage}}
@onSelectCategoryPageStyle={{this.selectCategoryPageStyle}}
@@ -213,21 +214,25 @@ export default class DesignWizardControls extends Component {
/>
</Section>
- <Section @title={{i18n "design_wizard.sections.welcome_banner"}}>
- <WelcomeBannerSection
- @enabled={{this.designWizard.welcomeBanner}}
- @location={{this.designWizard.welcomeBannerLocation}}
- @onSelectLocation={{this.selectWelcomeBannerLocation}}
- @onToggle={{this.toggleWelcomeBanner}}
- />
- </Section>
-
- <Section @title={{i18n "design_wizard.sections.search"}}>
- <SearchSection
- @onSelect={{this.selectSearchExperience}}
- @searchExperience={{this.designWizard.searchExperience}}
- />
- </Section>
+ {{#if this.designWizard.supportsWelcomeBanner}}
+ <Section @title={{i18n "design_wizard.sections.welcome_banner"}}>
+ <WelcomeBannerSection
+ @enabled={{this.designWizard.welcomeBanner}}
+ @location={{this.designWizard.welcomeBannerLocation}}
+ @onSelectLocation={{this.selectWelcomeBannerLocation}}
+ @onToggle={{this.toggleWelcomeBanner}}
+ />
+ </Section>
+
+ {{/if}}
+ {{#if this.designWizard.supportsSearch}}
+ <Section @title={{i18n "design_wizard.sections.search"}}>
+ <SearchSection
+ @onSelect={{this.selectSearchExperience}}
+ @searchExperience={{this.designWizard.searchExperience}}
+ />
+ </Section>
+ {{/if}}
{{/if}}
</div>
diff --git a/frontend/discourse/app/components/design-wizard/homepage-section.gjs b/frontend/discourse/app/components/design-wizard/homepage-section.gjs
index b609bb6fbe8..111124e5bc1 100644
--- a/frontend/discourse/app/components/design-wizard/homepage-section.gjs
+++ b/frontend/discourse/app/components/design-wizard/homepage-section.gjs
@@ -2,10 +2,15 @@ import { array, fn } from "@ember/helper";
import { on } from "@ember/modifier";
import OptionRow from "discourse/components/design-wizard/option-row";
import { HORIZON_THEME_ID } from "discourse/lib/theme-selector";
+import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
const TOPIC_PAGES = ["latest", "new", "hot"];
+function isTopicPage(page) {
+ return TOPIC_PAGES.includes(page);
+}
+
function topicPageLabel(page) {
return i18n(`filters.${page}.title`);
}
@@ -104,12 +109,28 @@ const CategoryStyleMock = <template>
{{/if}}
</template>;
+const ConversationMock = <template>
+ {{#each (array 1 2 3)}}
+ <span class="design-wizard__mock-message">
+ <span class="design-wizard__mock-avatar"></span>
+ <span class="design-wizard__mock-message-body">
+ <span class="design-wizard__mock-line --title"></span>
+ <span class="design-wizard__mock-line --text"></span>
+ </span>
+ </span>
+ {{/each}}
+ <span class="design-wizard__mock-composer">
+ <span class="design-wizard__mock-line --text"></span>
+ <span class="design-wizard__mock-avatar"></span>
+ </span>
+</template>;
+
const DesignWizardHomepageSection = <template>
<div class="design-wizard__homepage-cards">
<button
- aria-pressed={{if (eq @homepage "categories") "false" "true"}}
+ aria-pressed={{if (isTopicPage @homepage) "true" "false"}}
class="design-wizard__homepage-card
- {{unless (eq @homepage 'categories') '--selected'}}"
+ {{if (isTopicPage @homepage) '--selected'}}"
data-homepage="topics"
type="button"
{{on "click" (fn @onSelectHomepage "latest")}}
@@ -135,6 +156,30 @@ const DesignWizardHomepageSection = <template>
</span>
{{i18n "design_wizard.homepage.categories"}}
</button>
+ {{#each @additionalHomepages as |option|}}
+ <button
+ aria-pressed={{if (eq @homepage option.id) "true" "false"}}
+ class="design-wizard__homepage-card
+ {{if (eq @homepage option.id) '--selected'}}"
+ data-homepage={{option.id}}
+ type="button"
+ {{on "click" (fn @onSelectHomepage option.id)}}
+ >
+ {{#if (eq option.illustration "conversation")}}
+ <span
+ aria-hidden="true"
+ class="design-wizard__homepage-thumbnail --conversation"
+ >
+ <ConversationMock />
+ </span>
+ {{else}}
+ <span class="design-wizard__homepage-thumbnail --icon">
+ {{dIcon option.icon}}
+ </span>
+ {{/if}}
+ {{option.name}}
+ </button>
+ {{/each}}
</div>
{{#if (eq @homepage "categories")}}
@@ -165,7 +210,7 @@ const DesignWizardHomepageSection = <template>
{{/let}}
</div>
</div>
- {{else}}
+ {{else if (isTopicPage @homepage)}}
<div class="design-wizard__detail-group">
<span class="design-wizard__label">
{{i18n "design_wizard.homepage.topic_page_type"}}
@@ -182,6 +227,12 @@ const DesignWizardHomepageSection = <template>
{{/each}}
</div>
</div>
+ {{else}}
+ {{#each @additionalHomepages as |option|}}
+ {{#if (eq @homepage option.id)}}
+ <p class="design-wizard__detail-group">{{option.description}}</p>
+ {{/if}}
+ {{/each}}
{{/if}}
</template>;
diff --git a/frontend/discourse/app/components/design-wizard/theme-section.gjs b/frontend/discourse/app/components/design-wizard/theme-section.gjs
index b8b9488b38e..6bdf65102e7 100644
--- a/frontend/discourse/app/components/design-wizard/theme-section.gjs
+++ b/frontend/discourse/app/components/design-wizard/theme-section.gjs
@@ -4,6 +4,7 @@ import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
@@ -50,7 +51,11 @@ class ThemeCard extends Component {
<template>
<div class="design-wizard__theme-card-wrapper">
<label
- class="design-wizard__theme-card {{if this.selected '--selected'}}"
+ class={{dConcatClass
+ "design-wizard__theme-card"
+ (if this.selected "--selected")
+ (unless this.currentScreenshotUrl "--without-screenshot")
+ }}
data-theme-id={{@theme.id}}
>
<input
@@ -73,11 +78,11 @@ class ThemeCard extends Component {
{{i18n "design_wizard.theme.selected"}}
</span>
{{/if}}
- <span
- class="design-wizard__theme-screenshot
- {{if this.showSkeleton '--loading'}}"
- >
- {{#if this.currentScreenshotUrl}}
+ {{#if this.currentScreenshotUrl}}
+ <span
+ class="design-wizard__theme-screenshot
+ {{if this.showSkeleton '--loading'}}"
+ >
<img
alt=""
class="design-wizard__theme-screenshot-image"
@@ -89,8 +94,8 @@ class ThemeCard extends Component {
{{on "load" this.screenshotSettled}}
{{on "error" this.screenshotSettled}}
/>
- {{/if}}
- </span>
+ </span>
+ {{/if}}
<span class="design-wizard__theme-name">{{@theme.name}}</span>
<span class="design-wizard__theme-description">
{{@theme.description}}
diff --git a/frontend/discourse/app/services/design-wizard.js b/frontend/discourse/app/services/design-wizard.js
index 1e3a6288fb7..29a3261e013 100644
--- a/frontend/discourse/app/services/design-wizard.js
+++ b/frontend/discourse/app/services/design-wizard.js
@@ -59,6 +59,7 @@ export default class DesignWizardService extends Service {
@tracked bodyFont;
@tracked headingFont;
@tracked homepage;
+ @tracked homepageSettings;
@tracked categoryPageStyle;
@tracked welcomeBanner;
@tracked welcomeBannerLocation;
@@ -82,6 +83,7 @@ export default class DesignWizardService extends Service {
#starting = false;
#startFailed = false;
#originalSiteSettings;
+ #originalHomepageSettings;
#originalColorSchemeLinks;
#prefetched = false;
@@ -89,6 +91,25 @@ export default class DesignWizardService extends Service {
return this.data?.themes.find((theme) => theme.id === this.themeId);
}
+ get additionalHomepages() {
+ return this.data?.additional_homepages ?? [];
+ }
+
+ get supportsWelcomeBanner() {
+ return this.selectedTheme?.supports_welcome_banner !== false;
+ }
+
+ get supportsSearch() {
+ return this.selectedTheme?.supports_search !== false;
+ }
+
+ get #supportedHomepages() {
+ return [
+ ...SUPPORTED_HOMEPAGES,
+ ...this.additionalHomepages.map(({ id }) => id),
+ ];
+ }
+
get pairs() {
return this.selectedTheme?.palette_pairs ?? [];
}
@@ -112,8 +133,7 @@ export default class DesignWizardService extends Service {
: (pair.light ?? pair.dark);
}
- // the endpoint only accepts core themes, so a site whose default theme the
- // wizard cannot express is not offered a way back to it
+ // Only themes offered by the wizard can be restored through its endpoint.
get canRevert() {
return (
this.source === SOURCE_ADMIN && this.progressSaved && !!this.#snapshot
@@ -135,11 +155,18 @@ export default class DesignWizardService extends Service {
base_font: this.bodyFont,
heading_font: this.headingFont,
homepage: this.homepage,
+ homepage_settings: this.homepageSettings,
category_page_style:
this.homepage === "categories" ? this.categoryPageStyle : null,
- enable_welcome_banner: this.welcomeBanner,
- welcome_banner_location: this.welcomeBannerLocation,
- search_experience: this.searchExperience,
+ ...(this.supportsWelcomeBanner
+ ? {
+ enable_welcome_banner: this.welcomeBanner,
+ welcome_banner_location: this.welcomeBannerLocation,
+ }
+ : {}),
+ ...(this.supportsSearch
+ ? { search_experience: this.searchExperience }
+ : {}),
};
}
@@ -286,13 +313,37 @@ export default class DesignWizardService extends Service {
this.showIntro = false;
}
- selectTheme(themeId) {
+ async selectTheme(themeId) {
if (themeId === this.themeId || this.applyingTheme) {
return;
}
this.applyingTheme = true;
+ const previousThemeId = this.themeId;
+ const theme = this.data.themes.find(
+ (candidate) => candidate.id === themeId
+ );
this.themeId = themeId;
+
+ if (theme?.remote_url) {
+ try {
+ const result = await ajax("/admin/themes/import", {
+ type: "POST",
+ data: { remote: theme.remote_url },
+ });
+ if (!this.active) {
+ this.applyingTheme = false;
+ return;
+ }
+ themeId = result.theme.id;
+ this.themeId = themeId;
+ } catch (error) {
+ this.themeId = previousThemeId;
+ this.applyingTheme = false;
+ popupAjaxError(error);
+ return;
+ }
+ }
// these are resolved per theme, so let the reloaded page re-seed them from
// the theme being previewed rather than carrying the old theme's values
this.welcomeBanner = undefined;
@@ -349,17 +400,23 @@ export default class DesignWizardService extends Service {
selectHomepage(homepage) {
this.homepage = homepage;
+ const additionalHomepage = this.additionalHomepages.find(
+ ({ id }) => id === homepage
+ );
+ this.homepageSettings = {
+ ...this.#originalHomepageSettings,
+ ...additionalHomepage?.settings,
+ };
if (homepage === "categories") {
this.categoryPageStyle = "categories_boxes";
this.siteSettings.desktop_category_page_style = this.categoryPageStyle;
}
this.#persistState();
- // the page behind the sheet is the preview: show the chosen homepage.
- // Explicit routes, because "/" resolves to the currently saved default
- // homepage, and a router transition (unlike DiscourseURL.routeTo) can
- // never escalate to a full page load, which would dismiss the sheet
- this.router.transitionTo(`discovery.${homepage}`);
+ // An explicit destination previews unsaved choices without reloading the wizard.
+ this.router.transitionTo(
+ additionalHomepage?.path ?? `discovery.${homepage}`
+ );
}
selectCategoryPageStyle(value) {
@@ -529,6 +586,7 @@ export default class DesignWizardService extends Service {
this.showIntro = false;
this.#snapshot = undefined;
this.#originalSiteSettings = undefined;
+ this.#originalHomepageSettings = undefined;
}
// captured before anything is previewed or saved, from the values the server
@@ -550,13 +608,20 @@ export default class DesignWizardService extends Service {
heading_font: this.data.heading_font,
// a homepage the wizard cannot express is left alone rather than replaced
// with the one it fell back to
- homepage: SUPPORTED_HOMEPAGES.includes(this.data.homepage)
+ homepage: this.#supportedHomepages.includes(this.data.homepage)
? this.data.homepage
: null,
+ homepage_settings: this.data.homepage_settings,
category_page_style: settings.desktop_category_page_style,
- enable_welcome_banner: settings.enable_welcome_banner,
welcome_banner_location: settings.welcome_banner_location,
- search_experience: settings.search_experience,
+ ...(currentTheme.supports_welcome_banner !== false
+ ? {
+ enable_welcome_banner: settings.enable_welcome_banner,
+ }
+ : {}),
+ ...(currentTheme.supports_search !== false
+ ? { search_experience: settings.search_experience }
+ : {}),
};
}
@@ -577,6 +642,8 @@ export default class DesignWizardService extends Service {
this.headingFont = this.data.heading_font;
this.colorMode = renderedColorMode();
this.homepage = this.#supportedHomepage(this.data.homepage);
+ this.#originalHomepageSettings = this.data.homepage_settings ?? {};
+ this.homepageSettings = this.#originalHomepageSettings;
this.categoryPageStyle = this.siteSettings.desktop_category_page_style;
this.welcomeBanner = this.siteSettings.enable_welcome_banner;
this.welcomeBannerLocation = this.siteSettings.welcome_banner_location;
@@ -589,6 +656,11 @@ export default class DesignWizardService extends Service {
this.returnUrl = stored.returnUrl;
this.progressSaved = stored.progressSaved ?? false;
this.#snapshot = stored.snapshot;
+ this.#originalHomepageSettings =
+ stored.originalHomepageSettings ??
+ stored.snapshot?.homepage_settings ??
+ this.data.homepage_settings ??
+ {};
// the intro is only ever shown once, before the first selection
this.showIntro = false;
this.themeId = stored.themeId;
@@ -599,6 +671,8 @@ export default class DesignWizardService extends Service {
this.headingFont = stored.headingFont;
this.homepage =
stored.homepage ?? this.#supportedHomepage(this.data.homepage);
+ this.homepageSettings =
+ stored.homepageSettings ?? this.data.homepage_settings ?? {};
this.categoryPageStyle =
stored.categoryPageStyle ?? this.siteSettings.desktop_category_page_style;
this.welcomeBanner =
@@ -623,6 +697,8 @@ export default class DesignWizardService extends Service {
bodyFont: this.bodyFont,
headingFont: this.headingFont,
homepage: this.homepage,
+ homepageSettings: this.homepageSettings,
+ originalHomepageSettings: this.#originalHomepageSettings,
categoryPageStyle: this.categoryPageStyle,
welcomeBanner: this.welcomeBanner,
welcomeBannerLocation: this.welcomeBannerLocation,
@@ -641,9 +717,13 @@ export default class DesignWizardService extends Service {
if (this.homepage === "categories") {
this.siteSettings.desktop_category_page_style = this.categoryPageStyle;
}
- this.siteSettings.enable_welcome_banner = this.welcomeBanner;
- this.siteSettings.welcome_banner_location = this.welcomeBannerLocation;
- this.siteSettings.search_experience = this.searchExperience;
+ if (this.supportsWelcomeBanner) {
+ this.siteSettings.enable_welcome_banner = this.welcomeBanner;
+ this.siteSettings.welcome_banner_location = this.welcomeBannerLocation;
+ }
+ if (this.supportsSearch) {
+ this.siteSettings.search_experience = this.searchExperience;
+ }
}
#refreshCategoriesPage() {
@@ -659,7 +739,7 @@ export default class DesignWizardService extends Service {
}
#supportedHomepage(homepage) {
- return SUPPORTED_HOMEPAGES.includes(homepage) ? homepage : "latest";
+ return this.#supportedHomepages.includes(homepage) ? homepage : "latest";
}
#currentPairKey(theme) {
diff --git a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
index a79626cc231..4903ee68d8c 100644
--- a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
+++ b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
@@ -5,6 +5,7 @@ import { test } from "qunit";
import StartPostingOption from "discourse/components/admin-onboarding/start-posting-option";
import { AUTO_GROUPS } from "discourse/lib/constants";
import { withPluginApi } from "discourse/lib/plugin-api";
+import { setDefaultHomepage } from "discourse/lib/utilities";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
@@ -794,3 +795,25 @@ acceptance("Admin - Onboarding Banner - setting disabled", function (needs) {
.doesNotExist("does not show onboarding banner");
});
});
+
+acceptance("Admin - Onboarding Banner - registered homepage", function (needs) {
+ needs.user({ admin: true, show_site_owner_onboarding: true });
+ needs.settings({ enable_site_owner_onboarding: true });
+ needs.site({
+ homepage_options: [{ id: "custom", path: "/tags", server_side: false }],
+ });
+
+ test("shows the checklist on a registered homepage and hides it elsewhere", async function (assert) {
+ await visit("/latest");
+ setDefaultHomepage("custom");
+ await visit("/tags");
+
+ assert
+ .dom(".admin-onboarding-banner")
+ .exists("shows onboarding outside discovery routes");
+ await visit("/categories");
+ assert
+ .dom(".admin-onboarding-banner")
+ .doesNotExist("keeps onboarding off other pages");
+ });
+});
diff --git a/frontend/discourse/tests/acceptance/design-wizard-test.gjs b/frontend/discourse/tests/acceptance/design-wizard-test.gjs
index 09c65b533a0..fbefa6c7e1d 100644
--- a/frontend/discourse/tests/acceptance/design-wizard-test.gjs
+++ b/frontend/discourse/tests/acceptance/design-wizard-test.gjs
@@ -56,6 +56,9 @@ const designWizardData = () => ({
acceptance("Design wizard - admin launch", function (needs) {
let savedPayloads = [];
+ let wizardData;
+ let importRequests;
+ let importFails;
needs.user({
admin: true,
@@ -65,6 +68,9 @@ acceptance("Design wizard - admin launch", function (needs) {
needs.hooks.beforeEach(function () {
savedPayloads = [];
+ wizardData = designWizardData();
+ importRequests = [];
+ importFails = false;
this.originalSchemeLinks = captureColorSchemeLinks();
});
@@ -77,9 +83,16 @@ acceptance("Design wizard - admin launch", function (needs) {
needs.pretender((server, helper) => {
server.get("/admin/config/design-wizard.json", () =>
- helper.response(200, designWizardData())
+ helper.response(200, wizardData)
);
+ server.post("/admin/themes/import", (request) => {
+ importRequests.push(helper.parsePostData(request.requestBody));
+ return importFails
+ ? helper.response(422, { errors: ["Unable to install theme"] })
+ : helper.response(201, { theme: { id: 42, name: "Concord" } });
+ });
+
server.put("/admin/config/design-wizard.json", (request) => {
savedPayloads.push(helper.parsePostData(request.requestBody));
return helper.response(200, { success: "OK" });
@@ -104,6 +117,306 @@ acceptance("Design wizard - admin launch", function (needs) {
);
});
+ test("installs a remote theme before navigating to its preview", async function (assert) {
+ const remoteUrl = "https://github.com/discourse/discourse-concord-theme";
+ wizardData.themes.push({
+ id: "concord",
+ name: "Concord",
+ remote_url: remoteUrl,
+ palette_pairs: [],
+ });
+ const redirect = sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click('[data-theme-id="concord"] input');
+
+ assert.deepEqual(
+ importRequests,
+ [{ remote: remoteUrl }],
+ "imports the offered repository once"
+ );
+ assert.true(
+ redirect.calledWith("/?preview_theme_id=42"),
+ "previews the installed theme ID"
+ );
+ const stored = JSON.parse(
+ this.owner
+ .lookup("service:key-value-store")
+ .get("design_wizard_panel_state")
+ );
+ assert.strictEqual(
+ stored.themeId,
+ 42,
+ "the installed ID survives the preview reload"
+ );
+ await click(".design-wizard__close");
+ });
+
+ test("a failed theme install restores the selection and allows retrying", async function (assert) {
+ wizardData.themes.push({
+ id: "concord",
+ name: "Concord",
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ palette_pairs: [],
+ });
+ importFails = true;
+ const redirect = sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click('[data-theme-id="concord"] input');
+
+ assert
+ .dom(".dialog-body")
+ .includesText("Unable to install theme", "shows the installation error");
+ assert
+ .dom('[data-theme-id="-1"] input')
+ .isChecked("restores the previous selection");
+ assert
+ .dom('[data-theme-id="concord"] input')
+ .isNotDisabled("allows another attempt");
+ assert.false(redirect.called, "does not navigate to a missing theme");
+
+ await click(".dialog-footer .btn-primary");
+ importFails = false;
+ await click('[data-theme-id="concord"] input');
+ assert.true(
+ redirect.calledWith("/?preview_theme_id=42"),
+ "a successful retry opens the preview"
+ );
+ await click(".design-wizard__close");
+ });
+
+ test("previews and saves an additional homepage without a destination picker", async function (assert) {
+ wizardData.additional_homepages = [
+ {
+ id: "chat",
+ name: "Chat",
+ description:
+ "Open the General channel when members visit your homepage.",
+ icon: "comments",
+ illustration: "conversation",
+ settings: { chat_homepage_channel: "12" },
+ path: "/categories",
+ },
+ ];
+ const redirect = sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+ assert
+ .dom('[data-homepage="chat"] .design-wizard__mock-message')
+ .exists({ count: 3 });
+ assert.dom('[data-homepage="chat"] .design-wizard__mock-composer').exists();
+ await click('[data-homepage="chat"]');
+
+ assert.strictEqual(
+ currentURL(),
+ "/categories",
+ "previews the path provided by the server"
+ );
+ assert
+ .dom('[data-homepage="chat"]')
+ .hasAttribute("aria-pressed", "true", "selects Chat");
+ assert
+ .dom('[data-homepage="topics"]')
+ .hasAttribute("aria-pressed", "false", "clears the topic selection");
+ assert
+ .dom(".design-wizard__detail-group")
+ .includesText("General", "explains the fixed destination");
+ assert.dom("[data-topic-page]").doesNotExist("hides topic list choices");
+ assert
+ .dom(".design-wizard__detail-group select")
+ .doesNotExist("does not offer a channel picker");
+ await click(".design-wizard__save");
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage,
+ "chat",
+ "saves the registered homepage"
+ );
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "12",
+ "uses the General channel provided by the server"
+ );
+ assert.true(redirect.called, "finishes the wizard");
+ });
+
+ test("omits unsupported welcome and search choices", async function (assert) {
+ wizardData.themes[0].supports_welcome_banner = false;
+ wizardData.themes[0].supports_search = false;
+ sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+
+ assert.dom(".design-wizard__sections").doesNotIncludeText("Welcome banner");
+ assert.dom(".design-wizard__sections").doesNotIncludeText("Search");
+ await click(".design-wizard__save");
+ for (const key of [
+ "enable_welcome_banner",
+ "welcome_banner_location",
+ "search_experience",
+ ]) {
+ assert.false(key in savedPayloads.at(-1), `${key} is not saved`);
+ }
+ });
+
+ ["chat", "latest"].forEach((homepage) => {
+ test(`preserves and restores the chat destination from ${homepage}`, async function (assert) {
+ wizardData.homepage = homepage;
+ wizardData.homepage_settings = { chat_homepage_channel: "23" };
+ wizardData.additional_homepages = [
+ {
+ id: "chat",
+ name: "Chat",
+ path: "/categories",
+ settings: { chat_homepage_channel: "12" },
+ },
+ ];
+ sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click(".design-wizard__next");
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "23",
+ "Next preserves the existing channel"
+ );
+ await click(".design-wizard__next");
+ await click('[data-homepage="chat"]');
+ const wizard = this.owner.lookup("service:design-wizard");
+ await wizard.saveProgress();
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "12",
+ "explicitly selecting Chat chooses General"
+ );
+
+ await wizard.start({ resuming: true });
+ await wizard.saveProgress();
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "12",
+ "the selection survives a preview reload"
+ );
+ await click(".design-wizard__close");
+ await click(".dialog-footer .btn-danger");
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage,
+ homepage,
+ "reverts the original homepage"
+ );
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "23",
+ "reverts the original channel after resuming"
+ );
+ });
+ });
+
+ ["topics", "categories"].forEach((choice) => {
+ [false, true].forEach((resume) => {
+ test(`switching from Chat to ${choice} preserves the original channel${resume ? " after a preview reload" : ""}`, async function (assert) {
+ wizardData.homepage_settings = { chat_homepage_channel: "23" };
+ wizardData.additional_homepages = [
+ {
+ id: "chat",
+ name: "Chat",
+ path: "/categories",
+ settings: { chat_homepage_channel: "12" },
+ },
+ ];
+ sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+ await click('[data-homepage="chat"]');
+
+ if (resume) {
+ const wizard = this.owner.lookup("service:design-wizard");
+ await wizard.saveProgress();
+ wizardData.homepage = "chat";
+ wizardData.homepage_settings = { chat_homepage_channel: "12" };
+ await wizard.start({ resuming: true });
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+ }
+
+ await click(`[data-homepage="${choice}"]`);
+ await click(".design-wizard__save");
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage,
+ choice === "topics" ? "latest" : "categories",
+ "saves the selected forum homepage"
+ );
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings.chat_homepage_channel,
+ "23",
+ "restores the channel configured before the wizard started"
+ );
+ });
+ });
+ });
+
+ test("reverts the welcome banner location after switching from Concord", async function (assert) {
+ wizardData.themes[0].default = false;
+ wizardData.themes.push({
+ id: 42,
+ name: "Concord",
+ default: true,
+ supports_welcome_banner: false,
+ supports_search: false,
+ palette_pairs: [],
+ });
+ this.siteSettings.welcome_banner_location = "top_menu";
+ sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+ await click('[data-theme-id="-1"] input');
+ const wizard = this.owner.lookup("service:design-wizard");
+ await wizard.start({ resuming: true });
+ wizard.applyingTheme = false;
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+ wizard.selectWelcomeBannerLocation("all");
+ await click(".design-wizard__back");
+ await click(".design-wizard__next");
+ assert.strictEqual(
+ savedPayloads.at(-1).welcome_banner_location,
+ "all",
+ "saves the changed site-wide location"
+ );
+ await click(".design-wizard__close");
+ await click(".dialog-footer .btn-danger");
+ assert.strictEqual(
+ savedPayloads.at(-1).theme_id,
+ "42",
+ "reverts to Concord"
+ );
+ assert.strictEqual(
+ savedPayloads.at(-1).welcome_banner_location,
+ "top_menu",
+ "restores the original site-wide location"
+ );
+ });
+
test("the appearance section launches the wizard on the forum", async function (assert) {
await visit("/admin");
diff --git a/frontend/discourse/tests/integration/components/design-wizard-sections-test.gjs b/frontend/discourse/tests/integration/components/design-wizard-sections-test.gjs
index c6a180850a8..61ead83eae1 100644
--- a/frontend/discourse/tests/integration/components/design-wizard-sections-test.gjs
+++ b/frontend/discourse/tests/integration/components/design-wizard-sections-test.gjs
@@ -77,9 +77,14 @@ module(
.dom(
".design-wizard__theme-card[data-theme-id='-2'] .design-wizard__theme-screenshot"
)
- .doesNotHaveClass(
- "--loading",
- "does not leave a skeleton running for a theme with no screenshot"
+ .doesNotExist(
+ "does not render an empty screenshot for a theme without one"
+ );
+ assert
+ .dom(".design-wizard__theme-card[data-theme-id='-2']")
+ .hasClass(
+ "--without-screenshot",
+ "uses a compact card without a screenshot"
);
});
diff --git a/lib/design_wizard/homepages.rb b/lib/design_wizard/homepages.rb
new file mode 100644
index 00000000000..fc0ecf1a8f6
--- /dev/null
+++ b/lib/design_wizard/homepages.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module DesignWizard
+ class Homepages
+ def self.additional_options
+ return [] if !SiteSetting.concord_in_wizard
+
+ DiscoursePluginRegistry.apply_modifier(:design_wizard_homepages, [])
+ end
+
+ def self.ids
+ %w[latest new hot categories] + additional_options.map { |option| option[:id] }
+ end
+
+ def self.current_settings
+ additional_options
+ .flat_map { |option| option.fetch(:settings, {}).keys }
+ .uniq
+ .index_with { |name| SiteSetting.public_send(name) }
+ end
+
+ def self.settings_for(id, overrides: {})
+ defaults = additional_options.find { |option| option[:id] == id }&.fetch(:settings, {}) || {}
+ defaults = {} if id == SiteSetting.homepage
+ defaults.merge(overrides)
+ end
+ end
+end
diff --git a/lib/design_wizard/themes.rb b/lib/design_wizard/themes.rb
new file mode 100644
index 00000000000..06c45ecdf2e
--- /dev/null
+++ b/lib/design_wizard/themes.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module DesignWizard
+ class Themes
+ CONCORD = {
+ name: "Concord",
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ supports_welcome_banner: false,
+ supports_search: false,
+ screenshot_light_url: "/images/design-wizard/concord-light.jpg",
+ screenshot_dark_url: "/images/design-wizard/concord-dark.jpg",
+ }.freeze
+
+ def self.selectable
+ Theme.where(id: Theme::CORE_THEMES.values).or(installed_concord)
+ end
+
+ def self.ids
+ Theme::CORE_THEMES.values + installed_concord.pluck(:id)
+ end
+
+ def self.available_to_install(themes, guardian:)
+ return [] if !SiteSetting.concord_in_wizard || !guardian.can_create_theme?
+ return [] if !guardian.allowed_theme_repo_import?(CONCORD[:remote_url])
+ return [] if themes.any? { |theme| definition_for(theme) }
+
+ [
+ CONCORD.merge(
+ screenshot_light_url: Discourse.base_path + CONCORD[:screenshot_light_url],
+ screenshot_dark_url: Discourse.base_path + CONCORD[:screenshot_dark_url],
+ id: "concord",
+ description: I18n.t("design_wizard.themes.concord.description"),
+ palette_pairs: [],
+ ),
+ ]
+ end
+
+ def self.definition_for(theme)
+ return if !SiteSetting.concord_in_wizard
+
+ CONCORD if theme.remote_theme&.remote_url&.delete_suffix(".git") == CONCORD[:remote_url]
+ end
+
+ def self.installed_concord
+ return Theme.none if !SiteSetting.concord_in_wizard
+
+ Theme.where(
+ component: false,
+ remote_theme_id:
+ RemoteTheme.where(
+ remote_url: [CONCORD[:remote_url], "#{CONCORD[:remote_url]}.git"],
+ ).select(:id),
+ )
+ end
+ private_class_method :installed_concord
+ end
+end
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat.js b/plugins/chat/assets/javascripts/discourse/routes/chat.js
index 599e1afa28a..c46cda4769c 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat.js
@@ -19,6 +19,7 @@ export default class ChatRoute extends DiscourseRoute {
@service chatStateManager;
@service chatDrawerRouter;
@service currentUser;
+ @service designWizard;
@service siteSettings;
titleToken() {
@@ -56,6 +57,7 @@ export default class ChatRoute extends DiscourseRoute {
isDrawerPreferred &&
canHandleInDrawer &&
!isHomepageTransition(transition) &&
+ !(this.designWizard.active && this.designWizard.homepage === "chat") &&
(!fullPageReload || requiresRefresh)
) {
transition.abort();
diff --git a/plugins/chat/assets/stylesheets/common/base-common.scss b/plugins/chat/assets/stylesheets/common/base-common.scss
index e735f0478f3..4bb4f52777f 100644
--- a/plugins/chat/assets/stylesheets/common/base-common.scss
+++ b/plugins/chat/assets/stylesheets/common/base-common.scss
@@ -209,6 +209,7 @@ body.has-full-page-chat {
}
.full-page-chat {
+ --chat-content-offset: var(--admin-onboarding-banner-height, 0px);
display: grid;
grid-template-columns: var(--full-page-sidebar-width) 1fr;
background: var(--d-content-background);
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel.scss b/plugins/chat/assets/stylesheets/common/chat-channel.scss
index 044139bbe38..41b087b4847 100644
--- a/plugins/chat/assets/stylesheets/common/chat-channel.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-channel.scss
@@ -16,7 +16,7 @@
@include viewport.from(xl) {
height: calc(
var(--composer-vh, 1vh) * 100 - var(--main-outlet-offset, 0px) -
- 1px - var(--chat-header-offset, 0)
+ 1px - var(--chat-header-offset, 0) - var(--chat-content-offset, 0px)
);
}
}
diff --git a/plugins/chat/assets/stylesheets/common/chat-height-mixin.scss b/plugins/chat/assets/stylesheets/common/chat-height-mixin.scss
index 650dcbe3c61..c26a9b2e412 100644
--- a/plugins/chat/assets/stylesheets/common/chat-height-mixin.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-height-mixin.scss
@@ -3,7 +3,7 @@
// -1px is for the bottom border of the chat navbar
$base-height: calc(
var(--composer-vh, 1vh) * 100 - var(--main-outlet-offset, 0px) - 1px -
- $inset - var(--composer-height, 0px)
+ $inset - var(--composer-height, 0px) - var(--chat-content-offset, 0px)
);
height: calc($base-height);
diff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.yml
index e9ac6b54099..a6cf55e2b0f 100644
--- a/plugins/chat/config/locales/server.en.yml
+++ b/plugins/chat/config/locales/server.en.yml
@@ -58,6 +58,8 @@ en:
Visit the channel at %{channel_url} to retry.
chat:
+ design_wizard_homepage_name: "Chat"
+ design_wizard_homepage_description: "Open the %{channel} channel when members visit your homepage."
deleted_chat_username: deleted
crawler:
directory_title: "Chat channels"
diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb
index 4c71c2f307f..b3e7e49f393 100644
--- a/plugins/chat/plugin.rb
+++ b/plugins/chat/plugin.rb
@@ -444,6 +444,28 @@ after_initialize do
homepage_channel = -> { Chat::Channel.find_by(id: SiteSetting.chat_homepage_channel.presence) }
+ register_modifier(:design_wizard_homepages) do |options|
+ next options if !SiteSetting.enable_public_channels
+
+ channel = Chat::CategoryChannel.find_by(chatable_id: SiteSetting.general_category_id)
+ next options if !channel || channel.archived? || channel.read_restricted?
+
+ options +
+ [
+ {
+ id: "chat",
+ name: I18n.t("chat.design_wizard_homepage_name"),
+ description: I18n.t("chat.design_wizard_homepage_description", channel: channel.title),
+ icon: "comments",
+ illustration: "conversation",
+ path: channel.relative_url.delete_prefix(Discourse.base_path),
+ settings: {
+ chat_homepage_channel: channel.id.to_s,
+ },
+ },
+ ]
+ end
+
register_homepage(
"chat",
name: "chat.homepage_option",
diff --git a/plugins/chat/spec/requests/design_wizard_controller_spec.rb b/plugins/chat/spec/requests/design_wizard_controller_spec.rb
new file mode 100644
index 00000000000..b6b772f3e08
--- /dev/null
+++ b/plugins/chat/spec/requests/design_wizard_controller_spec.rb
@@ -0,0 +1,273 @@
+# frozen_string_literal: true
+
+RSpec.describe Admin::Config::DesignWizardController do
+ fab!(:admin)
+ fab!(:general_category, :category)
+ fab!(:general_channel) do
+ Fabricate(:category_channel, chatable: general_category, name: "General")
+ end
+ fab!(:other_channel) { Fabricate(:category_channel, name: "General") }
+
+ before do
+ SiteSetting.concord_in_wizard = true
+ SiteSetting.chat_enabled = true
+ SiteSetting.enable_public_channels = true
+ SiteSetting.general_category_id = general_category.id
+ end
+
+ describe "#index" do
+ before { sign_in(admin) }
+
+ it "offers General defaults and the current channel settings for a forum homepage" do
+ SiteSetting.default_homepage = "categories"
+ SiteSetting.chat_homepage_channel = other_channel.id
+ get "/admin/config/design-wizard.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["additional_homepages"]).to eq(
+ [
+ {
+ "id" => "chat",
+ "name" => I18n.t("chat.design_wizard_homepage_name"),
+ "description" =>
+ I18n.t("chat.design_wizard_homepage_description", channel: general_channel.title),
+ "icon" => "comments",
+ "illustration" => "conversation",
+ "path" => general_channel.relative_url,
+ "settings" => {
+ "chat_homepage_channel" => general_channel.id.to_s,
+ },
+ },
+ ],
+ )
+ expect(response.parsed_body["homepage_settings"]).to eq(
+ "chat_homepage_channel" => other_channel.id.to_s,
+ )
+ end
+
+ it "returns the configured channel settings for a Chat homepage" do
+ SiteSetting.default_homepage = "chat"
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["homepage_settings"]).to eq(
+ "chat_homepage_channel" => other_channel.id.to_s,
+ )
+ end
+
+ it "omits the subfolder from the homepage path" do
+ set_subfolder "/forum"
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"].sole["path"]).to eq(
+ "/chat/c/#{general_channel.slug}/#{general_channel.id}",
+ )
+ end
+
+ it "does not substitute another channel named General when the General category has no channel" do
+ general_channel.destroy!
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+
+ it "hides chat when the wizard setting is disabled" do
+ SiteSetting.concord_in_wizard = false
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+
+ it "hides chat when public channels are disabled" do
+ SiteSetting.enable_public_channels = false
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+
+ it "hides chat when the General category is private" do
+ general_category.update!(read_restricted: true)
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+
+ it "hides chat when the General channel is archived" do
+ general_channel.update!(status: :archived)
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+
+ it "hides chat when chat is disabled" do
+ SiteSetting.chat_enabled = false
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["additional_homepages"]).to eq([])
+ end
+ end
+
+ describe "#update" do
+ let(:params) { { theme_id: Theme::CORE_THEMES["foundation"], homepage: "chat" } }
+
+ before { sign_in(admin) }
+
+ it "selects the General channel regardless of a supplied channel ID and keeps Foundation" do
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ put "/admin/config/design-wizard.json",
+ params: params.merge(chat_homepage_channel: other_channel.id)
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.default_homepage).to eq("chat")
+ expect(SiteSetting.chat_homepage_channel).to eq(general_channel.id.to_s)
+ expect(SiteSetting.default_theme_id).to eq(Theme::CORE_THEMES["foundation"])
+ end
+
+ it "preserves the configured channel when choosing a forum homepage" do
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ put "/admin/config/design-wizard.json", params: params.merge(homepage: "categories")
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.default_homepage).to eq("categories")
+ expect(SiteSetting.chat_homepage_channel).to eq(other_channel.id.to_s)
+ end
+
+ it "preserves the current Chat channel when saving the next wizard step" do
+ SiteSetting.default_homepage = "chat"
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ put "/admin/config/design-wizard.json", params: params.merge(base_font: "lato")
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.chat_homepage_channel).to eq(other_channel.id.to_s)
+ expect(SiteSetting.base_font).to eq("lato")
+ end
+
+ it "selects General when explicitly requested while Chat is already the homepage" do
+ SiteSetting.default_homepage = "chat"
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ put "/admin/config/design-wizard.json",
+ params:
+ params.merge(homepage_settings: { chat_homepage_channel: general_channel.id.to_s })
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.chat_homepage_channel).to eq(general_channel.id.to_s)
+ end
+
+ %w[chat categories].each do |original_homepage|
+ it "restores the original #{original_homepage} homepage and channel settings after a preview" do
+ SiteSetting.default_homepage = original_homepage
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ get "/admin/config/design-wizard.json"
+ snapshot = response.parsed_body.slice("homepage", "homepage_settings")
+
+ put "/admin/config/design-wizard.json",
+ params:
+ params.merge(homepage_settings: { chat_homepage_channel: general_channel.id.to_s })
+ expect(response.status).to eq(200)
+ expect(SiteSetting.chat_homepage_channel).to eq(general_channel.id.to_s)
+
+ put "/admin/config/design-wizard.json",
+ params: snapshot.merge("theme_id" => Theme::CORE_THEMES["foundation"])
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.default_homepage).to eq(original_homepage)
+ expect(SiteSetting.chat_homepage_channel).to eq(other_channel.id.to_s)
+ end
+ end
+
+ it "rejects settings that are not registered homepage settings" do
+ put "/admin/config/design-wizard.json",
+ params: params.merge(homepage_settings: { title: "Unexpected title" })
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"]).to be_present
+ end
+
+ it "rejects an unavailable channel without changing homepage settings" do
+ SiteSetting.chat_homepage_channel = other_channel.id
+
+ expect do
+ put "/admin/config/design-wizard.json",
+ params: params.merge(homepage_settings: { chat_homepage_channel: "999999" })
+ end.not_to change { [SiteSetting.default_homepage, SiteSetting.chat_homepage_channel] }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"]).to be_present
+ end
+
+ it "rejects channel overrides when the wizard setting is disabled" do
+ SiteSetting.concord_in_wizard = false
+
+ put "/admin/config/design-wizard.json",
+ params:
+ params.merge(
+ homepage: "categories",
+ homepage_settings: {
+ chat_homepage_channel: general_channel.id.to_s,
+ },
+ )
+
+ expect(response.status).to eq(400)
+ end
+
+ shared_examples "an unavailable chat homepage" do
+ it "rejects the selection without updating homepage settings" do
+ expect do put "/admin/config/design-wizard.json", params: end.not_to change {
+ [SiteSetting.default_homepage, SiteSetting.chat_homepage_channel]
+ }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"]).to be_present
+ end
+ end
+
+ context "when the wizard setting is disabled" do
+ before { SiteSetting.concord_in_wizard = false }
+
+ include_examples "an unavailable chat homepage"
+ end
+
+ context "when public channels are disabled" do
+ before { SiteSetting.enable_public_channels = false }
+
+ include_examples "an unavailable chat homepage"
+ end
+
+ context "when chat is disabled" do
+ before { SiteSetting.chat_enabled = false }
+
+ include_examples "an unavailable chat homepage"
+ end
+
+ context "when the General category is private" do
+ before { general_category.update!(read_restricted: true) }
+
+ include_examples "an unavailable chat homepage"
+ end
+
+ context "when the General channel is archived" do
+ before { general_channel.update!(status: :archived) }
+
+ include_examples "an unavailable chat homepage"
+ end
+
+ context "when the General category has no channel" do
+ before { general_channel.destroy! }
+
+ include_examples "an unavailable chat homepage"
+ end
+ end
+end
diff --git a/plugins/chat/spec/system/homepage_channel_spec.rb b/plugins/chat/spec/system/homepage_channel_spec.rb
index 714e94dfcd5..a75173cb11a 100644
--- a/plugins/chat/spec/system/homepage_channel_spec.rb
+++ b/plugins/chat/spec/system/homepage_channel_spec.rb
@@ -68,6 +68,55 @@ RSpec.describe "Chat channel as the homepage" do
expect(page).to have_no_css(".chat-channel")
end
+ context "when the site owner is onboarding" do
+ fab!(:current_user, :admin)
+ fab!(:other_channel, :category_channel)
+ fab!(:other_message) { Fabricate(:chat_message, chat_channel: other_channel) }
+
+ let(:banner) { PageObjects::Components::AdminOnboardingBanner.new }
+ let(:sidebar) { PageObjects::Pages::ChatSidebar.new }
+
+ before do
+ SiteSetting.enable_site_owner_onboarding = true
+ Theme.foundation_theme.set_default!
+ channel_1.add(current_user)
+ other_channel.add(current_user)
+ end
+
+ it "lets the owner see the checklist on the Chat homepage but not another channel" do
+ visit("/")
+
+ expect(channel_page.messages).to have_message(id: message_1.id)
+ expect(banner).to be_visible
+ expect_composer_in_viewport
+
+ click_button(I18n.t("js.admin_onboarding_banner.collapse"), enable_aria_label: true)
+ expect_composer_in_viewport
+
+ visit(channel_1.relative_url)
+
+ expect(channel_page.messages).to have_message(id: message_1.id)
+ expect(banner).to be_visible
+ expect_composer_in_viewport
+
+ sidebar.open_channel(other_channel)
+
+ expect(channel_page.messages).to have_message(id: other_message.id)
+ expect(banner).to be_not_visible
+ expect_composer_in_viewport
+ end
+
+ def expect_composer_in_viewport
+ try_until_success do
+ bottom =
+ channel_page.composer.component.evaluate_script("this.getBoundingClientRect().bottom")
+ viewport_height = page.evaluate_script("window.innerHeight")
+ expect(bottom).to be <= viewport_height
+ expect(bottom).to be >= viewport_height - 20
+ end
+ end
+ end
+
context "when on mobile", mobile: true do
it "links back to the forum rather than the homepage" do
visit("/")
diff --git a/plugins/chat/test/javascripts/unit/routes/chat-design-wizard-test.js b/plugins/chat/test/javascripts/unit/routes/chat-design-wizard-test.js
new file mode 100644
index 00000000000..f1f09eb50aa
--- /dev/null
+++ b/plugins/chat/test/javascripts/unit/routes/chat-design-wizard-test.js
@@ -0,0 +1,55 @@
+import { setupTest } from "ember-qunit";
+import { module, test } from "qunit";
+import sinon from "sinon";
+
+module("Unit | Routes | chat | design-wizard", function (hooks) {
+ setupTest(hooks);
+
+ test("previews the chat homepage full page while preserving the drawer preference", function (assert) {
+ const route = this.owner.lookup("route:chat");
+ const sandbox = sinon.createSandbox();
+
+ try {
+ sandbox.stub(route.chat, "chatDisabledInPreferences").get(() => false);
+ sandbox.stub(route.chat, "userCanChat").get(() => true);
+ sandbox.stub(route.chatStateManager, "isDrawerPreferred").get(() => true);
+ sandbox.stub(route.chatDrawerRouter, "canHandleRoute").returns(true);
+ const trigger = sandbox.stub(route.appEvents, "trigger");
+ const transition = {
+ to: { name: "chat.channel" },
+ from: { name: "discovery.latest" },
+ targetName: "chat.channel",
+ intent: { url: "/chat/c/general/1" },
+ abort: sandbox.stub(),
+ };
+
+ route.designWizard.active = true;
+ route.designWizard.homepage = "chat";
+ route.beforeModel(transition);
+
+ assert.false(
+ transition.abort.called,
+ "allows the full page transition during preview"
+ );
+ assert.true(
+ trigger.calledWith("chat:toggle-close"),
+ "closes any existing drawer"
+ );
+
+ route.designWizard.active = false;
+ trigger.resetHistory();
+ route.beforeModel(transition);
+
+ assert.true(
+ transition.abort.calledOnce,
+ "normal navigation still uses the drawer"
+ );
+ assert.true(
+ trigger.calledWith("chat:open-url", "/chat/c/general/1"),
+ "opens the requested channel in the drawer"
+ );
+ } finally {
+ sandbox.restore();
+ }
+ });
+});
diff --git a/public/images/design-wizard/concord-dark.jpg b/public/images/design-wizard/concord-dark.jpg
new file mode 100644
index 00000000000..735cc5b20a1
Binary files /dev/null and b/public/images/design-wizard/concord-dark.jpg differ
diff --git a/public/images/design-wizard/concord-light.jpg b/public/images/design-wizard/concord-light.jpg
new file mode 100644
index 00000000000..d6dcfcf1795
Binary files /dev/null and b/public/images/design-wizard/concord-light.jpg differ
diff --git a/spec/requests/admin/config/design_wizard_controller_spec.rb b/spec/requests/admin/config/design_wizard_controller_spec.rb
index 15721d0d82d..042abe7a9b3 100644
--- a/spec/requests/admin/config/design_wizard_controller_spec.rb
+++ b/spec/requests/admin/config/design_wizard_controller_spec.rb
@@ -34,6 +34,7 @@ RSpec.describe Admin::Config::DesignWizardController do
horizon = themes.find { |theme| theme["id"] == Theme::CORE_THEMES["horizon"] }
expect(horizon["description"]).to eq("A simple, beautiful theme")
+ expect(horizon).to include("supports_welcome_banner" => true, "supports_search" => true)
expect(horizon["palette_pairs"].map { |pair| pair["key"] }).to include(
"horizon",
"royal",
@@ -55,6 +56,139 @@ RSpec.describe Admin::Config::DesignWizardController do
expect(dracula["light"]).to be_nil
end
+ it "excludes installed Concord from the choices by default" do
+ concord =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+ concord.set_default!
+
+ get "/admin/config/design-wizard.json"
+
+ expect(SiteSetting.concord_in_wizard).to eq(false)
+ expect(response.parsed_body["themes"].map { |theme| theme["id"] }).to contain_exactly(
+ *Theme::CORE_THEMES.values,
+ )
+ expect(response.parsed_body["current_theme"]).to include("id" => concord.id)
+ end
+
+ it "offers Concord for installation without creating a theme" do
+ SiteSetting.concord_in_wizard = true
+ expect { get "/admin/config/design-wizard.json" }.not_to change { Theme.count }
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["themes"].find { |theme| theme["id"] == "concord" }).to include(
+ "name" => "Concord",
+ "remote_url" => "https://github.com/discourse/discourse-concord-theme",
+ "description" => I18n.t("design_wizard.themes.concord.description"),
+ "palette_pairs" => [],
+ "supports_welcome_banner" => false,
+ "supports_search" => false,
+ "screenshot_light_url" => "/images/design-wizard/concord-light.jpg",
+ "screenshot_dark_url" => "/images/design-wizard/concord-dark.jpg",
+ )
+ end
+
+ it "limits choices to core themes and Concord when other themes are installed" do
+ SiteSetting.concord_in_wizard = true
+ Fabricate(:theme, name: "Concord")
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(:remote_theme, remote_url: "https://github.com/discourse/other-theme"),
+ )
+ Fabricate(
+ :theme,
+ component: true,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["themes"].map { |theme| theme["id"] }).to contain_exactly(
+ *Theme::CORE_THEMES.values,
+ "concord",
+ )
+ end
+
+ it "hides installation choices when repository imports are restricted" do
+ SiteSetting.concord_in_wizard = true
+ global_setting :allowed_theme_repos, "https://github.com/discourse/other-theme"
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["themes"].map { |theme| theme["id"] }).to contain_exactly(
+ *Theme::CORE_THEMES.values,
+ )
+ end
+
+ it "hides installation choices when theme creation is disabled" do
+ SiteSetting.concord_in_wizard = true
+ plugin = Plugin::Instance.new
+ modifier = ->(*) { false }
+ DiscoursePluginRegistry.register_modifier(
+ plugin,
+ :user_guardian_can_create_theme,
+ &modifier
+ )
+
+ get "/admin/config/design-wizard.json"
+
+ expect(response.parsed_body["themes"].map { |theme| theme["id"] }).to contain_exactly(
+ *Theme::CORE_THEMES.values,
+ )
+ ensure
+ DiscoursePluginRegistry.unregister_modifier(
+ plugin,
+ :user_guardian_can_create_theme,
+ &modifier
+ )
+ end
+
+ it "returns installed Concord as a selectable default with its palette state" do
+ SiteSetting.concord_in_wizard = true
+ concord =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme.git",
+ ),
+ )
+ palette = Fabricate(:color_scheme, theme_id: concord.id, user_selectable: true)
+ concord.update!(color_scheme_id: palette.id)
+ concord.set_default!
+
+ get "/admin/config/design-wizard.json"
+
+ themes = response.parsed_body["themes"]
+ expect(themes.map { |theme| theme["id"] }).to contain_exactly(
+ *Theme::CORE_THEMES.values,
+ concord.id,
+ )
+ expect(themes.find { |theme| theme["id"] == concord.id }).to include(
+ "default" => true,
+ "color_scheme_id" => palette.id,
+ "supports_welcome_banner" => false,
+ "supports_search" => false,
+ "screenshot_light_url" => "/images/design-wizard/concord-light.jpg",
+ "screenshot_dark_url" => "/images/design-wizard/concord-dark.jpg",
+ )
+ expect(response.parsed_body["current_theme"]).to be_nil
+ expect(response.parsed_body["palettes_user_selectable"]).to eq(true)
+ end
+
context "with a theme screenshot" do
fab!(:upload, :image_upload)
@@ -228,6 +362,53 @@ RSpec.describe Admin::Config::DesignWizardController do
expect(light.reload.user_selectable).to eq(true)
end
+ it "applies installed Concord" do
+ SiteSetting.concord_in_wizard = true
+ concord =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+
+ put "/admin/config/design-wizard.json", params: { theme_id: concord.id }
+
+ expect(response.status).to eq(200)
+ expect(SiteSetting.default_theme_id).to eq(concord.id)
+ end
+
+ it "rejects installed Concord by default" do
+ concord =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+
+ expect do
+ put "/admin/config/design-wizard.json", params: { theme_id: concord.id }
+ end.not_to change { SiteSetting.default_theme_id }
+
+ expect(response.status).to eq(400)
+ end
+
+ it "rejects unsupported themes without changing the default" do
+ custom_theme = Fabricate(:theme)
+
+ expect do
+ put "/admin/config/design-wizard.json", params: { theme_id: custom_theme.id }
+ end.not_to change { SiteSetting.default_theme_id }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"]).to be_present
+ end
+
it "applies the welcome banner and search choices to the chosen theme" do
horizon = Theme.horizon_theme
diff --git a/spec/serializers/current_user_serializer_spec.rb b/spec/serializers/current_user_serializer_spec.rb
index 81b7bfcee5b..43aac0e7432 100644
--- a/spec/serializers/current_user_serializer_spec.rb
+++ b/spec/serializers/current_user_serializer_spec.rb
@@ -537,6 +537,29 @@ RSpec.describe CurrentUserSerializer do
expect(admin_serializer.as_json[:can_run_design_wizard]).to eq(true)
end
+ it "remains available when Concord is installed and selected as the default" do
+ SiteSetting.concord_in_wizard = true
+ concord =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+
+ expect(admin_serializer.as_json[:can_run_design_wizard]).to eq(true)
+
+ concord.set_default!
+
+ expect(admin_serializer.as_json[:can_run_design_wizard]).to eq(true)
+
+ SiteSetting.concord_in_wizard = false
+
+ expect(admin_serializer.as_json).not_to have_key(:can_run_design_wizard)
+ end
+
it "is not included once a theme is installed" do
Fabricate(:theme)
expect(admin_serializer.as_json).not_to have_key(:can_run_design_wizard)
diff --git a/spec/services/design_wizard/apply_spec.rb b/spec/services/design_wizard/apply_spec.rb
index 511e1c078f2..ad7893cddba 100644
--- a/spec/services/design_wizard/apply_spec.rb
+++ b/spec/services/design_wizard/apply_spec.rb
@@ -11,7 +11,55 @@ RSpec.describe DesignWizard::Apply do
describe described_class::Contract, type: :model do
it { is_expected.to validate_presence_of(:theme_id) }
- it { is_expected.to validate_inclusion_of(:theme_id).in_array(Theme::CORE_THEMES.values) }
+ it { is_expected.to allow_values(*Theme::CORE_THEMES.values).for(:theme_id) }
+
+ it "accepts installed official themes with either repository URL format" do
+ SiteSetting.concord_in_wizard = true
+ ["", ".git"].each do |suffix|
+ theme =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme#{suffix}",
+ ),
+ )
+
+ expect(described_class.new(theme_id: theme.id)).to be_valid
+ end
+ end
+
+ it "rejects custom themes, similarly named repositories, and components" do
+ SiteSetting.concord_in_wizard = true
+ custom_theme = Fabricate(:theme, name: "Concord")
+ unofficial_theme =
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/other/discourse-concord-theme",
+ ),
+ )
+ component =
+ Fabricate(
+ :theme,
+ component: true,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+
+ [custom_theme, unofficial_theme, component].each do |theme|
+ contract = described_class.new(theme_id: theme.id)
+
+ expect(contract).to be_invalid
+ expect(contract.errors.of_kind?(:theme_id, :inclusion)).to eq(true)
+ end
+ end
it do
is_expected.to validate_inclusion_of(:base_font).in_array(
@@ -49,6 +97,23 @@ RSpec.describe DesignWizard::Apply do
).allow_nil
end
+ it "defaults homepage settings to an empty hash" do
+ contract = described_class.new(theme_id: Theme::CORE_THEMES["foundation"])
+
+ expect(contract).to be_valid
+ expect(contract.homepage_settings).to eq({})
+ end
+
+ it "rejects non-hash and unregistered homepage settings" do
+ [nil, "invalid", [], { title: "Unexpected title" }].each do |homepage_settings|
+ contract =
+ described_class.new(theme_id: Theme::CORE_THEMES["foundation"], homepage_settings:)
+
+ expect(contract).to be_invalid
+ expect(contract.errors.of_kind?(:homepage_settings, :invalid)).to eq(true)
+ end
+ end
+
it "normalizes the base light palette id to nil" do
contract =
described_class.new(
@@ -91,6 +156,45 @@ RSpec.describe DesignWizard::Apply do
let(:theme_id) { Theme::CORE_THEMES["foundation"] }
let(:params) { { theme_id: } }
+ context "when applying an installed official theme" do
+ fab!(:concord_theme) do
+ Fabricate(
+ :theme,
+ remote_theme:
+ Fabricate(
+ :remote_theme,
+ remote_url: "https://github.com/discourse/discourse-concord-theme",
+ ),
+ )
+ end
+ fab!(:palette) { Fabricate(:color_scheme, theme_id: concord_theme.id) }
+
+ let(:theme_id) { concord_theme.id }
+ let(:params) { { theme_id:, light_palette_id: palette.id, palettes_user_selectable: true } }
+
+ before { SiteSetting.concord_in_wizard = true }
+
+ it "rejects the installed theme when Concord is disabled" do
+ SiteSetting.concord_in_wizard = false
+
+ expect(result).to fail_a_contract
+ end
+
+ it "selects the theme and its palette" do
+ expect(result).to run_successfully
+ expect(SiteSetting.default_theme_id).to eq(concord_theme.id)
+ expect(concord_theme.reload.color_scheme_id).to eq(palette.id)
+ expect(palette.reload.user_selectable).to eq(true)
+ end
+ end
+
+ context "when applying an unsupported theme" do
+ fab!(:custom_theme, :theme)
+ let(:theme_id) { custom_theme.id }
+
+ it { is_expected.to fail_a_contract }
+ end
+
context "when the contract isn't valid" do
let(:params) { { theme_id:, base_font: "not_a_font" } }