mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: endpoint to reset community community-section (#21664)
In upcoming PRs, admins will be able to edit the Community section. We need an endpoint which allows resetting it to the default state.
This commit is contained in:
committed by
GitHub
parent
984a616204
commit
7ead8de232
@@ -3,10 +3,25 @@
|
||||
RSpec.describe SidebarSection do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:sidebar_section) { Fabricate(:sidebar_section, user: user) }
|
||||
let(:community_section) do
|
||||
SidebarSection.find_by(section_type: SidebarSection.section_types[:community])
|
||||
end
|
||||
|
||||
it "uses system user for public sections" do
|
||||
expect(sidebar_section.user_id).to eq(user.id)
|
||||
sidebar_section.update!(public: true)
|
||||
expect(sidebar_section.user_id).to eq(Discourse.system_user.id)
|
||||
end
|
||||
|
||||
it "resets Community section to the default state" do
|
||||
community_section.update!(title: "test")
|
||||
community_section.sidebar_section_links.first.linkable.update!(name: "everything edited")
|
||||
community_section.sidebar_section_links.last.destroy!
|
||||
|
||||
community_section.reset_community!
|
||||
expect(community_section.reload.title).to eq("Community")
|
||||
expect(community_section.sidebar_section_links.all.map { |link| link.linkable.name }).to eq(
|
||||
["Everything", "My Posts", "Review", "Admin", "Users", "About", "FAQ", "Groups", "Badges"],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
RSpec.describe SidebarSectionsController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
|
||||
describe "#index" do
|
||||
fab!(:sidebar_section) { Fabricate(:sidebar_section, title: "private section", user: user) }
|
||||
@@ -100,6 +101,20 @@ RSpec.describe SidebarSectionsController do
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "does not allow moderator to create public section" do
|
||||
sign_in(moderator)
|
||||
post "/sidebar_sections.json",
|
||||
params: {
|
||||
title: "custom section",
|
||||
public: true,
|
||||
links: [
|
||||
{ icon: "link", name: "categories", value: "/categories" },
|
||||
{ icon: "address-book", name: "tags", value: "/tags" },
|
||||
],
|
||||
}
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "allows admin to create public section" do
|
||||
sign_in(admin)
|
||||
post "/sidebar_sections.json",
|
||||
@@ -334,5 +349,43 @@ RSpec.describe SidebarSectionsController do
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "doesn't allow moderator to delete public sidebar section" do
|
||||
sign_in(moderator)
|
||||
sidebar_section.update!(public: true)
|
||||
delete "/sidebar_sections/#{sidebar_section.id}.json"
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reset" do
|
||||
let(:community_section) do
|
||||
SidebarSection.find_by(section_type: SidebarSection.section_types[:community])
|
||||
end
|
||||
let(:everything_link) { community_section.sidebar_section_links.first }
|
||||
|
||||
it "doesn't allow user to reset community section" do
|
||||
sign_in(user)
|
||||
SidebarSection.any_instance.expects(:reset_community!).never
|
||||
put "/sidebar_sections/reset/#{community_section.id}.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "doesn't allow staff to reset community section" do
|
||||
sign_in(moderator)
|
||||
SidebarSection.any_instance.expects(:reset_community!).never
|
||||
put "/sidebar_sections/reset/#{community_section.id}.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "allows admins to reset community section to default" do
|
||||
sign_in(admin)
|
||||
SidebarSection.any_instance.expects(:reset_community!).once
|
||||
put "/sidebar_sections/reset/#{community_section.id}.json"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["sidebar_section"]["id"]).to eq(community_section.id)
|
||||
expect(response.parsed_body["sidebar_section"]["title"]).to eq(community_section.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user