A platform for community discussion. Free, open, simple.
FIX: admin always see configure default sidebar categories (#20836)
Krzysztof Kotlareke0cf2849fd7c
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbsindex a48a31c7787..269263b9656 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs@@ -1,4 +1,4 @@-{{#if this.shouldDisplay}}+{{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}<Sidebar::Section@sectionName="categories"@headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}}@@ -12,44 +12,48 @@@collapsable={{@collapsable}}>- {{#if (gt this.sectionLinks.length 0)}}- {{#each this.sectionLinks as |sectionLink|}}+ {{#if this.shouldDisplay}}+ {{#if (gt this.sectionLinks.length 0)}}+ {{#each this.sectionLinks as |sectionLink|}}+ <Sidebar::SectionLink+ @route={{sectionLink.route}}+ @query={{sectionLink.query}}+ @title={{sectionLink.title}}+ @content={{sectionLink.text}}+ @currentWhen={{sectionLink.currentWhen}}+ @model={{sectionLink.model}}+ @badgeText={{sectionLink.badgeText}}+ @prefixBadge={{sectionLink.prefixBadge}}+ @prefixType={{sectionLink.prefixType}}+ @prefixValue={{sectionLink.prefixValue}}+ @prefixColor={{sectionLink.prefixColor}}+ @prefixElementColors={{sectionLink.prefixElementColors}}+ @suffixCSSClass={{sectionLink.suffixCSSClass}}+ @suffixValue={{sectionLink.suffixValue}}+ @suffixType={{sectionLink.suffixType}}+ data-category-id={{sectionLink.category.id}}+ />+ {{/each}}+ {{else}}<Sidebar::SectionLink- @route={{sectionLink.route}}- @query={{sectionLink.query}}- @title={{sectionLink.title}}- @content={{sectionLink.text}}- @currentWhen={{sectionLink.currentWhen}}- @model={{sectionLink.model}}- @badgeText={{sectionLink.badgeText}}- @prefixBadge={{sectionLink.prefixBadge}}- @prefixType={{sectionLink.prefixType}}- @prefixValue={{sectionLink.prefixValue}}- @prefixColor={{sectionLink.prefixColor}}- @prefixElementColors={{sectionLink.prefixElementColors}}- @suffixCSSClass={{sectionLink.suffixCSSClass}}- @suffixValue={{sectionLink.suffixValue}}- @suffixType={{sectionLink.suffixType}}- data-category-id={{sectionLink.category.id}}+ @linkName="configure-categories"+ @route="preferences.sidebar"+ @prefixType="icon"+ @prefixValue="pencil-alt"+ @model={{this.currentUser}}+ @content={{i18n+ "sidebar.sections.categories.links.add_categories.content"+ }}+ @title={{i18n+ "sidebar.sections.categories.links.add_categories.title"+ }}/>- {{/each}}- {{else}}- <Sidebar::SectionLink- @linkName="configure-categories"- @route="preferences.sidebar"- @prefixType="icon"- @prefixValue="pencil-alt"- @model={{this.currentUser}}- @content={{i18n- "sidebar.sections.categories.links.add_categories.content"- }}- @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@linkName="configure-default-sidebar-categories"@content={{i18n "sidebar.sections.categories.configure_defaults"}}diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.jsindex d3bc1378a7a..4ad61911dbf 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js+++ b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js@@ -64,6 +64,10 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie}}+ get shouldDisplayDefaultConfig() {+ return this.currentUser.admin && !this.hasDefaultSidebarCategories;+ }+get hasDefaultSidebarCategories() {return this.siteSettings.default_sidebar_categories.length > 0;}diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbsindex 3bea81d2579..b09db23259e 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs@@ -1,4 +1,4 @@-{{#if this.shouldDisplay}}+{{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}<Sidebar::Section@sectionName="tags"@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}@@ -12,38 +12,40 @@@collapsable={{@collapsable}}>- {{#if (gt this.sectionLinks.length 0)}}- {{#each this.sectionLinks as |sectionLink|}}+ {{#if this.shouldDisplay}}+ {{#if (gt this.sectionLinks.length 0)}}+ {{#each this.sectionLinks as |sectionLink|}}+ <Sidebar::SectionLink+ @route={{sectionLink.route}}+ @title={{sectionLink.title}}+ @content={{sectionLink.text}}+ @currentWhen={{sectionLink.currentWhen}}+ @prefixType={{sectionLink.prefixType}}+ @prefixValue={{sectionLink.prefixValue}}+ @badgeText={{sectionLink.badgeText}}+ @models={{sectionLink.models}}+ @suffixCSSClass={{sectionLink.suffixCSSClass}}+ @suffixValue={{sectionLink.suffixValue}}+ @suffixType={{sectionLink.suffixType}}+ data-tag-name={{sectionLink.tagName}}+ />+ {{/each}}+ {{else}}<Sidebar::SectionLink- @route={{sectionLink.route}}- @title={{sectionLink.title}}- @content={{sectionLink.text}}- @currentWhen={{sectionLink.currentWhen}}- @prefixType={{sectionLink.prefixType}}- @prefixValue={{sectionLink.prefixValue}}- @badgeText={{sectionLink.badgeText}}- @models={{sectionLink.models}}- @suffixCSSClass={{sectionLink.suffixCSSClass}}- @suffixValue={{sectionLink.suffixValue}}- @suffixType={{sectionLink.suffixType}}- data-tag-name={{sectionLink.tagName}}+ @linkName="configure-tags"+ @route="preferences.sidebar"+ @prefixType="icon"+ @prefixValue="pencil-alt"+ @model={{this.currentUser}}+ @content={{i18n "sidebar.sections.tags.links.add_tags.content"}}+ @title={{i18n "sidebar.sections.tags.links.add_tags.title"}}/>- {{/each}}- {{else}}- <Sidebar::SectionLink- @linkName="configure-tags"- @route="preferences.sidebar"- @prefixType="icon"- @prefixValue="pencil-alt"- @model={{this.currentUser}}- @content={{i18n "sidebar.sections.tags.links.add_tags.content"}}- @title={{i18n "sidebar.sections.tags.links.add_tags.title"}}- />- {{/if}}+ {{/if}}- <Sidebar::Common::AllTagsSectionLink />+ <Sidebar::Common::AllTagsSectionLink />+ {{/if}}- {{#if (and this.currentUser.admin (not this.hasDefaultSidebarTags))}}+ {{#if this.shouldDisplayDefaultConfig}}<Sidebar::SectionLink@linkName="configure-default-sidebar-tags"@content={{i18n "sidebar.sections.tags.configure_defaults"}}diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.jsindex 950d9fea914..a622605e4e9 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js+++ b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js@@ -69,6 +69,10 @@ export default class SidebarUserTagsSection extends Component {}}+ get shouldDisplayDefaultConfig() {+ return this.currentUser.admin && !this.hasDefaultSidebarTags;+ }+get hasDefaultSidebarTags() {return this.siteSettings.default_sidebar_tags.length > 0;}diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.jsindex 5e33a388f17..1fe30b9e87e 100644--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js@@ -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) {- setupUserSidebarCategories();updateCurrentUser({ admin: true });await visit("/");diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.jsindex bd31fb664c7..cc8acf7db7e 100644--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js@@ -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) {- updateCurrentUser({ admin: true });+ updateCurrentUser({ admin: true, sidebar_tags: [] });++ updateCurrentUser({+ sidebar_tags: [],+ });await visit("/");diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-sidebar-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-sidebar-test.jsindex 6f79b40b44f..50a8a4d84b4 100644--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-sidebar-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-sidebar-test.js@@ -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) {+ updateCurrentUser({ admin: false, display_sidebar_tags: false });await visit("/u/eviltrout/preferences/sidebar");assert.notOk(exists(".sidebar-section[data-section-name='categories']"));