FEATURE: Add default site settings to control the defaults of navigation menu preferences (#22485)

Follow-up to b27e12445d

This commit adds 2 new site settings `default_sidebar_link_to_filtered_list` and `default_sidebar_show_count_of_new_items` to control the default values for the navigation menu preferences that were added in the linked commit (`sidebar_link_to_filtered_list` and `sidebar_show_count_of_new_items` respectively).
This commit is contained in:
Osama Sayegh 2023-07-07 04:52:10 +03:00 committed by GitHub
parent bf582290ba
commit d2d6d727de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 1 deletions

View File

@ -69,6 +69,8 @@ const DEFAULT_USER_PREFERENCES = [
"default_title_count_mode",
"default_navigation_menu_categories",
"default_navigation_menu_tags",
"default_sidebar_link_to_filtered_list",
"default_sidebar_show_count_of_new_items",
];
export default Mixin.create({

View File

@ -255,6 +255,8 @@ class Admin::SiteSettingsController < Admin::AdminController
default_text_size: "text_size_key",
default_title_count_mode: "title_count_mode_key",
default_hide_profile_and_presence: "hide_profile_and_presence",
default_sidebar_link_to_filtered_list: "sidebar_link_to_filtered_list",
default_sidebar_show_count_of_new_items: "sidebar_show_count_of_new_items",
}
end

View File

@ -89,6 +89,8 @@ class UserOption < ActiveRecord::Base
self.title_count_mode = SiteSetting.default_title_count_mode
self.hide_profile_and_presence = SiteSetting.default_hide_profile_and_presence
self.sidebar_link_to_filtered_list = SiteSetting.default_sidebar_link_to_filtered_list
self.sidebar_show_count_of_new_items = SiteSetting.default_sidebar_show_count_of_new_items
true
end

View File

@ -2351,6 +2351,8 @@ en:
default_title_count_mode: "Default mode for the page title counter"
enable_offline_indicator: "Display a message to users when it is detected that they have no network connection"
default_sidebar_link_to_filtered_list: "Make navigation menu links link to filtered list by default."
default_sidebar_show_count_of_new_items: "Make navigation menu links show count of new items instead of badges by default."
retain_web_hook_events_period_days: "Number of days to retain web hook event records."
retry_web_hook_events: "Automatically retry failed web hook events for 4 times. Time gaps between the retries are 1, 5, 25 and 125 minutes."

View File

@ -2727,6 +2727,9 @@ user_preferences:
enable_offline_indicator:
default: false
client: true
default_sidebar_link_to_filtered_list: false
default_sidebar_show_count_of_new_items: false
api:
retain_web_hook_events_period_days:
default: 30

View File

@ -166,7 +166,9 @@ def insert_user_options
notification_level_when_replying,
like_notification_frequency,
skip_new_user_tips,
hide_profile_and_presence
hide_profile_and_presence,
sidebar_link_to_filtered_list,
sidebar_show_count_of_new_items
)
SELECT u.id
, #{SiteSetting.default_email_mailing_list_mode}
@ -188,6 +190,8 @@ def insert_user_options
, #{SiteSetting.default_other_like_notification_frequency}
, #{SiteSetting.default_other_skip_new_user_tips}
, #{SiteSetting.default_hide_profile_and_presence}
, #{SiteSetting.default_sidebar_link_to_filtered_list}
, #{SiteSetting.default_sidebar_show_count_of_new_items}
FROM users u
LEFT JOIN user_options uo ON uo.user_id = u.id
WHERE uo.user_id IS NULL

View File

@ -44,6 +44,30 @@ RSpec.describe UserOption do
expect(user.user_option.email_digests).to eq(false)
expect(user.user_option.digest_after_minutes).to eq(0)
end
it "should correctly set sidebar_link_to_filtered_list when `default_sidebar_link_to_filtered_list` site setting is enabled" do
SiteSetting.default_sidebar_link_to_filtered_list = true
user = Fabricate(:user)
expect(user.user_option.sidebar_link_to_filtered_list).to eq(true)
end
it "should correctly set sidebar_link_to_filtered_list when `default_sidebar_link_to_filtered_list` site setting is disabled" do
SiteSetting.default_sidebar_link_to_filtered_list = false
user = Fabricate(:user)
expect(user.user_option.sidebar_link_to_filtered_list).to eq(false)
end
it "should correctly set sidebar_show_count_of_new_items when `default_sidebar_show_count_of_new_items` site setting is enabled" do
SiteSetting.default_sidebar_show_count_of_new_items = true
user = Fabricate(:user)
expect(user.user_option.sidebar_show_count_of_new_items).to eq(true)
end
it "should correctly set sidebar_show_count_of_new_items when `default_sidebar_show_count_of_new_items` site setting is disabled" do
SiteSetting.default_sidebar_show_count_of_new_items = false
user = Fabricate(:user)
expect(user.user_option.sidebar_show_count_of_new_items).to eq(false)
end
end
describe "site settings" do