From 476d26159a054331a3f5329a64b33c54bcc3d41f Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 14 Aug 2020 19:10:56 +0530 Subject: [PATCH] FEATURE: add new user option `skip_new_user_tips`. (#10437) And add new site setting `default_other_skip_new_user_tips` in user preferences category. --- app/assets/javascripts/admin/mixins/setting-component.js | 1 + .../discourse/app/controllers/preferences/interface.js | 3 ++- app/assets/javascripts/discourse/app/models/user.js | 3 ++- .../discourse/app/templates/preferences/interface.hbs | 1 + app/controllers/admin/site_settings_controller.rb | 1 + app/models/user_option.rb | 1 + app/serializers/current_user_serializer.rb | 7 ++++++- app/serializers/user_option_serializer.rb | 3 ++- app/services/user_updater.rb | 3 ++- config/locales/client.en.yml | 1 + config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + ...0200814081437_add_skip_new_user_tips_to_user_options.rb | 7 +++++++ lib/tasks/import.rake | 4 +++- spec/models/user_option_spec.rb | 2 ++ spec/models/user_spec.rb | 2 ++ spec/serializers/user_serializer_spec.rb | 3 ++- test/javascripts/fixtures/session-fixtures.js | 3 ++- test/javascripts/fixtures/user_fixtures.js | 3 +++ 19 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20200814081437_add_skip_new_user_tips_to_user_options.rb diff --git a/app/assets/javascripts/admin/mixins/setting-component.js b/app/assets/javascripts/admin/mixins/setting-component.js index 699cecd32eb..44609e88cff 100644 --- a/app/assets/javascripts/admin/mixins/setting-component.js +++ b/app/assets/javascripts/admin/mixins/setting-component.js @@ -167,6 +167,7 @@ export default Mixin.create({ "default_other_enable_defer", "default_other_dynamic_favicon", "default_other_like_notification_frequency", + "default_other_skip_new_user_tips", "default_topics_automatic_unpin", "default_categories_watching", "default_categories_tracking", diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js index 8b63f5b5fe0..dd80b409d29 100644 --- a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js +++ b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js @@ -43,7 +43,8 @@ export default Controller.extend({ "homepage_id", "hide_profile_and_presence", "text_size", - "title_count_mode" + "title_count_mode", + "skip_new_user_tips" ]; if (makeDefault) { diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index 2dca08adcda..6013cae781b 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -318,7 +318,8 @@ const User = RestModel.extend({ "hide_profile_and_presence", "text_size", "title_count_mode", - "timezone" + "timezone", + "skip_new_user_tips" ]; if (fields) { diff --git a/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs b/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs index c3d23b12ff2..af40097a8dd 100644 --- a/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs +++ b/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs @@ -103,6 +103,7 @@ onChange=(action (mut model.user_option.title_count_mode)) }} + {{preference-checkbox labelKey="user.skip_new_user_tips" checked=model.user_option.skip_new_user_tips class="pref-new-user-tips"}} {{plugin-outlet name="user-preferences-interface" args=(hash model=model save=(action "save"))}} diff --git a/app/controllers/admin/site_settings_controller.rb b/app/controllers/admin/site_settings_controller.rb index e56c7faf019..46b74093308 100644 --- a/app/controllers/admin/site_settings_controller.rb +++ b/app/controllers/admin/site_settings_controller.rb @@ -194,6 +194,7 @@ class Admin::SiteSettingsController < Admin::AdminController default_other_auto_track_topics_after_msecs: "auto_track_topics_after_msecs", default_other_notification_level_when_replying: "notification_level_when_replying", default_other_like_notification_frequency: "like_notification_frequency", + default_other_skip_new_user_tips: "skip_new_user_tips", default_email_digest_frequency: "digest_after_minutes", default_include_tl0_in_digests: "include_tl0_in_digests", default_text_size: "text_size_key", diff --git a/app/models/user_option.rb b/app/models/user_option.rb index 7a68727e90e..8619e116b5b 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -57,6 +57,7 @@ class UserOption < ActiveRecord::Base self.enable_defer = SiteSetting.default_other_enable_defer self.external_links_in_new_tab = SiteSetting.default_other_external_links_in_new_tab self.dynamic_favicon = SiteSetting.default_other_dynamic_favicon + self.skip_new_user_tips = SiteSetting.default_other_skip_new_user_tips self.new_topic_duration_minutes = SiteSetting.default_other_new_topic_duration_minutes self.auto_track_topics_after_msecs = SiteSetting.default_other_auto_track_topics_after_msecs diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index 290569a3b17..d64f2d5b595 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -47,7 +47,8 @@ class CurrentUserSerializer < BasicUserSerializer :ignored_users, :title_count_mode, :timezone, - :featured_topic + :featured_topic, + :skip_new_user_tips def groups object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } } @@ -204,6 +205,10 @@ class CurrentUserSerializer < BasicUserSerializer object.user_option.mailing_list_mode end + def skip_new_user_tips + object.user_option.skip_new_user_tips + end + def include_primary_group_id? object.primary_group_id.present? end diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rb index 0187bcc9e9a..fb6091abd9d 100644 --- a/app/serializers/user_option_serializer.rb +++ b/app/serializers/user_option_serializer.rb @@ -30,7 +30,8 @@ class UserOptionSerializer < ApplicationSerializer :text_size, :text_size_seq, :title_count_mode, - :timezone + :timezone, + :skip_new_user_tips def auto_track_topics_after_msecs object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 32446e0395b..8c0149b121e 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -43,7 +43,8 @@ class UserUpdater :hide_profile_and_presence, :text_size, :title_count_mode, - :timezone + :timezone, + :skip_new_user_tips ] def initialize(actor, user) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 46b2680b795..1fd701bacd7 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -930,6 +930,7 @@ en: dismiss_notifications_tooltip: "Mark all unread notifications as read" first_notification: "Your first notification! Select it to begin." dynamic_favicon: "Show counts on browser icon" + skip_new_user_tips: "Skip new user onboarding tips and badges" theme_default_on_all_devices: "Make this the default theme on all my devices" dark_mode: "Dark Mode" dark_mode_enable: "Enable automatic dark mode color scheme" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index cfa0a449f58..ee30f95221f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2157,6 +2157,7 @@ en: default_other_enable_quoting: "Enable quote reply for highlighted text by default." default_other_enable_defer: "Enable defer topic functionality by default." default_other_dynamic_favicon: "Show new/updated topic count on browser icon by default." + default_other_skip_new_user_tips: "Skip new user onboarding tips and badges." default_other_like_notification_frequency: "Notify users on likes by default" diff --git a/config/site_settings.yml b/config/site_settings.yml index a01d6ebf3ac..4a828f21a2c 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -2133,6 +2133,7 @@ user_preferences: default_other_enable_quoting: true default_other_enable_defer: false default_other_dynamic_favicon: false + default_other_skip_new_user_tips: false default_other_like_notification_frequency: enum: "LikeNotificationFrequencySiteSetting" default: 1 diff --git a/db/migrate/20200814081437_add_skip_new_user_tips_to_user_options.rb b/db/migrate/20200814081437_add_skip_new_user_tips_to_user_options.rb new file mode 100644 index 00000000000..68f5d1f4f75 --- /dev/null +++ b/db/migrate/20200814081437_add_skip_new_user_tips_to_user_options.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddSkipNewUserTipsToUserOptions < ActiveRecord::Migration[6.0] + def change + add_column :user_options, :skip_new_user_tips, :boolean, default: false, null: false + end +end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 0bd46c0280d..a4552c70c50 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -159,7 +159,8 @@ def insert_user_options new_topic_duration_minutes, auto_track_topics_after_msecs, notification_level_when_replying, - like_notification_frequency + like_notification_frequency, + skip_new_user_tips ) SELECT u.id , #{SiteSetting.default_email_mailing_list_mode} @@ -179,6 +180,7 @@ def insert_user_options , #{SiteSetting.default_other_auto_track_topics_after_msecs} , #{SiteSetting.default_other_notification_level_when_replying} , #{SiteSetting.default_other_like_notification_frequency} + , #{SiteSetting.default_other_skip_new_user_tips} FROM users u LEFT JOIN user_options uo ON uo.user_id = u.id WHERE uo.user_id IS NULL diff --git a/spec/models/user_option_spec.rb b/spec/models/user_option_spec.rb index 621b585ea93..19a9ab5031d 100644 --- a/spec/models/user_option_spec.rb +++ b/spec/models/user_option_spec.rb @@ -56,6 +56,7 @@ describe UserOption do SiteSetting.default_other_enable_defer = true SiteSetting.default_other_external_links_in_new_tab = true SiteSetting.default_other_dynamic_favicon = true + SiteSetting.default_other_skip_new_user_tips = true user = Fabricate(:user) @@ -63,6 +64,7 @@ describe UserOption do expect(user.user_option.enable_defer).to eq(true) expect(user.user_option.external_links_in_new_tab).to eq(true) expect(user.user_option.dynamic_favicon).to eq(true) + expect(user.user_option.skip_new_user_tips).to eq(true) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fbaa52a4931..52f38a0e925 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1658,6 +1658,7 @@ describe User do SiteSetting.default_other_external_links_in_new_tab = true SiteSetting.default_other_enable_quoting = false SiteSetting.default_other_dynamic_favicon = true + SiteSetting.default_other_skip_new_user_tips = true SiteSetting.default_topics_automatic_unpin = false @@ -1677,6 +1678,7 @@ describe User do expect(options.external_links_in_new_tab).to eq(true) expect(options.enable_quoting).to eq(false) expect(options.dynamic_favicon).to eq(true) + expect(options.skip_new_user_tips).to eq(true) expect(options.automatically_unpin_topics).to eq(false) expect(options.new_topic_duration_minutes).to eq(-1) expect(options.auto_track_topics_after_msecs).to eq(0) diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb index 42a1e1b725d..fe770e4d717 100644 --- a/spec/serializers/user_serializer_spec.rb +++ b/spec/serializers/user_serializer_spec.rb @@ -30,13 +30,14 @@ describe UserSerializer do user = Fabricate.build(:user, id: 1, user_profile: Fabricate.build(:user_profile), - user_option: UserOption.new(dynamic_favicon: true), + user_option: UserOption.new(dynamic_favicon: true, skip_new_user_tips: true), user_stat: UserStat.new ) json = UserSerializer.new(user, scope: Guardian.new(user), root: false).as_json expect(json[:user_option][:dynamic_favicon]).to eq(true) + expect(json[:user_option][:skip_new_user_tips]).to eq(true) expect(json[:user_option][:new_topic_duration_minutes]).to eq(60 * 24) expect(json[:user_option][:auto_track_topics_after_msecs]).to eq(0) expect(json[:user_option][:notification_level_when_replying]).to eq(3) diff --git a/test/javascripts/fixtures/session-fixtures.js b/test/javascripts/fixtures/session-fixtures.js index fe26b20cd6c..d2849bb86cf 100644 --- a/test/javascripts/fixtures/session-fixtures.js +++ b/test/javascripts/fixtures/session-fixtures.js @@ -29,7 +29,8 @@ export default { dismissed_banner_key: null, akismet_review_count: 0, title_count_mode: "notifications", - timezone: "Australia/Brisbane" + timezone: "Australia/Brisbane", + skip_new_user_tips: false } } }; diff --git a/test/javascripts/fixtures/user_fixtures.js b/test/javascripts/fixtures/user_fixtures.js index 242437cfdf7..287bb901b8a 100644 --- a/test/javascripts/fixtures/user_fixtures.js +++ b/test/javascripts/fixtures/user_fixtures.js @@ -176,6 +176,7 @@ export default { new_topic_duration_minutes: 1440, external_links_in_new_tab: false, dynamic_favicon: true, + skip_new_user_tips: false, enable_quoting: true, muted_category_ids: [], tracked_category_ids: [], @@ -2641,6 +2642,7 @@ export default { email_level: 1, external_links_in_new_tab: false, dynamic_favicon: false, + skip_new_user_tips: false, enable_quoting: true, digest_after_minutes: 10080, automatically_unpin_topics: true, @@ -2951,6 +2953,7 @@ export default { email_messages_level: 0, external_links_in_new_tab: false, dynamic_favicon: false, + skip_new_user_tips: false, enable_quoting: true, enable_defer: false, digest_after_minutes: 1440,