A platform for community discussion. Free, open, simple.
FEATURE: confirmation when a public section is updated (#26546)
Krzysztof Kotlarek0085365459ea
diff --git a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.js b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.jsindex a91f4a2b4a2..9bdb22e6f75 100644--- a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.js+++ b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.js@@ -298,6 +298,23 @@ export default class SidebarSectionForm extends Component {}update() {+ this.wasPublic || this.isPublic+ ? this.#updateWithConfirm()+ : this.#updateCall();+ }++ #updateWithConfirm() {+ return this.dialog.yesNoConfirm({+ message: this.isPublic+ ? I18n.t("sidebar.sections.custom.update_public_confirm")+ : I18n.t("sidebar.sections.custom.mark_as_private_confirm"),+ didConfirm: () => {+ return this.#updateCall();+ },+ });+ }++ #updateCall() {return ajax(`/sidebar_sections/${this.transformedModel.id}`, {type: "PUT",contentType: "application/json",@@ -353,6 +370,14 @@ export default class SidebarSectionForm extends Component {: "sidebar.sections.custom.add";}+ get isPublic() {+ return this.transformedModel.public;+ }++ get wasPublic() {+ return this.model?.section?.public;+ }+@afterRenderfocusNewRowInput(id) {document@@ -460,6 +485,9 @@ export default class SidebarSectionForm extends Component {this.flashType = "error";});},+ didCancel: () => {+ this.closeModal();+ },});}@@ -471,7 +499,9 @@ export default class SidebarSectionForm extends Component {@actiondelete() {return this.dialog.yesNoConfirm({- message: I18n.t("sidebar.sections.custom.delete_confirm"),+ message: this.model.section.public+ ? I18n.t("sidebar.sections.custom.delete_public_confirm")+ : I18n.t("sidebar.sections.custom.delete_confirm"),didConfirm: () => {return ajax(`/sidebar_sections/${this.transformedModel.id}`, {type: "DELETE",diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex cad642d88c6..c7abeca864c 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4635,6 +4635,9 @@ en:save: "Save"delete: "Delete"delete_confirm: "Are you sure you want to delete this section?"+ delete_public_confirm: "This section is <strong>visible to everyone</strong>, are you sure you want to delete it?"+ update_public_confirm: "Changes will be <strong>visible to everyone</strong> on this site. Are you sure?"+ mark_as_private_confirm: "This section is <strong>visible to everyone</strong>. After the update, it will be <strong>visible only to you</strong>. Are you sure?"reset_confirm: "Are you sure you want to reset this section to default?"public: "Visible to everyone"always_public: "Content in this section is always public"diff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rbindex 09de7465289..810825c2ae5 100644--- a/spec/system/custom_sidebar_sections_spec.rb+++ b/spec/system/custom_sidebar_sections_spec.rb@@ -231,6 +231,7 @@ describe "Custom sidebar sections", type: :system dolatest_link = find(".draggable[data-link-name='Sidebar Latest']")tags_link.drag_to(latest_link, html5: true, delay: 0.4)section_modal.save+ expect(section_modal).to be_closedexpect(sidebar.primary_section_links("my-section")).to eq(["Sidebar Categories", "Sidebar Tags", "Sidebar Latest"],@@ -292,6 +293,7 @@ describe "Custom sidebar sections", type: :system dosidebar.edit_custom_section("My section")section_modal.delete+ expect(section_modal).to have_text("Are you sure you want to delete this section?")section_modal.confirm_deleteexpect(sidebar).to have_no_section("My section")@@ -315,15 +317,51 @@ describe "Custom sidebar sections", type: :system dosection_modal.fill_name("Edited public section")section_modal.save+ expect(section_modal).to have_text(+ "Changes will be visible to everyone on this site. Are you sure?",+ )++ section_modal.confirm_update+expect(sidebar).to have_section("Edited public section")sidebar.edit_custom_section("Edited public section")section_modal.delete+ expect(section_modal).to have_text(+ "This section is visible to everyone, are you sure you want to delete it?",+ )section_modal.confirm_deleteexpect(sidebar).to have_no_section("Edited public section")end+ it "displays warning when public section is marked as private" do+ sign_in admin+ visit("/latest")+ sidebar.click_add_section_button++ section_modal.fill_name("Public section")+ section_modal.fill_link("Sidebar Tags", "/tags")+ section_modal.mark_as_public+ section_modal.save++ sidebar.edit_custom_section("Public section")+ section_modal.fill_name("Edited public section")+ section_modal.mark_as_public+ section_modal.save++ expect(section_modal).to have_text(+ "This section is visible to everyone. After the update, it will be visible only to you. Are you sure?",+ )++ section_modal.confirm_update++ expect(sidebar).to have_section("Edited public section")+ expect(page).not_to have_css(+ ".sidebar-section[data-section-name='edited-public-section'] .d-icon-globe",+ )+ end+it "shows anonymous public sections" dosidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")diff --git a/spec/system/editing_sidebar_community_section_spec.rb b/spec/system/editing_sidebar_community_section_spec.rbindex 16538d4807b..997ce6d12c2 100644--- a/spec/system/editing_sidebar_community_section_spec.rb+++ b/spec/system/editing_sidebar_community_section_spec.rb@@ -30,6 +30,7 @@ RSpec.describe "Editing Sidebar Community Section", type: :system domodal.fill_link("Topics", "/latest", "paper-plane")modal.topics_link.drag_to(modal.review_link, delay: 0.4)modal.save+ modal.confirm_updateexpect(sidebar.primary_section_links("community")).to eq(["My Posts", "Topics", "Review", "Admin", "More"],diff --git a/spec/system/page_objects/modals/sidebar_section_form.rb b/spec/system/page_objects/modals/sidebar_section_form.rbindex bb3a989e251..08fc10cecd8 100644--- a/spec/system/page_objects/modals/sidebar_section_form.rb+++ b/spec/system/page_objects/modals/sidebar_section_form.rb@@ -29,6 +29,12 @@ module PageObjectsdef confirm_deletefind(".dialog-container .btn-primary").click+ closed?+ end++ def confirm_update+ find(".dialog-container .btn-primary").click+ closed?enddef reset@@ -40,7 +46,6 @@ module PageObjectsdef savefind("#save-section").click- closed?selfend