mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +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:

committed by
GitHub

parent
a68bea26ce
commit
0085365459
@ -298,6 +298,23 @@ export default class SidebarSectionForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
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}`, {
|
return ajax(`/sidebar_sections/${this.transformedModel.id}`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
@ -353,6 +370,14 @@ export default class SidebarSectionForm extends Component {
|
|||||||
: "sidebar.sections.custom.add";
|
: "sidebar.sections.custom.add";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isPublic() {
|
||||||
|
return this.transformedModel.public;
|
||||||
|
}
|
||||||
|
|
||||||
|
get wasPublic() {
|
||||||
|
return this.model?.section?.public;
|
||||||
|
}
|
||||||
|
|
||||||
@afterRender
|
@afterRender
|
||||||
focusNewRowInput(id) {
|
focusNewRowInput(id) {
|
||||||
document
|
document
|
||||||
@ -460,6 +485,9 @@ export default class SidebarSectionForm extends Component {
|
|||||||
this.flashType = "error";
|
this.flashType = "error";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
didCancel: () => {
|
||||||
|
this.closeModal();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +499,9 @@ export default class SidebarSectionForm extends Component {
|
|||||||
@action
|
@action
|
||||||
delete() {
|
delete() {
|
||||||
return this.dialog.yesNoConfirm({
|
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: () => {
|
didConfirm: () => {
|
||||||
return ajax(`/sidebar_sections/${this.transformedModel.id}`, {
|
return ajax(`/sidebar_sections/${this.transformedModel.id}`, {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
|
@ -4635,6 +4635,9 @@ en:
|
|||||||
save: "Save"
|
save: "Save"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
delete_confirm: "Are you sure you want to delete this section?"
|
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?"
|
reset_confirm: "Are you sure you want to reset this section to default?"
|
||||||
public: "Visible to everyone"
|
public: "Visible to everyone"
|
||||||
always_public: "Content in this section is always public"
|
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']")
|
latest_link = find(".draggable[data-link-name='Sidebar Latest']")
|
||||||
tags_link.drag_to(latest_link, html5: true, delay: 0.4)
|
tags_link.drag_to(latest_link, html5: true, delay: 0.4)
|
||||||
section_modal.save
|
section_modal.save
|
||||||
|
expect(section_modal).to be_closed
|
||||||
|
|
||||||
expect(sidebar.primary_section_links("my-section")).to eq(
|
expect(sidebar.primary_section_links("my-section")).to eq(
|
||||||
["Sidebar Categories", "Sidebar Tags", "Sidebar Latest"],
|
["Sidebar Categories", "Sidebar Tags", "Sidebar Latest"],
|
||||||
@ -292,6 +293,7 @@ describe "Custom sidebar sections", type: :system do
|
|||||||
sidebar.edit_custom_section("My section")
|
sidebar.edit_custom_section("My section")
|
||||||
|
|
||||||
section_modal.delete
|
section_modal.delete
|
||||||
|
expect(section_modal).to have_text("Are you sure you want to delete this section?")
|
||||||
section_modal.confirm_delete
|
section_modal.confirm_delete
|
||||||
|
|
||||||
expect(sidebar).to have_no_section("My section")
|
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.fill_name("Edited public section")
|
||||||
section_modal.save
|
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")
|
expect(sidebar).to have_section("Edited public section")
|
||||||
|
|
||||||
sidebar.edit_custom_section("Edited public section")
|
sidebar.edit_custom_section("Edited public section")
|
||||||
section_modal.delete
|
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
|
section_modal.confirm_delete
|
||||||
|
|
||||||
expect(sidebar).to have_no_section("Edited public section")
|
expect(sidebar).to have_no_section("Edited public section")
|
||||||
end
|
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
|
it "shows anonymous public sections" do
|
||||||
sidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)
|
sidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)
|
||||||
sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")
|
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.fill_link("Topics", "/latest", "paper-plane")
|
||||||
modal.topics_link.drag_to(modal.review_link, delay: 0.4)
|
modal.topics_link.drag_to(modal.review_link, delay: 0.4)
|
||||||
modal.save
|
modal.save
|
||||||
|
modal.confirm_update
|
||||||
|
|
||||||
expect(sidebar.primary_section_links("community")).to eq(
|
expect(sidebar.primary_section_links("community")).to eq(
|
||||||
["My Posts", "Topics", "Review", "Admin", "More"],
|
["My Posts", "Topics", "Review", "Admin", "More"],
|
||||||
|
@ -29,6 +29,12 @@ module PageObjects
|
|||||||
|
|
||||||
def confirm_delete
|
def confirm_delete
|
||||||
find(".dialog-container .btn-primary").click
|
find(".dialog-container .btn-primary").click
|
||||||
|
closed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_update
|
||||||
|
find(".dialog-container .btn-primary").click
|
||||||
|
closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
@ -40,7 +46,6 @@ module PageObjects
|
|||||||
|
|
||||||
def save
|
def save
|
||||||
find("#save-section").click
|
find("#save-section").click
|
||||||
closed?
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user