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

Deal with anonymous user in meeting menu

Oliver Günther9926ac30a8ce
diff --git a/modules/meeting/app/menus/meetings/menu.rb b/modules/meeting/app/menus/meetings/menu.rb
index d3840389505..e1a0985b84b 100644
--- a/modules/meeting/app/menus/meetings/menu.rb
+++ b/modules/meeting/app/menus/meetings/menu.rb
@@ -35,21 +35,33 @@ module Meetings
[
OpenProject::Menu::MenuGroup.new(header: nil, children: top_level_menu_items),
OpenProject::Menu::MenuGroup.new(header: I18n.t(:label_meeting_series), children: meeting_series_menu_items),
- OpenProject::Menu::MenuGroup.new(header: I18n.t(:label_involvement), children: involvement_sidebar_menu_items)
+ involvement_group
].compact
end
def top_level_menu_items
+ [
+ my_meetings_item,
+ recurring_menu_item,
+ all_meetings_item
+ ].compact
+ end
+
+ def my_meetings_item
+ return unless User.current.logged?
+
+ my_meetings_href = polymorphic_path([project, :meetings])
+ menu_item(title: I18n.t(:label_my_meetings),
+ selected: params[:current_href] == my_meetings_href && params[:filters].blank?)
+ end
+
+ def all_meetings_item
all_filter = [{ invited_user_id: { operator: "*", values: [] } }].to_json
my_meetings_href = polymorphic_path([project, :meetings])
- [
- menu_item(title: I18n.t(:label_my_meetings),
- selected: params[:current_href] == my_meetings_href && params[:filters].blank?),
- recurring_menu_item,
- menu_item(title: I18n.t(:label_all_meetings),
- query_params: { filters: all_filter })
- ]
+ menu_item(title: I18n.t(:label_all_meetings),
+ selected: User.current.anonymous? && params[:current_href] == my_meetings_href && params[:filters].blank?,
+ query_params: { filters: all_filter })
end
def meeting_series_menu_items
@@ -80,6 +92,12 @@ module Meetings
query_params: { filters: recurring_filter, sort: "start_time" })
end
+ def involvement_group
+ return unless User.current.logged?
+
+ OpenProject::Menu::MenuGroup.new(header: I18n.t(:label_involvement), children: involvement_sidebar_menu_items)
+ end
+
def involvement_sidebar_menu_items
invitation_filter = [{ invited_user_id: { operator: "=", values: [User.current.id.to_s] } }].to_json
diff --git a/modules/meeting/spec/requests/meetings_menu_spec.rb b/modules/meeting/spec/requests/meetings_menu_spec.rb
new file mode 100644
index 00000000000..751f02fbdb4
--- /dev/null
+++ b/modules/meeting/spec/requests/meetings_menu_spec.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 "Meeting index menu",
+ :skip_csrf,
+ type: :rails_request do
+ shared_let(:project) { create(:public_project, enabled_module_names: %i[meetings]) }
+ shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_meetings] }) }
+
+ let(:request) do
+ get "/projects/#{project.id}/meetings/menu",
+ params: { current_href: "/projects/#{project.identifier}/meetings" }
+ end
+
+ subject do
+ request
+ response
+ end
+
+ before do
+ login_as user
+ end
+
+ describe "with normal user that can see meetings" do
+ it "shows all meetings and involvements" do
+ request
+
+ expect(page).to have_css(".op-submenu--item-action.selected", text: "My meetings")
+ expect(page).to have_text "All meetings"
+ expect(page).to have_text "Involvement"
+ expect(page).to have_text "Invitations"
+ expect(page).to have_text "Created by me"
+ expect(page).to have_text "Attended"
+ end
+ end
+
+ describe "with anonymous user that can see meetings" do
+ let(:user) do
+ create(:anonymous_role, permissions: %i[view_project view_meetings])
+ User.anonymous
+ end
+
+ context "when login required", with_settings: { login_required: true } do
+ it "redirects to login" do
+ expect(subject).to redirect_to(signin_path(back_url: menu_project_meetings_url(project.id)))
+ end
+ end
+
+ context "when login not required", with_settings: { login_required: false } do
+ it "shows all meetings, but no involvements" do
+ request
+
+ expect(page).to have_css(".op-submenu--item-action.selected", text: "All meetings")
+ expect(page).to have_no_text "My meetings"
+ expect(page).to have_no_text "Involvement"
+ expect(page).to have_no_text "Invitations"
+ expect(page).to have_no_text "Created by me"
+ expect(page).to have_no_text "Attended"
+ end
+ end
+ end
+end