Project

General

Profile

Feature #30207 ยป 30207-cross-project-menu.patch

Yuichi HARADA, 2018-12-19 02:51

View differences:

lib/redmine.rb
207 207
    :caption => :label_project_plural
208 208
  menu.push :activity, {:controller => 'activities', :action => 'index'}
209 209
  menu.push :issues,   {:controller => 'issues', :action => 'index'},
210
    :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true)},
210
    :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :issue_tracking)},
211 211
    :caption => :label_issue_plural
212 212
  menu.push :time_entries, {:controller => 'timelog', :action => 'index'},
213
    :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true)},
213
    :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :time_tracking)},
214 214
    :caption => :label_spent_time
215 215
  menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :caption => :label_gantt,
216
    :if => Proc.new {User.current.allowed_to?(:view_gantt, nil, :global => true)}
216
    :if => Proc.new {User.current.allowed_to?(:view_gantt, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :gantt)}
217 217
  menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :caption => :label_calendar,
218
    :if => Proc.new {User.current.allowed_to?(:view_calendar, nil, :global => true)}
218
    :if => Proc.new {User.current.allowed_to?(:view_calendar, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :calendar)}
219 219
  menu.push :news, {:controller => 'news', :action => 'index'},
220
    :if => Proc.new {User.current.allowed_to?(:view_news, nil, :global => true)},
220
    :if => Proc.new {User.current.allowed_to?(:view_news, nil, :global => true) && EnabledModule.exists?(:project => Project.visible, :name => :news)},
221 221
    :caption => :label_news_plural
222 222
end
223 223

  
test/integration/lib/redmine/menu_manager_test.rb
84 84
    get '/'
85 85
    assert_select 'body.has-main-menu', 0
86 86
  end
87

  
88
  def test_application_menu_should_show_only_enabled_modules_with_cross_projects
89
    user = User.find_by_login('dlopper')
90
    assert_equal [1, 3, 4, 6], Project.visible(user).ids
91

  
92
    # Delete the EnabledModule with project_id in [1, 4, 6]
93
    EnabledModule.where(:project_id => [1, 4, 6]).delete_all
94
    assert_equal ["repository", "wiki", "time_tracking", "issue_tracking", "calendar", "gantt"], Project.find(3).enabled_module_names
95

  
96
    log_user('dlopper', 'foo')
97
    get '/projects'
98
    assert_select '#main-menu' do
99
      assert_select 'a.projects',     :count => 1
100
      assert_select 'a.activity',     :count => 1
101

  
102
      assert_select 'a.issues',       :count => 1 # issue_tracking
103
      assert_select 'a.time-entries', :count => 1 # time_tracking
104
      assert_select 'a.gantt',        :count => 1 # gantt
105
      assert_select 'a.calendar',     :count => 1 # calendar
106
      assert_select 'a.news',         :count => 0 # news
107
    end
108
    assert_select '#projects-index' do
109
      assert_select 'a.project',      :count => 4 # Project.visible(user).count
110
    end
111
  end
87 112
end
    (1-1/1)