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

Only show archived projects filter for admins

Klaus Zanders344c2c5a35c5
diff --git a/app/helpers/menus/projects.rb b/app/helpers/menus/projects.rb
index dc5e5ea63e7..76db83891d8 100644
--- a/app/helpers/menus/projects.rb
+++ b/app/helpers/menus/projects.rb
@@ -60,8 +60,8 @@ module Menus
::Queries::Projects::Factory::STATIC_ACTIVE,
::Queries::Projects::Factory::STATIC_MY,
::Queries::Projects::Factory::STATIC_FAVORED,
- ::Queries::Projects::Factory::STATIC_ARCHIVED
- ]
+ current_user.admin? ? ::Queries::Projects::Factory::STATIC_ARCHIVED : nil
+ ].compact
end
def status_static_filters
diff --git a/spec/helpers/menus/projects_spec.rb b/spec/helpers/menus/projects_spec.rb
index 594aee6aaed..8dfa6436e98 100644
--- a/spec/helpers/menus/projects_spec.rb
+++ b/spec/helpers/menus/projects_spec.rb
@@ -59,6 +59,26 @@ RSpec.describe Menus::Projects do
describe "children items" do
subject(:children_menu_items) { first_level_menu_items.flat_map(&:children) }
+ context "when the current user is an admin" do
+ before do
+ allow(current_user).to receive(:admin?).and_return(true)
+ end
+
+ it "has an archived projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.archived")))
+ end
+ end
+
+ context "when the current user is not an admin" do
+ before do
+ allow(current_user).to receive(:admin?).and_return(false)
+ end
+
+ it "has an archived projects item" do
+ expect(children_menu_items).not_to include(have_attributes(title: I18n.t("projects.lists.archived")))
+ end
+ end
+
it "contains menu items" do
expect(children_menu_items).to all(be_a(OpenProject::Menu::MenuItem))
end