A platform for community discussion. Free, open, simple.
FIX: Limit site owner onboarding (#38873)
Penar Musaraj27671975e73b
diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rbindex f6c27656377..1c9ff8bb1e9 100644--- a/app/serializers/current_user_serializer.rb+++ b/app/serializers/current_user_serializer.rb@@ -83,7 +83,8 @@ class CurrentUserSerializer < BasicUserSerializer:effective_locale,:can_see_ip,:is_impersonating,- :can_change_post_owner+ :can_change_post_owner,+ :show_site_owner_onboardingdelegate :user_stat, to: :object, private: truedelegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat@@ -163,6 +164,16 @@ class CurrentUserSerializer < BasicUserSerializerscope.can_send_private_messages?end+ def include_show_site_owner_onboarding?+ SiteSetting.enable_site_owner_onboarding && object.admin? &&+ User.where(admin: true).human_users.minimum(:id) == object.id &&+ Topic.minimum(:created_at)&.after?(SiteSetting.site_owner_onboarding_max_days.days.ago)+ end++ def show_site_owner_onboarding+ true+ end+def include_has_unseen_features?object.staff?enddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 0575fdb7b87..2ee12e26e24 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -492,7 +492,6 @@ en:admin_onboarding_banner:launch_in_easy_steps: "Launch in %{step_count} easy steps"- skipped: "The admin onboarding checklist has now been skipped. If you would like to re-enable it, look for `enable site owner onboarding` in the site settings."congrats_onboarding_complete: "Congratulations on completing the onboarding process!"invite_collaborators:title: "Invite Collaborators"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 4abe1bfd953..84bbd7529d7 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2730,6 +2730,7 @@ en: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."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"welcome_banner_image: "Set an image to display in the background of the welcome banner."welcome_banner_location: "Determines where on the page the welcome banner will appear."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex e9846279c33..050f81baab2 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -3809,7 +3809,9 @@ uncategorized:client: truedefault: falsehidden: true- area: "site_admin"+ site_owner_onboarding_max_days:+ default: 5+ hidden: trueenable_welcome_banner:client: truediff --git a/frontend/discourse/app/components/admin-onboarding/banner.gjs b/frontend/discourse/app/components/admin-onboarding/banner.gjsindex 084f5705364..6fe306941e9 100644--- a/frontend/discourse/app/components/admin-onboarding/banner.gjs+++ b/frontend/discourse/app/components/admin-onboarding/banner.gjs@@ -137,13 +137,14 @@ const STEPS = [];export default class AdminOnboardingBanner extends Component {- @service siteSettings;@service currentUser;@service appEvents;@service keyValueStore;@service router;@service toasts;+ @tracked dismissed = false;+constructor() {super(...arguments);this.appEvents.on(@@ -163,15 +164,11 @@ export default class AdminOnboardingBanner extends Component {}get shouldDisplay() {- if (!this.currentUser) {- return false;- }-- if (!this.siteSettings.enable_site_owner_onboarding) {+ if (this.dismissed) {return false;}- if (!this.currentUser.admin) {+ if (!this.currentUser?.show_site_owner_onboarding) {return false;}@@ -192,19 +189,18 @@ export default class AdminOnboardingBanner extends Component {@actionasync endOnboarding({ skipped = true } = {}) {await SiteSetting.update("enable_site_owner_onboarding", false);+ this.dismissed = true;STEPS.forEach((Step) => {this.keyValueStore.remove(`onboarding_step_${Step.name}`);});- const label = skipped- ? "admin_onboarding_banner.skipped"- : "admin_onboarding_banner.congrats_onboarding_complete";-- this.toasts.success({- data: {- message: i18n(label),- },- });+ if (!skipped) {+ this.toasts.success({+ data: {+ message: i18n("admin_onboarding_banner.congrats_onboarding_complete"),+ },+ });+ }}<template>diff --git a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjsindex e7e5a24724b..b9bf0597f7f 100644--- a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs+++ b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs@@ -1,6 +1,6 @@import { action } from "@ember/object";import { service } from "@ember/service";-import { click, settled, visit } from "@ember/test-helpers";+import { click, visit } from "@ember/test-helpers";import { test } from "qunit";import sinon from "sinon";import StartPostingOption from "discourse/components/admin-onboarding/start-posting-option";@@ -12,6 +12,7 @@ acceptance("Admin - Onboarding Banner", function (needs) {needs.user({admin: true,groups: [AUTO_GROUPS.admins],+ show_site_owner_onboarding: true,});needs.settings({@@ -72,9 +73,6 @@ acceptance("Admin - Onboarding Banner", function (needs) {assert.dom(".admin-onboarding-banner").exists();await click(".admin-onboarding-banner .btn-close");- this.siteSettings.enable_site_owner_onboarding = false;-- await settled();assert.dom(".admin-onboarding-banner").doesNotExist();});diff --git a/spec/serializers/current_user_serializer_spec.rb b/spec/serializers/current_user_serializer_spec.rbindex e933fbaf1cd..5bdbcb30477 100644--- a/spec/serializers/current_user_serializer_spec.rb+++ b/spec/serializers/current_user_serializer_spec.rb@@ -421,4 +421,44 @@ RSpec.describe CurrentUserSerializer do)endend++ describe "#show_site_owner_onboarding" do+ fab!(:admin)+ fab!(:topic)+ fab!(:another_admin, :admin)++ let(:admin_serializer) { described_class.new(admin, scope: Guardian.new(admin), root: false) }++ before { SiteSetting.enable_site_owner_onboarding = true }++ it "is not included for non-admin users" do+ payload = serializer.as_json+ expect(payload).not_to have_key(:show_site_owner_onboarding)+ end++ it "is not included when setting is disabled" do+ SiteSetting.enable_site_owner_onboarding = false+ payload = admin_serializer.as_json+ expect(payload).not_to have_key(:show_site_owner_onboarding)+ end++ it "is true for the first admin on a new site" do+ payload = admin_serializer.as_json+ expect(payload[:show_site_owner_onboarding]).to eq(true)+ end++ it "is not included for a second admin" do+ serializer2 =+ described_class.new(another_admin, scope: Guardian.new(another_admin), root: false)+ payload = serializer2.as_json+ expect(payload).not_to have_key(:show_site_owner_onboarding)+ end++ it "is not included when the site is older than the max days setting" do+ SiteSetting.site_owner_onboarding_max_days = 5+ Topic.update_all(created_at: 6.days.ago)+ payload = admin_serializer.as_json+ expect(payload).not_to have_key(:show_site_owner_onboarding)+ end+ endenddiff --git a/spec/system/admin_onboarding_banner_spec.rb b/spec/system/admin_onboarding_banner_spec.rbindex dafdeb81b0c..e63a557682c 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" dofab!(:admin)+ # ensures there is at least one topic, otherwise the topic recent date check doesn't pass+ fab!(:topic)let(:banner) { PageObjects::Components::AdminOnboardingBanner.new }let(:predefined_topics_modal) { PageObjects::Modals::AdminOnboardingPredefinedTopics.new }@@ -34,8 +36,6 @@ describe "Admin Onboarding Banner" dobanner.close- expect(toasts).to have_success(I18n.t("js.admin_onboarding_banner.skipped"))-expect(SiteSetting.enable_site_owner_onboarding).to eq(false)endend