mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 03:33:39 +08:00
0a56274596
Context of this change: There are two site settings which an admin can configured to set the default categories and tags that are shown for a new user. `default_navigation_menu_categories` is used to determine the default categories while `default_navigation_menu_tags` is used to determine the default tags. Prior to this change when seeding the defaults, we will filter out the categories/tags that the user do not have permission to see. However, this means that when the user does eventually gain permission down the line, the default categories and tags do not appear. What does this change do? With this commit, we have changed it such that all the categories and tags configured in the `default_navigation_menu_categories` and `default_navigation_menu_tags` site settings are seeded regardless of whether the user's visibility of the categories or tags. During serialization, we will then filter out the categories and tags which the user does not have visibility of.
72 lines
2.6 KiB
Ruby
72 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe SidebarSectionLinksUpdater do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:user2) { Fabricate(:user) }
|
|
|
|
describe ".update_category_section_links" do
|
|
fab!(:public_category) { Fabricate(:category) }
|
|
fab!(:public_category2) { Fabricate(:category) }
|
|
|
|
fab!(:user_category_section_link) do
|
|
Fabricate(:category_sidebar_section_link, linkable: public_category, user: user)
|
|
end
|
|
|
|
fab!(:user2_category_section_link) do
|
|
Fabricate(:category_sidebar_section_link, linkable: public_category, user: user2)
|
|
end
|
|
|
|
it "deletes all sidebar category section links when category ids provided is blank" do
|
|
described_class.update_category_section_links(user, category_ids: [])
|
|
|
|
expect(SidebarSectionLink.exists?(linkable: public_category, user: user)).to eq(false)
|
|
expect(SidebarSectionLink.exists?(linkable: public_category, user: user2)).to eq(true)
|
|
end
|
|
|
|
it "updates user's sidebar category section link records to given category ids" do
|
|
expect(
|
|
SidebarSectionLink.where(linkable_type: "Category", user: user).pluck(:linkable_id),
|
|
).to contain_exactly(public_category.id)
|
|
|
|
described_class.update_category_section_links(
|
|
user,
|
|
category_ids: [public_category.id, public_category2.id],
|
|
)
|
|
|
|
expect(
|
|
SidebarSectionLink.where(linkable_type: "Category", user: user).pluck(:linkable_id),
|
|
).to contain_exactly(public_category.id, public_category2.id)
|
|
end
|
|
end
|
|
|
|
describe ".update_tag_section_links" do
|
|
fab!(:tag) { Fabricate(:tag) }
|
|
fab!(:tag2) { Fabricate(:tag) }
|
|
|
|
fab!(:user_tag_section_link) { Fabricate(:tag_sidebar_section_link, linkable: tag, user: user) }
|
|
|
|
fab!(:user2_tag_section_link) do
|
|
Fabricate(:tag_sidebar_section_link, linkable: tag, user: user2)
|
|
end
|
|
|
|
it "deletes all sidebar tag section links when tag names provided is blank" do
|
|
described_class.update_tag_section_links(user, tag_ids: [])
|
|
|
|
expect(SidebarSectionLink.exists?(linkable: tag, user: user)).to eq(false)
|
|
expect(SidebarSectionLink.exists?(linkable: tag, user: user2)).to eq(true)
|
|
end
|
|
|
|
it "updates user's sidebar tag section link records to given tag names" do
|
|
expect(
|
|
SidebarSectionLink.where(linkable_type: "Tag", user: user).pluck(:linkable_id),
|
|
).to contain_exactly(tag.id)
|
|
|
|
described_class.update_tag_section_links(user, tag_ids: [tag.id, tag2.id])
|
|
|
|
expect(
|
|
SidebarSectionLink.where(linkable_type: "Tag", user: user).pluck(:linkable_id),
|
|
).to contain_exactly(tag.id, tag2.id)
|
|
end
|
|
end
|
|
end
|