FIX: admin always see configure default sidebar categories (#20836)

When an admin removes all the categories from their personal sidebar configuration, the section should remain visible to them with the “Configure default categories” prompt.

Similar solution for tags.

/t/95036
This commit is contained in:
Krzysztof Kotlarek 2023-03-27 15:46:39 +11:00 committed by GitHub
parent 1edf7d1b72
commit e0cf2849fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 66 deletions

View File

@ -1,4 +1,4 @@
{{#if this.shouldDisplay}} {{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}
<Sidebar::Section <Sidebar::Section
@sectionName="categories" @sectionName="categories"
@headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}} @headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}}
@ -12,6 +12,7 @@
@collapsable={{@collapsable}} @collapsable={{@collapsable}}
> >
{{#if this.shouldDisplay}}
{{#if (gt this.sectionLinks.length 0)}} {{#if (gt this.sectionLinks.length 0)}}
{{#each this.sectionLinks as |sectionLink|}} {{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink <Sidebar::SectionLink
@ -43,13 +44,16 @@
@content={{i18n @content={{i18n
"sidebar.sections.categories.links.add_categories.content" "sidebar.sections.categories.links.add_categories.content"
}} }}
@title={{i18n "sidebar.sections.categories.links.add_categories.title"}} @title={{i18n
"sidebar.sections.categories.links.add_categories.title"
}}
/> />
{{/if}} {{/if}}
<Sidebar::Common::AllCategoriesSectionLink /> <Sidebar::Common::AllCategoriesSectionLink />
{{/if}}
{{#if (and this.currentUser.admin (not this.hasDefaultSidebarCategories))}} {{#if this.shouldDisplayDefaultConfig}}
<Sidebar::SectionLink <Sidebar::SectionLink
@linkName="configure-default-sidebar-categories" @linkName="configure-default-sidebar-categories"
@content={{i18n "sidebar.sections.categories.configure_defaults"}} @content={{i18n "sidebar.sections.categories.configure_defaults"}}

View File

@ -64,6 +64,10 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
} }
} }
get shouldDisplayDefaultConfig() {
return this.currentUser.admin && !this.hasDefaultSidebarCategories;
}
get hasDefaultSidebarCategories() { get hasDefaultSidebarCategories() {
return this.siteSettings.default_sidebar_categories.length > 0; return this.siteSettings.default_sidebar_categories.length > 0;
} }

View File

@ -1,4 +1,4 @@
{{#if this.shouldDisplay}} {{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}
<Sidebar::Section <Sidebar::Section
@sectionName="tags" @sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}} @headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@ -12,6 +12,7 @@
@collapsable={{@collapsable}} @collapsable={{@collapsable}}
> >
{{#if this.shouldDisplay}}
{{#if (gt this.sectionLinks.length 0)}} {{#if (gt this.sectionLinks.length 0)}}
{{#each this.sectionLinks as |sectionLink|}} {{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink <Sidebar::SectionLink
@ -42,8 +43,9 @@
{{/if}} {{/if}}
<Sidebar::Common::AllTagsSectionLink /> <Sidebar::Common::AllTagsSectionLink />
{{/if}}
{{#if (and this.currentUser.admin (not this.hasDefaultSidebarTags))}} {{#if this.shouldDisplayDefaultConfig}}
<Sidebar::SectionLink <Sidebar::SectionLink
@linkName="configure-default-sidebar-tags" @linkName="configure-default-sidebar-tags"
@content={{i18n "sidebar.sections.tags.configure_defaults"}} @content={{i18n "sidebar.sections.tags.configure_defaults"}}

View File

@ -69,6 +69,10 @@ export default class SidebarUserTagsSection extends Component {
} }
} }
get shouldDisplayDefaultConfig() {
return this.currentUser.admin && !this.hasDefaultSidebarTags;
}
get hasDefaultSidebarTags() { get hasDefaultSidebarTags() {
return this.siteSettings.default_sidebar_tags.length > 0; return this.siteSettings.default_sidebar_tags.length > 0;
} }

View File

@ -954,7 +954,6 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
}); });
test("section link to admin site settings page when default sidebar categories have not been configured", async function (assert) { test("section link to admin site settings page when default sidebar categories have not been configured", async function (assert) {
setupUserSidebarCategories();
updateCurrentUser({ admin: true }); updateCurrentUser({ admin: true });
await visit("/"); await visit("/");

View File

@ -666,7 +666,11 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
}); });
test("section link to admin site settings page when default sidebar tags have not been configured", async function (assert) { test("section link to admin site settings page when default sidebar tags have not been configured", async function (assert) {
updateCurrentUser({ admin: true }); updateCurrentUser({ admin: true, sidebar_tags: [] });
updateCurrentUser({
sidebar_tags: [],
});
await visit("/"); await visit("/");

View File

@ -109,6 +109,7 @@ acceptance("User Preferences - Sidebar", function (needs) {
}); });
test("user adding categories to sidebar when default sidebar categories have not been configured", async function (assert) { 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/sidebar");
assert.notOk(exists(".sidebar-section[data-section-name='categories']")); assert.notOk(exists(".sidebar-section[data-section-name='categories']"));