A platform for community discussion. Free, open, simple.
UX: Add custom section button should not be shown to anon users (#21651)
Alan Guo Xiang Tanb183b997fb58
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs b/app/assets/javascripts/discourse/app/components/sidebar/footer.hbsindex b8b0e1e47e8..00e9dd99028 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs@@ -3,12 +3,14 @@<div class="sidebar-footer-actions"><PluginOutlet @name="sidebar-footer-actions" />- <DButton- @icon="plus"- @action={{action this.addSection}}- @class="btn-flat add-section"- @title="sidebar.sections.custom.add"- />+ {{#if this.currentUser}}+ <DButton+ @icon="plus"+ @action={{action this.addSection}}+ @class="btn-flat add-section"+ @title="sidebar.sections.custom.add"+ />+ {{/if}}{{#if(ordiff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rbindex 6aab079fe6d..e465c1b92ac 100644--- a/spec/system/custom_sidebar_sections_spec.rb+++ b/spec/system/custom_sidebar_sections_spec.rb@@ -7,9 +7,13 @@ describe "Custom sidebar sections", type: :system, js: true dolet(:sidebar) { PageObjects::Components::Sidebar.new }it "allows the user to create custom section" do+ visit("/latest")++ expect(sidebar).to have_no_add_section_button+sign_in uservisit("/latest")- sidebar.open_new_custom_section+ sidebar.click_add_section_buttonexpect(section_modal).to be_visibleexpect(section_modal).to have_disabled_save@@ -29,7 +33,7 @@ describe "Custom sidebar sections", type: :system, js: true doit "allows the user to create custom section with /my link" dosign_in uservisit("/latest")- sidebar.open_new_custom_section+ sidebar.click_add_section_buttonexpect(section_modal).to be_visibleexpect(section_modal).to have_disabled_save@@ -49,7 +53,7 @@ describe "Custom sidebar sections", type: :system, js: true doit "allows the user to create custom section with external link" dosign_in uservisit("/latest")- sidebar.open_new_custom_section+ sidebar.click_add_section_buttonexpect(section_modal).to be_visibleexpect(section_modal).to have_disabled_save@@ -167,7 +171,7 @@ describe "Custom sidebar sections", type: :system, js: true doit "allows admin to create, edit and delete public section" dosign_in adminvisit("/latest")- sidebar.open_new_custom_section+ sidebar.click_add_section_buttonsection_modal.fill_name("Public section")section_modal.fill_link("Sidebar Tags", "/tags")@@ -207,7 +211,7 @@ describe "Custom sidebar sections", type: :system, js: true doit "validates custom section fields" dosign_in uservisit("/latest")- sidebar.open_new_custom_section+ sidebar.click_add_section_buttonsection_modal.fill_name("A" * (SidebarSection::MAX_TITLE_LENGTH + 1))section_modal.fill_link("B" * (SidebarUrl::MAX_NAME_LENGTH + 1), "/wrong-url")diff --git a/spec/system/page_objects/components/sidebar.rb b/spec/system/page_objects/components/sidebar.rbindex 7c4ef2bcace..87e2056030d 100644--- a/spec/system/page_objects/components/sidebar.rb+++ b/spec/system/page_objects/components/sidebar.rb@@ -15,8 +15,12 @@ module PageObjectspage.has_link?(category.name, class: "sidebar-section-link")end- def open_new_custom_section- find("button.add-section").click+ def click_add_section_button+ click_button(add_section_button_text)+ end++ def has_no_add_section_button?+ page.has_no_button?(add_section_button_text)enddef edit_custom_section(name)@@ -68,6 +72,10 @@ module PageObjectsattributes[:class] += "--active" if activepage.public_send(present ? :has_link? : :has_no_link?, name, **attributes)end++ def add_section_button_text+ I18n.t("js.sidebar.sections.custom.add")+ endendendend