DEV: Sidebar default tags and categories are determined at user creation (#18620)

The previous sidebar default tags and categories implementation did not
allow for a user to configure their sidebar to have no categories or
tags. This commit changes how the defaults are applied. When a user is being created,
we create the SidebarSectionLink records based on the `default_sidebar_categories` and
`default_sidebar_tags` site settings. SidebarSectionLink records are
only created for categories and tags which the user has visibility on at
the point of user creation.

With this change, we're also adding the ability for admins to apply
changes to the `default_sidebar_categories` and `default_sidebar_tags`
site settings historically when changing their site setting. When a new
category/tag has been added to the default, the new category/tag will be
added to the sidebar for all users if the admin elects to apply the changes historically.
Like wise when a tag/category is removed, the tag/category will be
removed from the sidebar for all users if the admin elects to apply the
changes historically.

Internal Ref: /t/73500
This commit is contained in:
Alan Guo Xiang Tan
2022-10-27 06:38:50 +08:00
committed by GitHub
parent a473e352de
commit 1b56a55f50
14 changed files with 637 additions and 107 deletions

View File

@ -23,9 +23,11 @@ class Admin::SiteSettingsController < Admin::AdminController
if !override
raise Discourse::InvalidParameters, "You cannot change this site setting because it is deprecated, use #{new_name} instead."
end
break new_name
end
end
id = new_setting_name if new_setting_name
raise_access_hidden_setting(id)
@ -101,6 +103,8 @@ class Admin::SiteSettingsController < Admin::AdminController
TagUser.insert_all!(tag_users)
end
end
elsif is_sidebar_default_setting?(id)
Jobs.enqueue(:backfill_sidebar_site_settings, setting_name: id, previous_value: previous_value, new_value: new_value)
end
end
@ -159,6 +163,8 @@ class Admin::SiteSettingsController < Admin::AdminController
.pluck("users.id")
json[:user_count] = user_ids.uniq.count
elsif is_sidebar_default_setting?(id)
json[:user_count] = SidebarSiteSettingsBackfiller.new(id, previous_value: previous_value, new_value: new_value).number_of_users_to_backfill
end
render json: json
@ -166,6 +172,10 @@ class Admin::SiteSettingsController < Admin::AdminController
private
def is_sidebar_default_setting?(setting_name)
%w{default_sidebar_categories default_sidebar_tags}.include?(setting_name.to_s)
end
def user_options
{
default_email_mailing_list_mode: "mailing_list_mode",