Skip to content

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

UX: Improve admin onboarding topic suggestions (#44080)

Keegan George0d7c58e67d04
diff --git a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
index ea0b8e4b71d..87c434aa3c1 100644
--- a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
+++ b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
@@ -206,8 +206,13 @@
border-radius: var(--d-border-radius);
background: var(--secondary);
+ &:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+ }
+
&:focus-visible,
- &:hover {
+ &:hover:not(:disabled) {
outline: 2px solid var(--tertiary);
.predefined-topic-options-modal__title {
@@ -216,6 +221,13 @@
}
}
+ &__heading {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-2);
+ }
+
&__title {
display: block;
font-weight: bold;
diff --git a/app/controllers/admin/onboarding_events_controller.rb b/app/controllers/admin/onboarding_events_controller.rb
index decebcd0169..c181be4d723 100644
--- a/app/controllers/admin/onboarding_events_controller.rb
+++ b/app/controllers/admin/onboarding_events_controller.rb
@@ -10,7 +10,15 @@ class Admin::OnboardingEventsController < Admin::AdminController
when "step_completed"
step = params.require(:step)
raise Discourse::InvalidParameters.new(:step) if !STEPS.include?(step)
- logger.log_admin_onboarding_step_completed(step)
+ topic_option = params[:topic_option]
+ if topic_option.present? &&
+ (
+ step != "start_posting" ||
+ !UserHistory::ADMIN_ONBOARDING_TOPIC_OPTIONS.include?(topic_option)
+ )
+ raise Discourse::InvalidParameters.new(:topic_option)
+ end
+ logger.log_admin_onboarding_step_completed(step, topic_option: topic_option.presence)
when "completed"
logger.log_admin_onboarding_completed
when "dismissed"
diff --git a/app/models/user_history.rb b/app/models/user_history.rb
index 77364b9df5c..a633217bf65 100644
--- a/app/models/user_history.rb
+++ b/app/models/user_history.rb
@@ -14,7 +14,13 @@ class UserHistory < ActiveRecord::Base
# Subjects logged alongside the :admin_onboarding_step_completed action, one
# per step of the admin onboarding panel.
- ADMIN_ONBOARDING_STEPS = %w[select_theme invite_collaborators start_posting].freeze
+ ADMIN_ONBOARDING_STEPS = %w[select_theme start_posting invite_collaborators].freeze
+ ADMIN_ONBOARDING_TOPIC_OPTIONS = %w[
+ plan_categories
+ plan_invites
+ introduce_yourself
+ write_your_own
+ ].freeze
# Each value in the context should be shorter than this
MAX_CONTEXT_LENGTH = 50_000
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index 6d08932877d..bddfe0a1aba 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -322,10 +322,24 @@ class StaffActionLogger
def log_admin_onboarding_step_completed(step, opts = {})
raise Discourse::InvalidParameters.new(:step) if step.blank?
+ topic_option = opts[:topic_option]
+ details = opts[:details]
+ if topic_option.present?
+ details =
+ I18n.t(
+ "staff_action_logs.admin_onboarding_topic_option",
+ option:
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.#{topic_option}.title"),
+ option_id: topic_option,
+ )
+ end
+
UserHistory.create!(
params(opts).merge(
action: UserHistory.actions[:admin_onboarding_step_completed],
subject: step,
+ new_value: topic_option,
+ details: details,
),
)
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index dad8d927dfc..b41a5cf565c 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -602,19 +602,20 @@ en:
predefined_topics_description: "Pick from a collection of conversation starters to get discussions going"
use_predefined: "Browse templates"
back: "Back"
+ category_unavailable: "This category is unavailable for posting."
icebreakers:
- fun_facts:
- title: "What are some fun facts about you?"
- body: "Hi everyone! I'm excited to start this new community. To kick things off, let's share a fun fact about ourselves. I'll go first: I love hiking and exploring new trails! What's something interesting about you?"
- coolest_thing_you_have_seen_today:
- title: "What's the coolest thing you've seen today?"
- body: "What's the coolest thing you've seen or experienced today? It could be anything from a beautiful sunset to a random act of kindness. I'll start: I saw a dog helping an elderly person cross the street!"
+ plan_categories:
+ title: "What categories should we start with?"
+ body: "Let’s figure out how to organise things before we launch! What will people want to talk about most? We can start with just a few categories and add more later."
+ plan_invites:
+ title: "Which members should we invite before we launch?"
+ body: "It’s always nicer to join a community that already has some people in it. Who should we invite first? Think of folks who love to chat, help others out, and would be excited to get involved early."
introduce_yourself:
title: "Introduce yourself"
body: "Welcome to the community! Let's get to know each other. Please introduce yourself and share a little bit about your interests. I'll go first: I'm passionate about technology and love teaching others!"
- what_is_your_favorite_food:
- title: "What is your favorite food?"
- body: "Share your favorite food with the community! I'll start: I love pizza, especially with extra cheese and pepperoni."
+ write_your_own:
+ title: "Write your own"
+ body: "Start a conversation with a topic tailored to your community."
design_wizard:
title: "Customize your site"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 261d18cc8ad..38496544b8d 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -6313,6 +6313,7 @@ en:
custom: "Notification from %{username} on %{site_title}"
staff_action_logs:
+ admin_onboarding_topic_option: "Selected option: %{option}\nOption ID: %{option_id}"
redacted: "[content not visible]"
json_too_long: "Values not logged because they exceed the column length limits"
not_found: "not found"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 46a2b2769ca..2d6ee6e911a 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4059,6 +4059,7 @@ uncategorized:
staff_category_id:
default: -1
hidden: true
+ client: true
area: "categories"
uncategorized_category_id:
default: -1
diff --git a/frontend/discourse/app/components/admin-onboarding/banner.gjs b/frontend/discourse/app/components/admin-onboarding/banner.gjs
index dbb7c9cd18f..35454b8b1f8 100644
--- a/frontend/discourse/app/components/admin-onboarding/banner.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/banner.gjs
@@ -50,37 +50,11 @@ const STEPS = [
this.designWizard.start({ onComplete: this.#onComplete });
}
},
- class InviteCollaborators extends OnboardingStep {
- static name = "invite_collaborators";
-
- @service appEvents;
-
- icon = "paper-plane";
-
- constructor() {
- super(...arguments);
- this.appEvents.on("create-invite:saved", this, this.markAsCompleted);
- }
-
- willDestroy() {
- super.willDestroy(...arguments);
- this.appEvents.off("create-invite:saved", this, this.markAsCompleted);
- }
-
- @action
- performAction() {
- showCreateInviteModal(this, {
- model: { invites: trackedArray(), defaultRole: "admin" },
- });
- }
- },
class StartPosting extends OnboardingStep {
static name = "start_posting";
- @service composer;
@service appEvents;
@service modal;
- @service siteSettings;
icon = "comments";
@@ -106,8 +80,10 @@ const STEPS = [
);
}
- completeStep() {
- return this.markAsCompleted();
+ completeStep(_post, composer) {
+ return this.markAsCompleted({
+ topicOption: composer?.adminOnboardingTopicOption,
+ });
}
showStartPostingOptions() {
@@ -129,22 +105,35 @@ const STEPS = [
});
}
- openTopic(topicKey) {
- this.composer.openNewTopic({
- title: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.title`
- ),
- body: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.body`
- ),
- });
- }
-
@action
async performAction() {
this.showStartPostingOptions();
}
},
+ class InviteCollaborators extends OnboardingStep {
+ static name = "invite_collaborators";
+
+ @service appEvents;
+
+ icon = "paper-plane";
+
+ constructor() {
+ super(...arguments);
+ this.appEvents.on("create-invite:saved", this, this.markAsCompleted);
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.appEvents.off("create-invite:saved", this, this.markAsCompleted);
+ }
+
+ @action
+ performAction() {
+ showCreateInviteModal(this, {
+ model: { invites: trackedArray(), defaultRole: "admin" },
+ });
+ }
+ },
];
export default class AdminOnboardingBanner extends Component {
diff --git a/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs b/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs
index c7942c52112..f1cdfe52fd2 100644
--- a/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs
@@ -3,34 +3,55 @@ import { concat, fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
+import Category from "discourse/models/category";
import DModal from "discourse/ui-kit/d-modal";
+import dCategoryBadge from "discourse/ui-kit/helpers/d-category-badge";
import { i18n } from "discourse-i18n";
export default class PredefinedTopicOptions extends Component {
@service composer;
+ @service siteSettings;
- icebreakerTopics = [
- "fun_facts",
- "coolest_thing_you_have_seen_today",
- "introduce_yourself",
- "what_is_your_favorite_food",
- ];
+ get topics() {
+ const staff = Category.findById(this.siteSettings.staff_category_id);
+ const general = Category.findById(this.siteSettings.general_category_id);
- openTopic(topicKey) {
- this.composer.openNewTopic({
- title: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.title`
- ),
- body: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.body`
- ),
- });
+ return [
+ { key: "plan_categories", category: staff },
+ { key: "plan_invites", category: staff },
+ { key: "introduce_yourself", category: general },
+ { key: "write_your_own", category: general },
+ ].map((topic) => ({
+ ...topic,
+ disabled: !topic.category?.canCreateTopic,
+ }));
}
@action
handleSelectTopic(topic) {
+ if (topic.disabled) {
+ return;
+ }
+
this.args.closeModal();
- this.openTopic(topic);
+ const custom = topic.key === "write_your_own";
+
+ this.composer.openNewTopic({
+ title: custom
+ ? ""
+ : i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${topic.key}.title`
+ ),
+ body: custom
+ ? ""
+ : i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${topic.key}.body`
+ ),
+ category: topic.category,
+ // Draft metadata follows this composer, not the last card clicked. It
+ // survives draft restoration and is discarded with an abandoned topic.
+ adminOnboardingTopicOption: topic.key,
+ });
}
<template>
@@ -44,26 +65,39 @@ export default class PredefinedTopicOptions extends Component {
>
<:body>
<div class="predefined-topic-options-modal__list">
- {{#each this.icebreakerTopics as |topic|}}
+ {{#each this.topics as |topic|}}
<button
class="predefined-topic-options-modal__card"
+ data-topic-option={{topic.key}}
+ disabled={{topic.disabled}}
+ title={{if
+ topic.disabled
+ (i18n
+ "admin_onboarding_banner.start_posting.category_unavailable"
+ )
+ }}
type="button"
{{on "click" (fn this.handleSelectTopic topic)}}
>
- <span class="predefined-topic-options-modal__title">
- {{i18n
- (concat
- "admin_onboarding_banner.start_posting.icebreakers."
- topic
- ".title"
- )
- }}
+ <span class="predefined-topic-options-modal__heading">
+ <span class="predefined-topic-options-modal__title">
+ {{i18n
+ (concat
+ "admin_onboarding_banner.start_posting.icebreakers."
+ topic.key
+ ".title"
+ )
+ }}
+ </span>
+ {{#if topic.category}}
+ {{dCategoryBadge topic.category}}
+ {{/if}}
</span>
<p class="predefined-topic-options-modal__body">
{{i18n
(concat
"admin_onboarding_banner.start_posting.icebreakers."
- topic
+ topic.key
".body"
)
}}
diff --git a/frontend/discourse/app/components/admin-onboarding/step.gjs b/frontend/discourse/app/components/admin-onboarding/step.gjs
index 2c6ab57c5fc..a52650165b2 100644
--- a/frontend/discourse/app/components/admin-onboarding/step.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/step.gjs
@@ -49,7 +49,7 @@ export default class OnboardingStep extends Component {
// Awaits the audit write so callers that reload the page on completion can't
// cancel it in flight.
- async markAsCompleted() {
+ async markAsCompleted(options = {}) {
// app events backing some steps can fire more than once, so only audit the
// first transition into the completed state
const alreadyCompleted = this.completed;
@@ -62,7 +62,11 @@ export default class OnboardingStep extends Component {
this.appEvents.trigger(`onboarding-step:completed`, this.name);
if (!alreadyCompleted) {
- await logOnboardingEvent("step_completed", this.name);
+ await logOnboardingEvent(
+ "step_completed",
+ this.name,
+ options?.topicOption
+ );
}
return this.args.onCompleted?.(this.name);
diff --git a/frontend/discourse/app/lib/admin-onboarding.js b/frontend/discourse/app/lib/admin-onboarding.js
index 706c1f8a602..7a3d8ea39a7 100644
--- a/frontend/discourse/app/lib/admin-onboarding.js
+++ b/frontend/discourse/app/lib/admin-onboarding.js
@@ -8,12 +8,17 @@ import { ajax } from "discourse/lib/ajax";
*
* @param {"step_completed"|"completed"|"dismissed"} event
* @param {string} [step] name of the step, for `step_completed` events
+ * @param {string} [topicOption] option used to complete `start_posting`
*/
-export async function logOnboardingEvent(event, step) {
+export async function logOnboardingEvent(event, step, topicOption) {
try {
await ajax("/admin/onboarding/events", {
type: "POST",
- data: { event, step },
+ data: {
+ event,
+ ...(step && { step }),
+ ...(topicOption && { topic_option: topicOption }),
+ },
});
} catch {
// intentionally ignored
diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.js
index 3d15284f68e..23addf1f261 100644
--- a/frontend/discourse/app/models/composer.js
+++ b/frontend/discourse/app/models/composer.js
@@ -102,6 +102,7 @@ const CLOSED = "closed",
archetypeId: "archetypeId",
whisper: "whisper",
metaData: "metaData",
+ adminOnboardingTopicOption: "adminOnboardingTopicOption",
composerTime: "composerTime",
typingTime: "typingTime",
postId: "post.id",
@@ -1541,6 +1542,7 @@ export default class Composer extends RestModel {
this.setProperties({
archetypeId: opts.archetypeId || this.site.default_archetype,
metaData: opts.metaData ? EmberObject.create(opts.metaData) : null,
+ adminOnboardingTopicOption: opts.adminOnboardingTopicOption ?? null,
reply: opts.reply || this.reply || "",
});
diff --git a/frontend/discourse/app/services/composer.js b/frontend/discourse/app/services/composer.js
index 81a1b546000..e1d310cddf4 100644
--- a/frontend/discourse/app/services/composer.js
+++ b/frontend/discourse/app/services/composer.js
@@ -1662,7 +1662,14 @@ export default class ComposerService extends Service {
}
@action
- async openNewTopic({ title, body, category, tags, formTemplate } = {}) {
+ async openNewTopic({
+ title,
+ body,
+ category,
+ tags,
+ formTemplate,
+ adminOnboardingTopicOption,
+ } = {}) {
const sharedDraftsCategoryId = this.site.shared_drafts_category_id;
const isSharedDraftCategory =
!!sharedDraftsCategoryId && category?.id === sharedDraftsCategoryId;
@@ -1678,6 +1685,7 @@ export default class ComposerService extends Service {
prioritizedCategoryId: categoryId,
topicCategoryId: categoryId,
formTemplateId: formTemplate?.id,
+ adminOnboardingTopicOption,
topicTitle: title,
topicBody: body,
topicTags: tags,
diff --git a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
index d3ee1ba939d..a79626cc231 100644
--- a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
+++ b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
@@ -7,6 +7,7 @@ import { AUTO_GROUPS } from "discourse/lib/constants";
import { withPluginApi } from "discourse/lib/plugin-api";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import { i18n } from "discourse-i18n";
const designWizardData = () => ({
themes: [
@@ -130,7 +131,7 @@ const withStep = (id, assert) => {
};
acceptance("Admin - Onboarding Banner", function (needs) {
- let loggedEvents = [];
+ const loggedEvents = [];
needs.user({
admin: true,
@@ -141,11 +142,12 @@ acceptance("Admin - Onboarding Banner", function (needs) {
needs.settings({
enable_site_owner_onboarding: true,
general_category_id: 1,
+ staff_category_id: 3,
default_composer_category: 1,
});
needs.hooks.beforeEach(function () {
- loggedEvents = [];
+ loggedEvents.length = 0;
this.schemeLinks = [];
// registered so afterEach tears them down even when an assertion throws
@@ -249,21 +251,136 @@ acceptance("Admin - Onboarding Banner", function (needs) {
);
});
- test("it can complete `start_posting` step with predefined data", async function (assert) {
- const step = withStep("start_posting", assert);
+ test("posting comes before inviting collaborators", async function (assert) {
await visit("/");
+ assert.deepEqual(
+ [...document.querySelectorAll(".onboarding-step")].map((step) => step.id),
+ ["select_theme", "start_posting", "invite_collaborators"]
+ );
+ });
- step.isNotChecked();
+ for (const [option, categoryId] of [
+ ["plan_categories", 3],
+ ["plan_invites", 3],
+ ["introduce_yourself", 1],
+ ["write_your_own", 1],
+ ]) {
+ test(`it completes posting with ${option}`, async function (assert) {
+ const step = withStep("start_posting", assert);
+ const composer = this.container.lookup("service:composer");
+ await visit("/");
+ step.isNotChecked();
+ await step.clickAction();
+ assert.dom(".predefined-topic-options-modal__card").exists({ count: 4 });
+ assert
+ .dom(`[data-topic-option="${option}"] .badge-category__name`)
+ .exists();
+ await click(`[data-topic-option="${option}"]`);
+
+ assert.strictEqual(composer.model.categoryId, categoryId);
+ assert.strictEqual(composer.model.adminOnboardingTopicOption, option);
+ assert.strictEqual(
+ composer.model.serializeDraftData().adminOnboardingTopicOption,
+ option,
+ "saves attribution with the draft"
+ );
+ const custom = option === "write_your_own";
+ assert
+ .dom("#reply-title")
+ .hasValue(
+ custom
+ ? ""
+ : i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${option}.title`
+ )
+ );
+ assert
+ .dom(".d-editor-input")
+ .hasValue(
+ custom
+ ? ""
+ : i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${option}.body`
+ )
+ );
+ assert.strictEqual(
+ loggedEvents.length,
+ 0,
+ "opening a card is not completion"
+ );
- await step.clickAction();
+ await fillIn("#reply-title", "A title tailored to this community");
+ await fillIn(
+ ".d-editor-input",
+ "A conversation tailored to this community."
+ );
+ await click(".create");
+ await visit("/");
+ step.isChecked();
+ assert.deepEqual(
+ loggedEvents,
+ [
+ {
+ event: "step_completed",
+ step: "start_posting",
+ topic_option: option,
+ },
+ ],
+ "logs the original choice even after editing its contents"
+ );
+ });
+ }
- assert.dom(".predefined-topic-options-modal__card").exists({ count: 4 });
- await click(".predefined-topic-options-modal__card:last-child");
+ test("unavailable categories cannot fall back to public posting", async function (assert) {
+ this.siteSettings.staff_category_id = -1;
+ await visit("/");
+ await withStep("start_posting", assert).clickAction();
+ assert.dom('[data-topic-option="plan_categories"]').isDisabled();
+ assert.dom('[data-topic-option="plan_invites"]').isDisabled();
+ assert.dom('[data-topic-option="introduce_yourself"]').isEnabled();
+ assert.dom('[data-topic-option="write_your_own"]').isEnabled();
+ });
+ test("discarding a suggestion does not attribute an unrelated topic to it", async function (assert) {
+ await visit("/");
+ await withStep("start_posting", assert).clickAction();
+ await click('[data-topic-option="plan_categories"]');
+ await click("#reply-control .discard-button");
+ await click(".discard-draft-modal__discard-btn");
+ assert.strictEqual(loggedEvents.length, 0);
+
+ const composer = this.container.lookup("service:composer");
+ await composer.openNewTopic({
+ title: "An unrelated conversation",
+ body: "This was not created from an onboarding option.",
+ });
+ await settled();
+ assert.strictEqual(composer.model.adminOnboardingTopicOption, null);
await click(".create");
await visit("/");
+ assert.strictEqual(loggedEvents.length, 1);
+ assert.strictEqual(loggedEvents[0].step, "start_posting");
+ assert.strictEqual(loggedEvents[0].topic_option, undefined);
+ });
- step.isChecked();
+ test("reopening a saved draft preserves the selected option", async function (assert) {
+ await visit("/");
+ await withStep("start_posting", assert).clickAction();
+ await click('[data-topic-option="plan_invites"]');
+ const composer = this.container.lookup("service:composer");
+ const { draftKey, draftSequence } = composer.model;
+ const draft = JSON.stringify(composer.model.serializeDraftData());
+ await click("#reply-control .discard-button");
+ await click(".discard-draft-modal__discard-btn");
+ await composer.open({ draft, draftKey, draftSequence });
+ await settled();
+ assert.strictEqual(
+ composer.model.adminOnboardingTopicOption,
+ "plan_invites"
+ );
+ await click(".create");
+ await visit("/");
+ assert.strictEqual(loggedEvents[0].topic_option, "plan_invites");
});
test("it can complete `start_posting` step with registered posting-options", async function (assert) {
diff --git a/spec/integrity/admin_onboarding_locale_spec.rb b/spec/integrity/admin_onboarding_locale_spec.rb
index e7ab580fd4f..0c114bca0f3 100644
--- a/spec/integrity/admin_onboarding_locale_spec.rb
+++ b/spec/integrity/admin_onboarding_locale_spec.rb
@@ -18,6 +18,12 @@ RSpec.describe "Admin onboarding banner locale keys" do
expect(steps).to include("select_theme")
end
+ it "defines every topic option recorded by the staff action log" do
+ options = banner.fetch("start_posting").fetch("icebreakers")
+ expect(options.keys).to contain_exactly(*UserHistory::ADMIN_ONBOARDING_TOPIC_OPTIONS)
+ expect(options.values).to all(include("title", "body"))
+ end
+
it "defines title, description, action and completed for every step" do
missing =
steps.each_with_object({}) do |step, hash|
diff --git a/spec/requests/admin/onboarding_events_controller_spec.rb b/spec/requests/admin/onboarding_events_controller_spec.rb
index a612e306dc0..a76adcdbbc0 100644
--- a/spec/requests/admin/onboarding_events_controller_spec.rb
+++ b/spec/requests/admin/onboarding_events_controller_spec.rb
@@ -23,6 +23,68 @@ RSpec.describe Admin::OnboardingEventsController do
expect(log.subject).to eq("select_theme")
end
+ UserHistory::ADMIN_ONBOARDING_TOPIC_OPTIONS.each do |option|
+ it "logs the selected #{option} option with readable details" do
+ post "/admin/onboarding/events.json",
+ params: {
+ event: "step_completed",
+ step: "start_posting",
+ topic_option: option,
+ }
+
+ expect(response.status).to eq(204)
+ log = UserHistory.last
+ expect(log.subject).to eq("start_posting")
+ expect(log.new_value).to eq(option)
+ expect(log.details).to eq(
+ I18n.t(
+ "staff_action_logs.admin_onboarding_topic_option",
+ option:
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.#{option}.title"),
+ option_id: option,
+ ),
+ )
+ end
+ end
+
+ it "still logs posting completed outside the suggested options" do
+ post "/admin/onboarding/events.json",
+ params: {
+ event: "step_completed",
+ step: "start_posting",
+ }
+
+ expect(response.status).to eq(204)
+ expect(UserHistory.last.new_value).to be_nil
+ expect(UserHistory.last.details).to be_nil
+ end
+
+ it "rejects an unknown topic option without logging" do
+ expect {
+ post "/admin/onboarding/events.json",
+ params: {
+ event: "step_completed",
+ step: "start_posting",
+ topic_option: "unknown",
+ }
+ }.not_to change { UserHistory.count }
+
+ expect(response.status).to eq(400)
+ end
+
+ it "rejects a topic option for another step without logging" do
+ expect {
+ post "/admin/onboarding/events.json",
+ params: {
+ event: "step_completed",
+ step: "select_theme",
+ topic_option: "plan_categories",
+ }
+ }.not_to change { UserHistory.count }
+
+ expect(response.status).to eq(400)
+ end
+
it "logs a staff action when onboarding is completed" do
post "/admin/onboarding/events.json", params: { event: "completed" }
diff --git a/spec/system/admin_onboarding_banner_spec.rb b/spec/system/admin_onboarding_banner_spec.rb
index ed2f89c6c9b..50f23e11afc 100644
--- a/spec/system/admin_onboarding_banner_spec.rb
+++ b/spec/system/admin_onboarding_banner_spec.rb
@@ -2,6 +2,8 @@
describe "Admin Onboarding Banner" do
fab!(:admin)
+ fab!(:staff_category) { Fabricate(:private_category, name: "Staff", group: Group[:staff]) }
+ fab!(:general_category) { Fabricate(:category, name: "General") }
let(:banner) { PageObjects::Components::AdminOnboardingBanner.new }
let(:predefined_topics_modal) { PageObjects::Modals::AdminOnboardingPredefinedTopics.new }
@@ -11,6 +13,8 @@ describe "Admin Onboarding Banner" do
let(:toasts) { PageObjects::Components::Toasts.new }
before do
+ SiteSetting.staff_category_id = staff_category.id
+ SiteSetting.general_category_id = general_category.id
SiteSetting.enable_invite_modal_with_roles = false
SiteSetting.enable_site_owner_onboarding = true
SiteSetting.default_theme_id = Theme.foundation_theme.id
@@ -26,6 +30,7 @@ describe "Admin Onboarding Banner" do
it "shows all three onboarding steps" do
visit("/")
+ expect(banner.step_names).to eq(%w[select_theme start_posting invite_collaborators])
expect(banner.step("select_theme")).to be_present
expect(banner.step("invite_collaborators")).to be_present
expect(banner.step("start_posting")).to be_present
@@ -61,7 +66,10 @@ describe "Admin Onboarding Banner" do
predefined_topics_modal.select_topic(0)
expect(composer).to be_opened
- expect(composer.composer_input.value).not_to be_empty
+ expect(composer.composer_input.value).to eq(
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.plan_categories.body"),
+ )
+ expect(composer.category_chooser).to have_selected_name(staff_category.name)
composer.composer_input.set("Testing topic selection")
composer.create
@@ -69,6 +77,119 @@ describe "Admin Onboarding Banner" do
visit("/")
expect(banner.step_completed?("start_posting")).to eq(true)
+
+ log =
+ UserHistory.find_by!(
+ action: UserHistory.actions[:admin_onboarding_step_completed],
+ acting_user_id: admin.id,
+ subject: "start_posting",
+ )
+ expect(log.new_value).to eq("plan_categories")
+ expect(Topic.last.category_id).to eq(staff_category.id)
+
+ logs = PageObjects::Pages::AdminStaffActionLogs.new
+ logs.visit
+ logs.show_details(log)
+ expect(page).to have_css(
+ ".log-details-modal",
+ text: "Selected option: What categories should we start with?",
+ )
+ expect(page).to have_css(".log-details-modal", text: "Option ID: plan_categories")
+ end
+
+ %w[plan_invites introduce_yourself write_your_own].each do |option|
+ it "publishes the #{option} choice in its category and records the original option" do
+ category = option == "plan_invites" ? staff_category : general_category
+ visit("/")
+ banner.click_step_action("start_posting")
+ predefined_topics_modal.select_option(option)
+
+ expect(composer).to be_opened
+ expect(composer.category_chooser).to have_selected_name(category.name)
+ if option == "write_your_own"
+ expect(composer).to have_input_title("")
+ expect(composer).to have_value("")
+ else
+ expect(composer).to have_input_title(
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.#{option}.title"),
+ )
+ expect(composer).to have_value(
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.#{option}.body"),
+ )
+ end
+
+ composer.fill_title("A conversation for our community")
+ composer.fill_content("A new conversation tailored to our community.")
+ composer.create
+ expect(page).to have_content("A new conversation tailored to our community.")
+
+ try_until_success do
+ log = UserHistory.find_by(acting_user_id: admin.id, subject: "start_posting")
+ expect(log&.new_value).to eq(option)
+ end
+ expect(Topic.last.category_id).to eq(category.id)
+ end
+ end
+
+ it "does not attribute an unrelated topic to a discarded suggestion" do
+ visit("/")
+ banner.click_step_action("start_posting")
+ predefined_topics_modal.select_option("plan_categories")
+ composer.discard
+ PageObjects::Modals::DiscardDraft.new.click_discard
+ expect(composer).to be_closed
+ expect(banner.step_not_completed?("start_posting")).to eq(true)
+ expect(UserHistory.exists?(acting_user_id: admin.id, subject: "start_posting")).to eq(false)
+
+ visit("/new-topic")
+ composer.fill_title("An unrelated community conversation")
+ composer.fill_content("This topic was not started from an onboarding suggestion.")
+ composer.switch_category(general_category.name)
+ composer.create
+ expect(page).to have_content("This topic was not started from an onboarding suggestion.")
+
+ try_until_success do
+ log = UserHistory.find_by(acting_user_id: admin.id, subject: "start_posting")
+ expect(log).to be_present
+ expect(log.new_value).to be_nil
+ expect(log.details).to be_nil
+ end
+ end
+
+ it "retains attribution when a saved draft is resumed after a reload" do
+ visit("/")
+ banner.click_step_action("start_posting")
+ predefined_topics_modal.select_option("plan_invites")
+ composer.close
+ expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))
+
+ visit("/")
+ drafts_menu = PageObjects::Components::DraftsMenu.new
+ drafts_menu.open
+ drafts_menu.resume_draft
+ expect(composer).to have_input_title(
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.plan_invites.title"),
+ )
+ composer.create
+ expect(page).to have_content(
+ I18n.t("js.admin_onboarding_banner.start_posting.icebreakers.plan_invites.body"),
+ )
+
+ try_until_success do
+ log = UserHistory.find_by(acting_user_id: admin.id, subject: "start_posting")
+ expect(log&.new_value).to eq("plan_invites")
+ end
+ end
+
+ it "disables Staff suggestions when the configured category is unavailable" do
+ SiteSetting.staff_category_id = -1
+ visit("/")
+ banner.click_step_action("start_posting")
+ expect(predefined_topics_modal).to have_disabled_option("plan_categories")
+ expect(predefined_topics_modal).to have_disabled_option("plan_invites")
+ predefined_topics_modal.select_option("write_your_own")
+ expect(composer).to be_opened
+ expect(composer.category_chooser).to have_selected_name(general_category.name)
end
it "can cancel topic selection without completing step" do
diff --git a/spec/system/page_objects/components/admin_onboarding_banner.rb b/spec/system/page_objects/components/admin_onboarding_banner.rb
index 275b4fa0062..9ebcfcaf5c1 100644
--- a/spec/system/page_objects/components/admin_onboarding_banner.rb
+++ b/spec/system/page_objects/components/admin_onboarding_banner.rb
@@ -3,6 +3,10 @@
module PageObjects
module Components
class AdminOnboardingBanner < PageObjects::Components::Base
+ def step_names
+ all(".admin-onboarding-banner .onboarding-step").map { |step| step[:id] }
+ end
+
def visible?
has_css?(".admin-onboarding-banner")
end
diff --git a/spec/system/page_objects/components/drafts_menu.rb b/spec/system/page_objects/components/drafts_menu.rb
index a934126ce89..7e955fbef7c 100644
--- a/spec/system/page_objects/components/drafts_menu.rb
+++ b/spec/system/page_objects/components/drafts_menu.rb
@@ -41,6 +41,10 @@ module PageObjects
find(MENU_SELECTOR + "-trigger").click
end
+ def resume_draft(index = 0)
+ all(MENU_SELECTOR + "-content .topic-drafts-item button")[index].click
+ end
+
def draft_item_count
all(MENU_SELECTOR + "-content .topic-drafts-item").size
end
diff --git a/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb b/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb
index 88f6faeabea..5634eea6001 100644
--- a/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb
+++ b/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb
@@ -25,6 +25,14 @@ module PageObjects
topic_cards[index].click
end
+ def select_option(option)
+ find("#{MODAL_SELECTOR} [data-topic-option='#{option}']").click
+ end
+
+ def has_disabled_option?(option)
+ has_css?("#{MODAL_SELECTOR} [data-topic-option='#{option}'][disabled]")
+ end
+
def cancel
close
end
diff --git a/spec/system/page_objects/pages/admin_staff_action_logs.rb b/spec/system/page_objects/pages/admin_staff_action_logs.rb
index d0ee171bf0f..9bc679dbf2d 100644
--- a/spec/system/page_objects/pages/admin_staff_action_logs.rb
+++ b/spec/system/page_objects/pages/admin_staff_action_logs.rb
@@ -32,6 +32,13 @@ module PageObjects
has_css?("#{log_row_selector(user_history)} .details", text: text)
end
+ def show_details(user_history)
+ log_row(user_history).find(
+ ".details a",
+ text: I18n.t("admin_js.admin.logs.staff_actions.show"),
+ ).click
+ end
+
def filter_by_action(action)
filter = PageObjects::Components::SelectKit.new("#staff-action-logs-action-filter")
filter.search(I18n.t("admin_js.admin.logs.staff_actions.actions.#{action}"))