From c5cf9d5a8df9aa24c496a03d71803fd04b7d4c20 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 29 Nov 2024 19:04:01 +0300 Subject: [PATCH 1/3] Remove activity menu for anonymous users with login required --- config/initializers/menus.rb | 1 + lib/redmine/menu_manager/top_menu_helper.rb | 2 ++ spec/features/menu_items/top_menu_item_spec.rb | 6 ------ 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb index e52606a27690..a0b9cb130832 100644 --- a/config/initializers/menus.rb +++ b/config/initializers/menus.rb @@ -43,6 +43,7 @@ menu.push :activity, { controller: "/activities", action: "index" }, context: :modules, + if: Proc.new { User.current.logged? || !Setting.login_required? }, icon: "history" menu.push :work_packages, diff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rb index 1881d9b12bf4..ec8391d3a23f 100644 --- a/lib/redmine/menu_manager/top_menu_helper.rb +++ b/lib/redmine/menu_manager/top_menu_helper.rb @@ -215,6 +215,8 @@ def more_top_menu_items def module_top_menu_item_groups items = more_top_menu_items + return items if items.empty? + item_groups = [] # add untitled group, if no heading is present diff --git a/spec/features/menu_items/top_menu_item_spec.rb b/spec/features/menu_items/top_menu_item_spec.rb index 16612c19ad4f..e25d4c3e8705 100644 --- a/spec/features/menu_items/top_menu_item_spec.rb +++ b/spec/features/menu_items/top_menu_item_spec.rb @@ -138,12 +138,6 @@ def click_link_in_open_menu(title) context "as an anonymous user" do let(:user) { create(:anonymous) } - context "when login_required", with_settings: { login_required: true } do - it "redirects to login" do - expect(page).to have_current_path /login/ - end - end - context "when not login_required", with_settings: { login_required: false } do it "displays only projects, activity and news" do has_menu_items? project_item, activity_item, news_item From b602ffd41cf5f11248165a15513a71f876dee2e7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 4 Dec 2024 09:56:31 +0300 Subject: [PATCH 2/3] Fix spec --- spec/features/menu_items/top_menu_item_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/features/menu_items/top_menu_item_spec.rb b/spec/features/menu_items/top_menu_item_spec.rb index e25d4c3e8705..99ed9849a026 100644 --- a/spec/features/menu_items/top_menu_item_spec.rb +++ b/spec/features/menu_items/top_menu_item_spec.rb @@ -67,7 +67,7 @@ def click_link_in_open_menu(title) end describe "Modules" do - let!(:top_menu) { find("[title=#{I18n.t('label_modules')}]") } + let(:top_menu) { find("[title=#{I18n.t('label_modules')}]") } shared_let(:menu_link_item) { Struct.new(:label, :path) } @@ -138,6 +138,14 @@ def click_link_in_open_menu(title) context "as an anonymous user" do let(:user) { create(:anonymous) } + context "when login_required", with_settings: { login_required: true } do + let(:open_menu) { false } + + it "redirects to login" do + expect(page).to have_current_path /login/ + end + end + context "when not login_required", with_settings: { login_required: false } do it "displays only projects, activity and news" do has_menu_items? project_item, activity_item, news_item From eac1fa87a0b923c4010e8be43597ff588c3dc854 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 10 Dec 2024 16:58:00 +0300 Subject: [PATCH 3/3] Review patch: return empty item groups --- lib/redmine/menu_manager/top_menu_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rb index ec8391d3a23f..e8e9b2ee3463 100644 --- a/lib/redmine/menu_manager/top_menu_helper.rb +++ b/lib/redmine/menu_manager/top_menu_helper.rb @@ -214,10 +214,9 @@ def more_top_menu_items end def module_top_menu_item_groups - items = more_top_menu_items - return items if items.empty? - item_groups = [] + items = more_top_menu_items + return item_groups if items.blank? # add untitled group, if no heading is present unless items.first.heading?