This menu item will show up once you have added the `:limit_post_creation_to_admins` feature flag (regardless of whether it is enabled or not). If you wish to add the menu item: ```console rails console runner "FeatureFlag.add(:limit_post_creation_to_admins)" ``` In "adding" the item, it will default to disabled. However, as an administrator you should now be able to toggle on and off the authorization enforcement. If you wish to remove the menu item: ```console rails console runner "FeatureFlag.remove(:limit_post_creation_to_admins)" ``` Future plans for this will be to remove the `FeatureFlag.exist?` conditional so that the menu item shows up. A major consideration is that we'll assume that all Forem's have a "default space" in which folks (by default) can post. Builds on forem/forem#16897 Closes forem/forem#16842
104 lines
3.3 KiB
Ruby
104 lines
3.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe AdminMenu do
|
|
describe ".nested_menu_items_from_request" do
|
|
subject(:method_call) { described_class.nested_menu_items_from_request(request) }
|
|
|
|
let(:request) { instance_double("ActionDispatch::Request", path: path) }
|
|
let(:path) { "/admin" }
|
|
|
|
context "when path is /admin/moderation/feedback_messages" do
|
|
let(:path) { "/admin/moderation/feedback_messages" }
|
|
|
|
it { is_expected.not_to be_present }
|
|
end
|
|
|
|
context "when path is /admin/content_manager/badge_achievements" do
|
|
let(:path) { "/admin/content_manager/badge_achievements" }
|
|
|
|
let(:badges_node) do
|
|
described_class::ITEMS[:content_manager].children
|
|
.detect { |ch| ch.name == "badges" }
|
|
end
|
|
|
|
it { is_expected.to eq(badges_node) }
|
|
end
|
|
end
|
|
|
|
describe ".navigation_items" do
|
|
subject(:navigation_items) { described_class.navigation_items }
|
|
|
|
it { is_expected.to be_a(Hash) }
|
|
end
|
|
|
|
describe "scope :content_manager" do
|
|
subject(:content_manager) { described_class.navigation_items.fetch(:content_manager) }
|
|
|
|
it { is_expected.to be_a(Menu::Scope) }
|
|
end
|
|
|
|
describe "scope :content_managers's posts item" do
|
|
subject(:posts) { content_manager.children.detect { |child| child.name == "posts" } }
|
|
|
|
let(:content_manager) { described_class.navigation_items.fetch(:content_manager) }
|
|
|
|
it { is_expected.to be_visible }
|
|
end
|
|
|
|
describe "scope :content_managers's spaces item" do
|
|
subject(:spaces) { content_manager.children.detect { |child| child.name == "spaces" } }
|
|
|
|
let(:content_manager) { described_class.navigation_items.fetch(:content_manager) }
|
|
|
|
context "when the :limit_post_creation_to_admins does not exist" do
|
|
it { is_expected.not_to be_visible }
|
|
end
|
|
|
|
context "when the :limit_post_creation_to_admins is enabled" do
|
|
before { FeatureFlag.enable(:limit_post_creation_to_admins) }
|
|
|
|
it { is_expected.to be_visible }
|
|
end
|
|
|
|
context "when the :limit_post_creation_to_admins is explicitly disabled" do
|
|
before { FeatureFlag.disable(:limit_post_creation_to_admins) }
|
|
|
|
it { is_expected.to be_visible }
|
|
end
|
|
end
|
|
|
|
describe "scope :customization" do
|
|
subject(:content_manager) { described_class.navigation_items.fetch(:customization) }
|
|
|
|
it { is_expected.to be_a(Menu::Scope) }
|
|
it { is_expected.to have_multiple_children }
|
|
it { is_expected.to have_children }
|
|
end
|
|
|
|
describe "scope :admin_team" do
|
|
subject(:content_manager) { described_class.navigation_items.fetch(:admin_team) }
|
|
|
|
it { is_expected.not_to have_multiple_children }
|
|
it { is_expected.to have_children }
|
|
end
|
|
|
|
describe "scope :customization's profile field" do
|
|
subject(:profile_field) { customization.children.detect { |child| child.name == "profile fields" } }
|
|
|
|
let(:customization) { described_class.navigation_items.fetch(:customization) }
|
|
|
|
it { is_expected.to be_a(Menu::Item) }
|
|
|
|
context "when :profile_field FeatureFlag is enabled" do
|
|
before { allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true) }
|
|
|
|
it { is_expected.to be_visible }
|
|
end
|
|
|
|
context "when :profile_field FeatureFlag is not enabled" do
|
|
before { allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false) }
|
|
|
|
it { is_expected.not_to be_visible }
|
|
end
|
|
end
|
|
end
|