mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
FEATURE: confirmation when a public section is updated (#26546)
Display additional confirmation when: - The public section is going to be updated; - The public section is going to be deleted; - The public section is going to be marked as private.
This commit is contained in:
parent
a68bea26ce
commit
0085365459
|
@ -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;
|
||||
}
|
||||
|
||||
@afterRender
|
||||
focusNewRowInput(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 {
|
|||
@action
|
||||
delete() {
|
||||
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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -231,6 +231,7 @@ describe "Custom sidebar sections", type: :system do
|
|||
latest_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_closed
|
||||
|
||||
expect(sidebar.primary_section_links("my-section")).to eq(
|
||||
["Sidebar Categories", "Sidebar Tags", "Sidebar Latest"],
|
||||
|
@ -292,6 +293,7 @@ describe "Custom sidebar sections", type: :system do
|
|||
sidebar.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_delete
|
||||
|
||||
expect(sidebar).to have_no_section("My section")
|
||||
|
@ -315,15 +317,51 @@ describe "Custom sidebar sections", type: :system do
|
|||
section_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_delete
|
||||
|
||||
expect(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" do
|
||||
sidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)
|
||||
sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")
|
||||
|
|
|
@ -30,6 +30,7 @@ RSpec.describe "Editing Sidebar Community Section", type: :system do
|
|||
modal.fill_link("Topics", "/latest", "paper-plane")
|
||||
modal.topics_link.drag_to(modal.review_link, delay: 0.4)
|
||||
modal.save
|
||||
modal.confirm_update
|
||||
|
||||
expect(sidebar.primary_section_links("community")).to eq(
|
||||
["My Posts", "Topics", "Review", "Admin", "More"],
|
||||
|
|
|
@ -29,6 +29,12 @@ module PageObjects
|
|||
|
||||
def confirm_delete
|
||||
find(".dialog-container .btn-primary").click
|
||||
closed?
|
||||
end
|
||||
|
||||
def confirm_update
|
||||
find(".dialog-container .btn-primary").click
|
||||
closed?
|
||||
end
|
||||
|
||||
def reset
|
||||
|
@ -40,7 +46,6 @@ module PageObjects
|
|||
|
||||
def save
|
||||
find("#save-section").click
|
||||
closed?
|
||||
self
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user