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

Add the `Time and Costs` items to the global menu

Aaron Contreras3f7a5855ef9d
diff --git a/frontend/src/global_styles/layout/_tree_menu.sass b/frontend/src/global_styles/layout/_tree_menu.sass
index e89066a6542..583d4238499 100644
--- a/frontend/src/global_styles/layout/_tree_menu.sass
+++ b/frontend/src/global_styles/layout/_tree_menu.sass
@@ -2,6 +2,7 @@ $tree-menu-item-height: 30px
.tree-menu--container
padding-top: 10px
+ color: var(--main-menu-font-color)
#main-menu ul ul.main-menu--children ul.pages-hierarchy,
div.wiki ul.pages-hierarchy,
diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rb
index d6a9e247770..480a12f6f80 100644
--- a/modules/reporting/app/controllers/cost_reports_controller.rb
+++ b/modules/reporting/app/controllers/cost_reports_controller.rb
@@ -81,6 +81,7 @@ class CostReportsController < ApplicationController
respond_to do |format|
format.html do
session[report_engine.name.underscore.to_sym].try(:delete, :name)
+ render locals: { menu_name: project_or_global_menu }
end
end
end
@@ -99,7 +100,7 @@ class CostReportsController < ApplicationController
end
def menu_item_to_highlight_on_index
- @project ? :costs : :cost_reports_global
+ @project ? :costs : :cost_reports_global_report_menu
end
##
@@ -127,7 +128,7 @@ class CostReportsController < ApplicationController
if @query
store_query(@query)
table
- render action: 'index' unless performed?
+ render action: 'index', locals: { menu_name: project_or_global_menu } unless performed?
else
raise ActiveRecord::RecordNotFound
end
diff --git a/modules/reporting/app/views/cost_reports/_report_list.html.erb b/modules/reporting/app/views/cost_reports/_report_list.html.erb
index 51edcf9944c..48f75c472ec 100644
--- a/modules/reporting/app/views/cost_reports/_report_list.html.erb
+++ b/modules/reporting/app/views/cost_reports/_report_list.html.erb
@@ -40,6 +40,6 @@ See COPYRIGHT and LICENSE files for more details.
<% end -%>
<% else %>
<ul class="pages-hierarchy -with-hierarchy">
- <li><%= t(:"label_no_reports") %></li>
+ <li class="tree-menu--title"><%= t(:"label_no_reports") %></li>
</ul>
<% end -%>
diff --git a/modules/reporting/app/views/cost_reports/index.html.erb b/modules/reporting/app/views/cost_reports/index.html.erb
index de858e902f8..63789fa31c7 100644
--- a/modules/reporting/app/views/cost_reports/index.html.erb
+++ b/modules/reporting/app/views/cost_reports/index.html.erb
@@ -57,9 +57,3 @@ See COPYRIGHT and LICENSE files for more details.
<%= t(:text_costs_are_rounded_note) %>
<%= "<br />#{t(:information_restricted_depending_on_permission)}".html_safe unless User.current.admin?%>
</p>
-
-<% if @project.blank? %>
- <% content_for :sidebar do %>
- <%= render :partial => "report_menu" %>
- <% end -%>
-<% end %>
diff --git a/modules/reporting/lib/open_project/reporting/engine.rb b/modules/reporting/lib/open_project/reporting/engine.rb
index 1647dfb84f7..37a6cc4c058 100644
--- a/modules/reporting/lib/open_project/reporting/engine.rb
+++ b/modules/reporting/lib/open_project/reporting/engine.rb
@@ -58,21 +58,37 @@ module OpenProject::Reporting
end
end
+ should_render = Proc.new do
+ (User.current.logged? || !Setting.login_required?) &&
+ (
+ User.current.allowed_to_globally?(:view_time_entries) ||
+ User.current.allowed_to_globally?(:view_own_time_entries) ||
+ User.current.allowed_to_globally?(:view_cost_entries) ||
+ User.current.allowed_to_globally?(:view_own_cost_entries)
+ )
+ end
+
# menu extensions
menu :top_menu,
:cost_reports_global,
{ controller: '/cost_reports', action: 'index', project_id: nil },
caption: :cost_reports_title,
icon: 'cost-reports',
- if: Proc.new {
- (User.current.logged? || !Setting.login_required?) &&
- (
- User.current.allowed_to_globally?(:view_time_entries) ||
- User.current.allowed_to_globally?(:view_own_time_entries) ||
- User.current.allowed_to_globally?(:view_cost_entries) ||
- User.current.allowed_to_globally?(:view_own_cost_entries)
- )
- }
+ if: should_render
+
+ menu :global_menu,
+ :cost_reports_global,
+ { controller: '/cost_reports', action: 'index', project_id: nil },
+ caption: :cost_reports_title,
+ icon: 'cost-reports',
+ if: should_render
+
+ menu :global_menu,
+ :cost_reports_global_report_menu,
+ { controller: '/cost_reports', action: 'index', project_id: nil },
+ parent: :cost_reports_global,
+ partial: 'cost_reports/report_menu',
+ if: should_render
menu :project_menu,
:costs,
diff --git a/modules/reporting/spec/features/main_menu_item_spec.rb b/modules/reporting/spec/features/main_menu_item_spec.rb
new file mode 100644
index 00000000000..a1da8934ef2
--- /dev/null
+++ b/modules/reporting/spec/features/main_menu_item_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+#
+
+require 'spec_helper'
+
+RSpec.describe 'Cost and Reports Main Menu Item', :js, :with_cuprite do
+ shared_let(:admin) { create(:admin) }
+ shared_let(:user_with_permissions) { create(:user, global_permissions: %i[view_time_entries]) }
+ shared_let(:user_without_permissions) { create(:user) }
+
+ before do
+ login_as current_user
+ visit root_path
+ end
+
+ shared_examples 'visiting the global cost reports page' do
+ it 'allows visiting the global cost reports page' do
+ within '#main-menu' do
+ click_link I18n.t(:cost_reports_title)
+ end
+
+ expect(page).to have_current_path(url_for(controller: '/cost_reports',
+ action: 'index',
+ project_id: nil,
+ only_path: true))
+ end
+ end
+
+ describe 'Main Menu' do
+ context 'as an admin' do
+ let(:current_user) { admin }
+
+ include_examples 'visiting the global cost reports page'
+ end
+
+ context 'as a user with permissions' do
+ let(:current_user) { user_with_permissions }
+
+ include_examples 'visiting the global cost reports page'
+ end
+
+ context 'as a user without adequate permissions' do
+ let(:current_user) { user_without_permissions }
+
+ it 'is not rendered' do
+ within '#main-menu' do
+ expect(page).not_to have_link(I18n.t(:cost_reports_title))
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/redmine/menu_manager_spec.rb b/spec/lib/redmine/menu_manager_spec.rb
index f59a93d17db..94ea1d6381b 100644
--- a/spec/lib/redmine/menu_manager_spec.rb
+++ b/spec/lib/redmine/menu_manager_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe Redmine::MenuManager do
context 'for the global_menu' do
it 'includes the expected items' do
expect(described_class.items(:global_menu).map(&:name))
- .to include(:home, :work_packages)
+ .to include(:home, :work_packages, :cost_reports_global)
end
end