FIX: Update sidebar to be navigation menu (#22101)

Communities can use sidebar or header dropdown, therefore navigation menu is a better name settings in 2 places:

- Old user sidebar preferences;
- Site setting about default tags and categories.
This commit is contained in:
Krzysztof Kotlarek 2023-06-15 09:31:28 +10:00 committed by GitHub
parent be7d82d2b0
commit 2effcaa0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 171 additions and 144 deletions

View File

@ -67,8 +67,8 @@ const DEFAULT_USER_PREFERENCES = [
"default_tags_watching_first_post",
"default_text_size",
"default_title_count_mode",
"default_sidebar_categories",
"default_sidebar_tags",
"default_navigation_menu_categories",
"default_navigation_menu_tags",
];
export default Mixin.create({

View File

@ -6,15 +6,15 @@ export default class SidebarAnonymousCategoriesSection extends SidebarCommonCate
constructor() {
super(...arguments);
if (!this.siteSettings.default_sidebar_categories) {
if (!this.siteSettings.default_navigation_menu_categories) {
this.shouldSortCategoriesByDefault = false;
}
}
get categories() {
if (this.siteSettings.default_sidebar_categories) {
if (this.siteSettings.default_navigation_menu_categories) {
return Category.findByIds(
this.siteSettings.default_sidebar_categories
this.siteSettings.default_navigation_menu_categories
.split("|")
.map((categoryId) => parseInt(categoryId, 10))
);

View File

@ -10,7 +10,7 @@ export default class SidebarAnonymousTagsSection extends Component {
get displaySection() {
return (
this.site.anonymous_default_sidebar_tags?.length > 0 ||
this.site.anonymous_default_navigation_menu_tags?.length > 0 ||
this.site.top_tags?.length > 0
);
}
@ -19,8 +19,8 @@ export default class SidebarAnonymousTagsSection extends Component {
get sectionLinks() {
let tags;
if (this.site.anonymous_default_sidebar_tags) {
tags = this.site.anonymous_default_sidebar_tags;
if (this.site.anonymous_default_navigation_menu_tags) {
tags = this.site.anonymous_default_navigation_menu_tags;
} else {
tags = this.site.top_tags.slice(0, 5);
}

View File

@ -50,7 +50,7 @@
{{else}}
<Sidebar::SectionLink
@linkName="configure-categories"
@route="preferences.sidebar"
@route="preferences.navigation-menu"
@prefixType="icon"
@prefixValue="pencil-alt"
@model={{this.currentUser}}
@ -68,13 +68,13 @@
{{#if this.shouldDisplayDefaultConfig}}
<Sidebar::SectionLink
@linkName="configure-default-sidebar-categories"
@linkName="configure-default-navigation-menu-categories"
@content={{i18n "sidebar.sections.categories.configure_defaults"}}
@prefixType="icon"
@prefixValue="wrench"
@route="adminSiteSettingsCategory"
@model="sidebar"
@query={{hash filter="default_sidebar_categories"}}
@query={{hash filter="default_navigation_menu_categories"}}
/>
{{/if}}
</Sidebar::Section>

View File

@ -70,7 +70,7 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
}
get hasDefaultSidebarCategories() {
return this.siteSettings.default_sidebar_categories.length > 0;
return this.siteSettings.default_navigation_menu_categories.length > 0;
}
@action
@ -80,7 +80,7 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
) {
showModal("sidebar-categories-form");
} else {
this.router.transitionTo("preferences.sidebar", this.currentUser);
this.router.transitionTo("preferences.navigation-menu", this.currentUser);
}
}
}

View File

@ -34,7 +34,7 @@
{{else}}
<Sidebar::SectionLink
@linkName="configure-tags"
@route="preferences.sidebar"
@route="preferences.navigation-menu"
@prefixType="icon"
@prefixValue="pencil-alt"
@model={{this.currentUser}}
@ -54,7 +54,7 @@
@prefixValue="wrench"
@route="adminSiteSettingsCategory"
@model="sidebar"
@query={{hash filter="default_sidebar_tags"}}
@query={{hash filter="default_navigation_menu_tags"}}
/>
{{/if}}
</Sidebar::Section>

View File

@ -74,11 +74,11 @@ export default class SidebarUserTagsSection extends Component {
}
get hasDefaultSidebarTags() {
return this.siteSettings.default_sidebar_tags.length > 0;
return this.siteSettings.default_navigation_menu_tags.length > 0;
}
@action
editTracked() {
this.router.transitionTo("preferences.sidebar", this.currentUser);
this.router.transitionTo("preferences.navigation-menu", this.currentUser);
}
}

View File

@ -12,7 +12,7 @@ export default class extends Controller {
@tracked saved = false;
@tracked selectedSidebarCategories = [];
@tracked selectedSidebarTagNames = [];
subpageTitle = I18n.t("user.preferences_nav.sidebar");
subpageTitle = I18n.t("user.preferences_nav.navigation_menu");
saveAttrNames = [
"sidebar_category_ids",

View File

@ -2,7 +2,7 @@ import I18n from "I18n";
import { tracked } from "@glimmer/tracking";
import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu";
export default class EverythingSectionLink extends BaseSectionLink {
@tracked totalUnread = 0;

View File

@ -5,7 +5,7 @@ import { get, set } from "@ember/object";
import { bind } from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu";
const UNREAD_AND_NEW_COUNTABLE = {
propertyName: "unreadAndNewCount",

View File

@ -2,7 +2,7 @@ import I18n from "I18n";
import { tracked } from "@glimmer/tracking";
import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu";
const USER_DRAFTS_CHANGED_EVENT = "user-drafts:changed";

View File

@ -4,7 +4,7 @@ import { tracked } from "@glimmer/tracking";
import { bind } from "discourse-common/utils/decorators";
import BaseTagSectionLink from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu";
export default class TagSectionLink extends BaseTagSectionLink {
@tracked totalUnread = 0;

View File

@ -175,7 +175,7 @@ export default function () {
this.route("tags");
this.route("interface");
this.route("apps");
this.route("sidebar");
this.route("navigation-menu");
this.route("email");
this.route("second-factor");

View File

@ -78,12 +78,12 @@
{{#if (not (eq this.siteSettings.navigation_menu "legacy"))}}
<DNavigationItem
@route="preferences.sidebar"
@class="user-nav__preferences-sidebar"
@route="preferences.navigation-menu"
@class="user-nav__preferences-navigation-menu"
@ariaCurrentContext="subNav"
>
{{d-icon "bars"}}
<span>{{i18n "user.preferences_nav.sidebar"}}</span>
<span>{{i18n "user.preferences_nav.navigation_menu"}}</span>
</DNavigationItem>
{{/if}}

View File

@ -1,4 +1,4 @@
<div class="control-group preferences-sidebar-categories">
<div class="control-group preferences-navigation-menu-categories">
<legend class="control-label">{{i18n
"user.experimental_sidebar.categories_section"
}}</legend>
@ -20,7 +20,7 @@
</div>
{{#if this.model.display_sidebar_tags}}
<div class="control-group preferences-sidebar-tags">
<div class="control-group preferences-navigation-menu-tags">
<legend class="control-label">{{i18n
"user.experimental_sidebar.tags_section"
}}</legend>
@ -41,7 +41,7 @@
</div>
{{/if}}
<div class="control-group preferences-sidebar-navigation">
<div class="control-group preferences-navigation-menu-navigation">
<legend class="control-label">{{i18n
"user.experimental_sidebar.navigation_section"
}}</legend>
@ -51,7 +51,7 @@
"user.experimental_sidebar.list_destination_instruction"
}}</label>
<ComboBox
@class="preferences-sidebar-navigation__list-destination-selector"
@class="preferences-navigation-menu-navigation__list-destination-selector"
@valueProperty="value"
@content={{this.sidebarListDestinations}}
@value={{this.newSidebarListDestination}}

View File

@ -12,7 +12,7 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) {
navigation_menu: "sidebar",
});
test("category section links ordered by category's topic count when default_sidebar_categories has not been configured and site setting to fix categories positions is disabled", async function (assert) {
test("category section links ordered by category's topic count when default_navigation_menu_categories has not been configured and site setting to fix categories positions is disabled", async function (assert) {
this.siteSettings.fixed_category_positions = false;
await visit("/");
@ -58,7 +58,7 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) {
);
});
test("category section links ordered by default category's position when default_sidebar_categories has not been configured and site setting to fix categories positions is enabled", async function (assert) {
test("category section links ordered by default category's position when default_navigation_menu_categories has not been configured and site setting to fix categories positions is enabled", async function (assert) {
this.siteSettings.fixed_category_positions = true;
await visit("/");
@ -102,9 +102,9 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) {
);
});
test("category section links in sidebar when default_sidebar_categories site setting has been configured and site setting to fix category position is enabled", async function (assert) {
test("category section links in sidebar when default_navigation_menu_categories site setting has been configured and site setting to fix category position is enabled", async function (assert) {
this.siteSettings.fixed_category_positions = true;
this.siteSettings.default_sidebar_categories = "1|3|13";
this.siteSettings.default_navigation_menu_categories = "1|3|13";
await visit("/");

View File

@ -38,7 +38,7 @@ acceptance("Sidebar - Anonymous Tags Section", function (needs) {
test("tag section links when site has default sidebar tags configured", async function (assert) {
const site = Site.current();
site.set("anonymous_default_sidebar_tags", ["random", "meta"]);
site.set("anonymous_default_navigation_menu_tags", ["random", "meta"]);
await visit("/");
@ -71,7 +71,7 @@ acceptance("Sidebar - Anonymous Tags Section", function (needs) {
site.setProperties({
top_tags: [],
anonymous_default_sidebar_tags: [],
anonymous_default_navigation_menu_tags: [],
});
await visit("/");

View File

@ -16,7 +16,7 @@ import {
resetCustomCountables,
} from "discourse/lib/sidebar/user/categories-section/category-section-link";
import { resetCustomTagSectionLinkPrefixIcons } from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu";
import { bind } from "discourse-common/utils/decorators";
acceptance("Sidebar - Plugin API", function (needs) {

View File

@ -137,8 +137,8 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
assert.strictEqual(
currentURL(),
"/u/eviltrout/preferences/sidebar",
"it should transition to user preferences sidebar page"
"/u/eviltrout/preferences/navigation-menu",
"it should transition to user preferences navigation menu page"
);
});
@ -156,7 +156,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
test("categories section is shown when user has not added any categories but default categories have been configured", async function (assert) {
updateCurrentUser({ sidebar_category_ids: [] });
const categories = Site.current().categories;
this.siteSettings.default_sidebar_categories = `${categories[0].id}|${categories[1].id}`;
this.siteSettings.default_navigation_menu_categories = `${categories[0].id}|${categories[1].id}`;
await visit("/");
@ -178,8 +178,8 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
assert.strictEqual(
currentURL(),
"/u/eviltrout/preferences/sidebar",
"it should transition to user preferences sidebar page"
"/u/eviltrout/preferences/navigation-menu",
"it should transition to user preferences navigation menu page"
);
});
@ -974,18 +974,18 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
assert.ok(
exists(
".sidebar-section-link[data-link-name='configure-default-sidebar-categories']"
".sidebar-section-link[data-link-name='configure-default-navigation-menu-categories']"
),
"section link to configure default sidebar categories is shown"
"section link to configure default navigation menu categories is shown"
);
await click(
".sidebar-section-link[data-link-name='configure-default-sidebar-categories']"
".sidebar-section-link[data-link-name='configure-default-navigation-menu-categories']"
);
assert.strictEqual(
currentURL(),
"/admin/site_settings/category/all_results?filter=default_sidebar_categories",
"/admin/site_settings/category/all_results?filter=default_navigation_menu_categories",
"it links to the admin site settings page correctly"
);
});

View File

@ -110,8 +110,8 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
assert.strictEqual(
currentURL(),
"/u/eviltrout/preferences/sidebar",
"it should transition to user preferences sidebar page"
"/u/eviltrout/preferences/navigation-menu",
"it should transition to user preferences navigation menu page"
);
});
@ -133,7 +133,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
sidebar_tags: [],
});
this.siteSettings.default_sidebar_tags = "tag1|tag2";
this.siteSettings.default_navigation_menu_tags = "tag1|tag2";
await visit("/");
@ -155,8 +155,8 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
assert.strictEqual(
currentURL(),
"/u/eviltrout/preferences/sidebar",
"it should transition to user preferences sidebar page"
"/u/eviltrout/preferences/navigation-menu",
"it should transition to user preferences navigation menu page"
);
});
@ -693,7 +693,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
assert.strictEqual(
currentURL(),
"/admin/site_settings/category/all_results?filter=default_sidebar_tags",
"/admin/site_settings/category/all_results?filter=default_navigation_menu_tags",
"it links to the admin site settings page correctly"
);
});

View File

@ -9,7 +9,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("User Preferences - Sidebar", function (needs) {
acceptance("User Preferences - Navigation Menu", function (needs) {
needs.user({
sidebar_category_ids: [],
sidebar_tags: [],
@ -110,7 +110,7 @@ acceptance("User Preferences - Sidebar", function (needs) {
test("user adding categories to sidebar when default sidebar categories have not been configured", async function (assert) {
updateCurrentUser({ admin: false, display_sidebar_tags: false });
await visit("/u/eviltrout/preferences/sidebar");
await visit("/u/eviltrout/preferences/navigation-menu");
assert.notOk(exists(".sidebar-section[data-section-name='categories']"));
@ -137,7 +137,7 @@ acceptance("User Preferences - Sidebar", function (needs) {
});
test("user adding categories to sidebar when default sidebar categories have been configured", async function (assert) {
this.siteSettings.default_sidebar_categories = "5";
this.siteSettings.default_navigation_menu_categories = "5";
await visit("/");
await click(
@ -223,13 +223,13 @@ acceptance("User Preferences - Sidebar", function (needs) {
test("user should not see tag chooser when display_sidebar_tags property is false", async function (assert) {
updateCurrentUser({ display_sidebar_tags: false });
await visit("/u/eviltrout/preferences/sidebar");
await visit("/u/eviltrout/preferences/navigation-menu");
assert.ok(!exists(".tag-chooser"), "tag chooser is not displayed");
});
test("user adding tags to sidebar when default tags have not been configured", async function (assert) {
await visit("/u/eviltrout/preferences/sidebar");
await visit("/u/eviltrout/preferences/navigation-menu");
const tagChooser = selectKit(".tag-chooser");
await tagChooser.expand();
@ -246,7 +246,7 @@ acceptance("User Preferences - Sidebar", function (needs) {
});
test("user adding tags to sidebar when default tags have been configured", async function (assert) {
this.siteSettings.default_sidebar_tags = "tag1|tag2";
this.siteSettings.default_navigation_menu_tags = "tag1|tag2";
await visit("/");
await click(

View File

@ -229,7 +229,7 @@ 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)
%w[default_navigation_menu_categories default_navigation_menu_tags].include?(setting_name.to_s)
end
def user_options

View File

@ -2065,8 +2065,8 @@ class User < ActiveRecord::Base
return if SiteSetting.legacy_navigation_menu?
return if staged? || bot?
if SiteSetting.default_sidebar_categories.present?
categories_to_update = SiteSetting.default_sidebar_categories.split("|")
if SiteSetting.default_navigation_menu_categories.present?
categories_to_update = SiteSetting.default_navigation_menu_categories.split("|")
if update
filtered_default_category_ids =
@ -2084,8 +2084,8 @@ class User < ActiveRecord::Base
)
end
if SiteSetting.tagging_enabled && SiteSetting.default_sidebar_tags.present?
tags_to_update = SiteSetting.default_sidebar_tags.split("|")
if SiteSetting.tagging_enabled && SiteSetting.default_navigation_menu_tags.present?
tags_to_update = SiteSetting.default_navigation_menu_tags.split("|")
if update
default_tag_ids = Tag.where(name: tags_to_update).pluck(:id)

View File

@ -37,7 +37,7 @@ class SiteSerializer < ApplicationSerializer
:hashtag_configurations,
:hashtag_icons,
:displayed_about_plugin_stat_groups,
:anonymous_default_sidebar_tags,
:anonymous_default_navigation_menu_tags,
:anonymous_sidebar_sections,
:whispers_allowed_groups_names,
:denied_emojis,
@ -250,13 +250,13 @@ class SiteSerializer < ApplicationSerializer
About.displayed_plugin_stat_groups
end
def anonymous_default_sidebar_tags
SiteSetting.default_sidebar_tags.split("|") - DiscourseTagging.hidden_tag_names(scope)
def anonymous_default_navigation_menu_tags
SiteSetting.default_navigation_menu_tags.split("|") - DiscourseTagging.hidden_tag_names(scope)
end
def include_anonymous_default_sidebar_tags?
def include_anonymous_default_navigation_menu_tags?
scope.anonymous? && !SiteSetting.legacy_navigation_menu? && SiteSetting.tagging_enabled &&
SiteSetting.default_sidebar_tags.present?
SiteSetting.default_navigation_menu_tags.present?
end
def anonymous_sidebar_sections

View File

@ -13,9 +13,9 @@ class SidebarSiteSettingsBackfiller
@linkable_klass, previous_ids, new_ids =
case setting_name
when "default_sidebar_categories"
when "default_navigation_menu_categories"
[Category, previous_value.split("|"), new_value.split("|")]
when "default_sidebar_tags"
when "default_navigation_menu_tags"
klass = Tag
[

View File

@ -1207,11 +1207,11 @@ en:
enable: "Enable sidebar"
options: "Options"
categories_section: "Categories Section"
categories_section_instruction: "Selected categories will be displayed under Sidebar's categories section."
categories_section_instruction: "Selected categories will be displayed under Navigation Menu's categories section."
tags_section: "Tags Section"
tags_section_instruction: "Selected tags will be displayed under Sidebar's tags section."
tags_section_instruction: "Selected tags will be displayed under Navigation Menu's tags section."
navigation_section: "Navigation"
list_destination_instruction: "When there's new content in the sidebar..."
list_destination_instruction: "When there's new content in the navigation menu..."
list_destination_default: "use the default link and show a badge for new items"
list_destination_unread_new: "link to unread/new and show a count of new items"
change: "change"
@ -1408,7 +1408,7 @@ en:
tags: "Tags"
interface: "Interface"
apps: "Apps"
sidebar: "Sidebar"
navigation_menu: "Navigation Menu"
change_password:
success: "(email sent)"

View File

@ -2424,8 +2424,8 @@ en:
splash_screen: "Displays a temporary loading screen while site assets load"
navigation_menu: "Determine which navigation menu to use. Sidebar and header navigation are customizable by users. Legacy option is available for backward compatibility."
default_sidebar_categories: "Selected categories will be displayed under Sidebar's Categories section by default."
default_sidebar_tags: "Selected tags will be displayed under Sidebar's Tags section by default."
default_navigation_menu_categories: "Selected categories will be displayed under Navigation Menu's Categories section by default."
default_navigation_menu_tags: "Selected tags will be displayed under Navigation Menu's Tags section by default."
enable_experimental_hashtag_autocomplete: "EXPERIMENTAL: Use the new #hashtag autocompletion system for categories and tags that renders the selected item differently and has improved search"
experimental_new_new_view_groups: 'EXPERIMENTAL: Enable a new topics list that combines unread and new topics and make the "Everything" link in the sidebar link to it.'
enable_custom_sidebar_sections: "EXPERIMENTAL: Enable custom sidebar sections"

View File

@ -650,7 +650,7 @@ Discourse::Application.routes.draw do
:constraints => {
username: RouteFormat.username,
}
get "#{root_path}/:username/preferences/sidebar" => "users#preferences",
get "#{root_path}/:username/preferences/navigation-menu" => "users#preferences",
:constraints => {
username: RouteFormat.username,
}

View File

@ -2128,11 +2128,11 @@ navigation:
default: "sidebar"
type: enum
enum: "NavigationMenuSiteSetting"
default_sidebar_categories:
default_navigation_menu_categories:
type: category_list
default: ""
client: true
default_sidebar_tags:
default_navigation_menu_tags:
type: tag_list
default: ""
client: true

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class RenameDefaultSidebarCategoriesSetting < ActiveRecord::Migration[7.0]
def change
execute "UPDATE site_settings SET name = 'default_navigation_menu_categories' WHERE name = 'default_sidebar_categories'"
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class RenameDefaultSidebarTagsSetting < ActiveRecord::Migration[7.0]
def change
execute "UPDATE site_settings SET name = 'default_navigation_menu_tags' WHERE name = 'default_sidebar_tags'"
end
end

View File

@ -138,9 +138,9 @@ module SeedData
SiteSetting.set(site_setting_name, category.id)
if sidebar
sidebar_categories = SiteSetting.default_sidebar_categories.split("|")
sidebar_categories = SiteSetting.default_navigation_menu_categories.split("|")
sidebar_categories << category.id
SiteSetting.set("default_sidebar_categories", sidebar_categories.join("|"))
SiteSetting.set("default_navigation_menu_categories", sidebar_categories.join("|"))
end
SiteSetting.set("default_composer_category", category.id) if default_composer_category

View File

@ -118,14 +118,14 @@ RSpec.describe SeedData::Categories do
expect(category.category_groups.first).to have_attributes(permissions(:staff, :full))
end
it "adds default categories SiteSetting.default_sidebar_categories" do
it "adds default categories SiteSetting.default_navigation_menu_categories" do
create_category("staff_category_id")
staff_category = Category.last
create_category("meta_category_id")
site_feedback_category = Category.last
create_category("general_category_id")
general_category = Category.last
site_setting_ids = SiteSetting.default_sidebar_categories.split("|")
site_setting_ids = SiteSetting.default_navigation_menu_categories.split("|")
create_category("uncategorized_category_id")
expect(site_setting_ids[0].to_i).to eq(staff_category.id)

View File

@ -48,8 +48,8 @@ RSpec.describe User do
before do
SiteSetting.navigation_menu = "sidebar"
SiteSetting.tagging_enabled = true
SiteSetting.default_sidebar_categories = "#{category.id}|#{secured_category.id}"
SiteSetting.default_sidebar_tags = "#{tag.name}|#{hidden_tag.name}"
SiteSetting.default_navigation_menu_categories = "#{category.id}|#{secured_category.id}"
SiteSetting.default_navigation_menu_tags = "#{tag.name}|#{hidden_tag.name}"
end
it "creates the right sidebar section link records for categories and tags that a user can see" do

View File

@ -92,24 +92,24 @@ RSpec.describe Admin::SiteSettingsController do
end
context "for sidebar defaults" do
it "returns the right count for the default_sidebar_categories site setting" do
it "returns the right count for the default_navigation_menu_categories site setting" do
category = Fabricate(:category)
put "/admin/site_settings/default_sidebar_categories/user_count.json",
put "/admin/site_settings/default_navigation_menu_categories/user_count.json",
params: {
default_sidebar_categories: "#{category.id}",
default_navigation_menu_categories: "#{category.id}",
}
expect(response.status).to eq(200)
expect(response.parsed_body["user_count"]).to eq(User.real.not_staged.count)
end
it "returns the right count for the default_sidebar_tags site setting" do
it "returns the right count for the default_navigation_menu_tags site setting" do
tag = Fabricate(:tag)
put "/admin/site_settings/default_sidebar_tags/user_count.json",
put "/admin/site_settings/default_navigation_menu_tags/user_count.json",
params: {
default_sidebar_tags: "#{tag.name}",
default_navigation_menu_tags: "#{tag.name}",
}
expect(response.status).to eq(200)
@ -319,32 +319,32 @@ RSpec.describe Admin::SiteSettingsController do
end
end
context "when updating default sidebar categories and tags" do
context "when updating default navigation menu categories and tags" do
it "does not enqueue the backfilling job if update_existing_user param is not present" do
expect_not_enqueued_with(job: :backfill_sidebar_site_settings) do
put "/admin/site_settings/default_sidebar_categories.json",
put "/admin/site_settings/default_navigation_menu_categories.json",
params: {
default_sidebar_categories: "1|2",
default_navigation_menu_categories: "1|2",
}
expect(response.status).to eq(200)
end
end
it "enqueues the backfilling job if update_existing_user param is present when updating default sidebar tags" do
SiteSetting.default_sidebar_tags = "tag3"
it "enqueues the backfilling job if update_existing_user param is present when updating default navigation menu tags" do
SiteSetting.default_navigation_menu_tags = "tag3"
expect_enqueued_with(
job: :backfill_sidebar_site_settings,
args: {
setting_name: "default_sidebar_tags",
setting_name: "default_navigation_menu_tags",
new_value: "tag1|tag2",
previous_value: "tag3",
},
) do
put "/admin/site_settings/default_sidebar_tags.json",
put "/admin/site_settings/default_navigation_menu_tags.json",
params: {
default_sidebar_tags: "tag1|tag2",
default_navigation_menu_tags: "tag1|tag2",
update_existing_user: true,
}
@ -352,20 +352,20 @@ RSpec.describe Admin::SiteSettingsController do
end
end
it "enqueues the backfilling job if update_existing_user param is present when updating default sidebar categories" do
SiteSetting.default_sidebar_categories = "3|4"
it "enqueues the backfilling job if update_existing_user param is present when updating default navigation_menu categories" do
SiteSetting.default_navigation_menu_categories = "3|4"
expect_enqueued_with(
job: :backfill_sidebar_site_settings,
args: {
setting_name: "default_sidebar_categories",
setting_name: "default_navigation_menu_categories",
new_value: "1|2",
previous_value: "3|4",
},
) do
put "/admin/site_settings/default_sidebar_categories.json",
put "/admin/site_settings/default_navigation_menu_categories.json",
params: {
default_sidebar_categories: "1|2",
default_navigation_menu_categories: "1|2",
update_existing_user: true,
}

View File

@ -131,7 +131,7 @@ RSpec.describe SiteSerializer do
expect(serialized[:shared_drafts_category_id]).to eq(nil)
end
describe "#anonymous_default_sidebar_tags" do
describe "#anonymous_default_navigation_menu_tags" do
fab!(:user) { Fabricate(:user) }
fab!(:tag) { Fabricate(:tag, name: "dev") }
fab!(:tag2) { Fabricate(:tag, name: "random") }
@ -143,7 +143,7 @@ RSpec.describe SiteSerializer do
before do
SiteSetting.navigation_menu = "sidebar"
SiteSetting.tagging_enabled = true
SiteSetting.default_sidebar_tags = "#{tag.name}|#{tag2.name}|#{hidden_tag.name}"
SiteSetting.default_navigation_menu_tags = "#{tag.name}|#{tag2.name}|#{hidden_tag.name}"
end
it "is not included in the serialised object when tagging is not enabled" do
@ -151,33 +151,33 @@ RSpec.describe SiteSerializer do
guardian = Guardian.new(user)
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil)
end
it "is not included in the serialised object when navigation menu is legacy" do
SiteSetting.navigation_menu = "legacy"
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil)
end
it "is not included in the serialised object when user is not anonymous" do
guardian = Guardian.new(user)
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil)
end
it "is not included in the serialisd object when default sidebar tags have not been configured" do
SiteSetting.default_sidebar_tags = ""
SiteSetting.default_navigation_menu_tags = ""
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil)
end
it "includes only tags user can see in the serialised object when user is anonymous" do
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:anonymous_default_sidebar_tags]).to eq(%w[dev random])
expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(%w[dev random])
end
end

View File

@ -59,11 +59,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do
end
describe "#backfill!" do
context "for default_sidebar_categories setting" do
context "for default_navigation_menu_categories setting" do
it "deletes the right sidebar section link records when categories are removed" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "#{category.id}|#{category2.id}|#{category3.id}",
new_value: "#{category3.id}",
)
@ -76,7 +76,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "creates the right sidebar section link records when categories are added" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "#{category.id}|#{category2.id}",
new_value: "#{category.id}|#{category2.id}|#{category3.id}",
)
@ -93,7 +93,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "creates the right sidebar section link records when categories are added" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "",
new_value: "#{category.id}|#{category2.id}|#{category3.id}",
)
@ -122,7 +122,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "deletes and creates the right sidebar section link records when categories are added and removed" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "#{category.id}|#{category2.id}",
new_value: "#{category3.id}",
)
@ -150,11 +150,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do
end
end
context "for default_sidebar_tags setting" do
context "for default_navigation_menu_tags setting" do
it "deletes the right sidebar section link records when tags are removed" do
backfiller =
described_class.new(
"default_sidebar_tags",
"default_navigation_menu_tags",
previous_value: "#{tag.name}|#{tag2.name}|#{tag3.name}",
new_value: "#{tag3.name}",
)
@ -167,7 +167,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "creates the right sidebar section link records when tags are added" do
backfiller =
described_class.new(
"default_sidebar_tags",
"default_navigation_menu_tags",
previous_value: "#{tag.name}|#{tag2.name}",
new_value: "#{tag.name}|#{tag2.name}|#{tag3.name}",
)
@ -182,7 +182,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "deletes and creates the right sidebar section link records when tags are added and removed" do
backfiller =
described_class.new(
"default_sidebar_tags",
"default_navigation_menu_tags",
previous_value: "#{tag.name}|#{tag2.name}",
new_value: "#{tag3.name}",
)
@ -207,11 +207,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do
end
describe "#number_of_users_to_backfill" do
context "for default_sidebar_categories setting" do
context "for default_navigation_menu_categories setting" do
it "returns 3 for the user count when a new category for all users is added" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "",
new_value: "#{category3.id}",
)
@ -222,7 +222,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "returns 2 for the user count when category which 2 users have configured in sidebar is removed" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "#{category.id}|#{category2.id}",
new_value: "#{category2.id}",
)
@ -234,7 +234,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "returns 3 for the user count when a new category is added and a category is removed" do
backfiller =
described_class.new(
"default_sidebar_categories",
"default_navigation_menu_categories",
previous_value: "#{category.id}|#{category2.id}",
new_value: "#{category2.id}|#{category3.id}",
)
@ -244,16 +244,24 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "returns 0 for the user count when no new category is added or removed" do
backfiller =
described_class.new("default_sidebar_categories", previous_value: "", new_value: "")
described_class.new(
"default_navigation_menu_categories",
previous_value: "",
new_value: "",
)
expect(backfiller.number_of_users_to_backfill).to eq(0)
end
end
context "for default_sidebar_tags setting" do
context "for default_navigation_menu_tags setting" do
it "returns 3 for the user count when a new tag for all users is added" do
backfiller =
described_class.new("default_sidebar_tags", previous_value: "", new_value: "#{tag3.name}")
described_class.new(
"default_navigation_menu_tags",
previous_value: "",
new_value: "#{tag3.name}",
)
expect(backfiller.number_of_users_to_backfill).to eq(3)
end
@ -262,7 +270,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "returns 2 for the user count when tag which 2 users have configured in sidebar is removed" do
backfiller =
described_class.new(
"default_sidebar_tags",
"default_navigation_menu_tags",
previous_value: "#{tag.name}|#{tag2.name}",
new_value: "#{tag2.name}",
)
@ -274,7 +282,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do
it "returns 3 for the user count when a new tag is added and a tag is removed" do
backfiller =
described_class.new(
"default_sidebar_tags",
"default_navigation_menu_tags",
previous_value: "#{tag.name}|#{tag2.name}",
new_value: "#{tag2.name}|#{tag3.name}",
)

View File

@ -22,7 +22,7 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
before do
SiteSetting.new_edit_sidebar_categories_tags_interface_groups = group.name
SiteSetting.default_sidebar_categories = "#{category.id}|#{category2.id}"
SiteSetting.default_navigation_menu_categories = "#{category.id}|#{category2.id}"
sign_in(user)
end

View File

@ -2,26 +2,26 @@
module PageObjects
module Pages
class UserPreferencesSidebar < PageObjects::Pages::Base
class UserPreferencesNavigationMenu < PageObjects::Pages::Base
def visit(user)
page.visit("/u/#{user.username}/preferences/sidebar")
page.visit("/u/#{user.username}/preferences/navigation-menu")
self
end
def has_sidebar_categories_preference?(*categories)
def has_navigation_menu_categories_preference?(*categories)
category_selector_header = page.find(".category-selector .select-kit-header-wrapper")
category_selector_header.has_content?(categories.map(&:name).join(", "))
end
def has_sidebar_tags_preference?(*tags)
def has_navigation_menu_tags_preference?(*tags)
tag_selector_header = page.find(".tag-chooser .select-kit-header-wrapper")
tag_selector_header.has_content?(tags.map(&:name).join(", "))
end
def has_sidebar_list_destination_preference?(type)
def has_navigation_menu_list_destination_preference?(type)
list_selector_header =
page.find(
".preferences-sidebar-navigation__list-destination-selector .select-kit-header-wrapper",
".preferences-navigation-menu-navigation__list-destination-selector .select-kit-header-wrapper",
)
list_selector_header.has_content?(
I18n.t("js.user.experimental_sidebar.list_destination_#{type}"),

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
describe "Viewing sidebar preferences", type: :system do
let(:user_preferences_sidebar_page) { PageObjects::Pages::UserPreferencesSidebar.new }
let(:user_preferences_navigation_menu_page) do
PageObjects::Pages::UserPreferencesNavigationMenu.new
end
before { SiteSetting.navigation_menu = "sidebar" }
@ -27,19 +29,22 @@ describe "Viewing sidebar preferences", type: :system do
before { sign_in(admin) }
it "should be able to view sidebar preferences of another user" do
it "should be able to view navigation menu preferences of another user" do
user.user_option.update!(sidebar_list_destination: "unread_new")
user_preferences_sidebar_page.visit(user)
user_preferences_navigation_menu_page.visit(user)
expect(user_preferences_sidebar_page).to have_sidebar_categories_preference(
expect(user_preferences_navigation_menu_page).to have_navigation_menu_categories_preference(
category,
category2,
)
expect(user_preferences_sidebar_page).to have_sidebar_tags_preference(tag, tag2)
expect(user_preferences_sidebar_page).to have_sidebar_list_destination_preference(
"unread_new",
expect(user_preferences_navigation_menu_page).to have_navigation_menu_tags_preference(
tag,
tag2,
)
expect(
user_preferences_navigation_menu_page,
).to have_navigation_menu_list_destination_preference("unread_new")
end
end
end