summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-01-13 03:23:18 +0000
committerGo MAEDA <maeda@farend.jp>2019-01-13 03:23:18 +0000
commit1d3e2006b1b8119cc28c5a55413441c3236879b9 (patch)
tree7d8584f892b0d2369650bcaa2bd0428e64d9107f
parent658df294dd789ffb71f4072f456a6bd6b565e93c (diff)
downloadredmine-1d3e2006b1b8119cc28c5a55413441c3236879b9.tar.gz
redmine-1d3e2006b1b8119cc28c5a55413441c3236879b9.zip
Hide menu item in the cross-project menu if the module is not enabled in any project (#30207).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@17794 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--lib/redmine.rb10
-rw-r--r--test/integration/lib/redmine/menu_manager_test.rb26
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 111653499..9bf00f366 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -207,17 +207,17 @@ Redmine::MenuManager.map :application_menu do |menu|
:caption => :label_project_plural
menu.push :activity, {:controller => 'activities', :action => 'index'}
menu.push :issues, {:controller => 'issues', :action => 'index'},
- :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true)},
+ :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :issue_tracking)},
:caption => :label_issue_plural
menu.push :time_entries, {:controller => 'timelog', :action => 'index'},
- :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true)},
+ :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :time_tracking)},
:caption => :label_spent_time
menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :caption => :label_gantt,
- :if => Proc.new {User.current.allowed_to?(:view_gantt, nil, :global => true)}
+ :if => Proc.new {User.current.allowed_to?(:view_gantt, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :gantt)}
menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :caption => :label_calendar,
- :if => Proc.new {User.current.allowed_to?(:view_calendar, nil, :global => true)}
+ :if => Proc.new {User.current.allowed_to?(:view_calendar, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :calendar)}
menu.push :news, {:controller => 'news', :action => 'index'},
- :if => Proc.new {User.current.allowed_to?(:view_news, nil, :global => true)},
+ :if => Proc.new {User.current.allowed_to?(:view_news, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :news)},
:caption => :label_news_plural
end
diff --git a/test/integration/lib/redmine/menu_manager_test.rb b/test/integration/lib/redmine/menu_manager_test.rb
index 0b01f5d7f..eb81d9cf4 100644
--- a/test/integration/lib/redmine/menu_manager_test.rb
+++ b/test/integration/lib/redmine/menu_manager_test.rb
@@ -84,4 +84,30 @@ class MenuManagerTest < Redmine::IntegrationTest
get '/'
assert_select 'body.has-main-menu', 0
end
+
+ def test_cross_project_menu_should_hide_item_if_module_is_not_enabled_for_any_project
+ user = User.find_by_login('dlopper')
+ assert_equal [1, 3, 4, 6], Project.visible(user).ids
+
+ # gantt and news are not enabled for any visible project
+ Project.find(1).enabled_module_names = %w(issue_tracking calendar)
+ Project.find(3).enabled_module_names = %w(time_tracking)
+ EnabledModule.where(:project_id => [4, 6]).delete_all
+
+ log_user('dlopper', 'foo')
+ get '/projects'
+ assert_select '#main-menu' do
+ assert_select 'a.projects', :count => 1
+ assert_select 'a.activity', :count => 1
+
+ assert_select 'a.issues', :count => 1 # issue_tracking
+ assert_select 'a.time-entries', :count => 1 # time_tracking
+ assert_select 'a.gantt', :count => 0 # gantt
+ assert_select 'a.calendar', :count => 1 # calendar
+ assert_select 'a.news', :count => 0 # news
+ end
+ assert_select '#projects-index' do
+ assert_select 'a.project', :count => 4
+ end
+ end
end