Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

hide menu items both from side menu and overview panel

Markus Kahl444afb25b008
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index eda3c858bac..3d24a891000 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -38,8 +38,8 @@ class AdminController < ApplicationController
def index
@menu_nodes = Redmine::MenuManager.items(:admin_menu).children
- @menu_nodes.delete_if { |node| node.name === :enterprise } unless OpenProject::Configuration.ee_manager_visible?
@menu_nodes.delete_if { |node| node.name === :admin_overview }
+ @menu_nodes.delete_if { |node| node.condition && !node.condition.call }
end
def projects
diff --git a/spec/controllers/admin_controller_spec.rb b/spec/controllers/admin_controller_spec.rb
index 1855fc422a4..3980ecd846a 100644
--- a/spec/controllers/admin_controller_spec.rb
+++ b/spec/controllers/admin_controller_spec.rb
@@ -42,6 +42,47 @@ describe AdminController, type: :controller do
expect(response).to be_successful
expect(response).to render_template 'index'
end
+
+ describe "with a plugin adding a menu item" do
+ render_views
+
+ let(:visible) { true }
+ let(:plugin_name) { nil }
+
+ before do
+ show = visible
+ name = plugin_name
+
+ Redmine::Plugin.register name.to_sym do
+ menu :admin_menu,
+ :"#{name}_settings",
+ { controller: '/settings', action: :plugin, id: :"openproject_#{name}" },
+ caption: name.capitalize,
+ icon: 'icon2 icon-arrow',
+ if: ->(*) { show }
+ end
+
+ get :index
+ end
+
+ context "with the menu item visible" do
+ let(:plugin_name) { "Apple" }
+ let(:visible) { true }
+
+ it "should show the plugin in the overview" do
+ expect(response.body).to have_selector('a.menu-block', text: plugin_name.capitalize)
+ end
+ end
+
+ context "with the menu item hidden" do
+ let(:plugin_name) { "Orange" }
+ let(:visible) { false }
+
+ it "should not show the plugin in the overview" do
+ expect(response.body).not_to have_selector('a.menu-block', text: plugin_name.capitalize)
+ end
+ end
+ end
end
describe '#plugins' do