From a0653b6986101db8e446aeb2fcb345c8ba8603d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 18 Dec 2024 14:46:42 +0100 Subject: [PATCH 1/2] Set participants only when present --- .../meetings/set_attributes_service.rb | 2 +- .../meeting/spec/requests/meetings_spec.rb | 2 - .../create_service_integration_spec.rb | 91 +++++++++++++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 modules/meeting/spec/services/meetings/create_service_integration_spec.rb diff --git a/modules/meeting/app/services/meetings/set_attributes_service.rb b/modules/meeting/app/services/meetings/set_attributes_service.rb index dd2ca21fe0cb..abe44c0d3a9a 100644 --- a/modules/meeting/app/services/meetings/set_attributes_service.rb +++ b/modules/meeting/app/services/meetings/set_attributes_service.rb @@ -33,7 +33,7 @@ def set_attributes(params) super - set_participants(participants) if participants + set_participants(participants) if participants.present? end def set_default_attributes(_params) diff --git a/modules/meeting/spec/requests/meetings_spec.rb b/modules/meeting/spec/requests/meetings_spec.rb index cc21843fdb57..cd6b7af0b80e 100644 --- a/modules/meeting/spec/requests/meetings_spec.rb +++ b/modules/meeting/spec/requests/meetings_spec.rb @@ -141,8 +141,6 @@ let(:send_notifications) { "1" } before do - meeting.participants.create!(user:, invited: true) - subject perform_enqueued_jobs end diff --git a/modules/meeting/spec/services/meetings/create_service_integration_spec.rb b/modules/meeting/spec/services/meetings/create_service_integration_spec.rb new file mode 100644 index 000000000000..973eb83bedeb --- /dev/null +++ b/modules/meeting/spec/services/meetings/create_service_integration_spec.rb @@ -0,0 +1,91 @@ +#-- 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 Meetings::CreateService, "integration", type: :model do + shared_let(:project) { create(:project, enabled_module_names: %i[meetings]) } + shared_let(:user) do + create(:user, member_with_permissions: { project => %i(view_meetings create_meetings) }) + end + shared_let(:other_user) do + create(:user, member_with_permissions: { project => %i(view_meetings) }) + end + let(:instance) { described_class.new(user:) } + let(:service_result) { subject } + let(:series) { service_result.result } + let(:params) { {} } + let(:default_params) do + { + project:, + title: "My test meeting" + } + end + + subject { instance.call(**params, **default_params) } + + describe "participants" do + context "when passed" do + let(:params) do + { + participants_attributes: [ + { user_id: other_user.id, invited: true, attended: true } + ] + } + end + + it "creates that meeting with that one participant" do + expect(subject).to be_success + expect(subject.result.participants.count).to eq(1) + expect(subject.result.participants.first.user).to eq(other_user) + end + end + + context "when passed as empty" do + let(:params) do + { + participants_attributes: {} + } + end + + it "creates the meeting with default" do + expect(subject).to be_success + expect(subject.result.participants.count).to eq(1) + expect(subject.result.participants.first.user).to eq(user) + end + end + + context "when not passed" do + it "creates the meeting with default" do + expect(subject).to be_success + expect(subject.result.participants.count).to eq(1) + expect(subject.result.participants.first.user).to eq(user) + end + end + end +end From 27bedfb2ae942ae8ce1bed7e234d5323faf31d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 18 Dec 2024 14:56:05 +0100 Subject: [PATCH 2/2] Don't add default filter if param is provided --- .../app/controllers/meetings_controller.rb | 2 +- .../spec/features/meetings_index_spec.rb | 42 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb index b708fac84c00..af3e93508f02 100644 --- a/modules/meeting/app/controllers/meetings_controller.rb +++ b/modules/meeting/app/controllers/meetings_controller.rb @@ -348,7 +348,7 @@ def apply_time_filter_and_sort(query) end def apply_default_filter_if_none_given(query) - return if query.filters.any? + return if params.key?(:filters) query.where("invited_user_id", "=", [User.current.id.to_s]) end diff --git a/modules/meeting/spec/features/meetings_index_spec.rb b/modules/meeting/spec/features/meetings_index_spec.rb index d4350d0df2f9..c585368a9d5c 100644 --- a/modules/meeting/spec/features/meetings_index_spec.rb +++ b/modules/meeting/spec/features/meetings_index_spec.rb @@ -49,13 +49,13 @@ end end - let(:meeting) do + shared_let(:meeting) do create(:meeting, project:, title: "Awesome meeting today!", start_time: Time.current) end - let(:tomorrows_meeting) do + shared_let(:tomorrows_meeting) do create(:meeting, project:, title: "Awesome meeting tomorrow!", @@ -63,25 +63,25 @@ duration: 2.0, location: "no-protocol.com") end - let(:meeting_with_no_location) do + shared_let(:meeting_with_no_location) do create(:meeting, project:, title: "Boring meeting without a location!", start_time: 1.day.from_now, location: "") end - let(:meeting_with_malicious_location) do + shared_let(:meeting_with_malicious_location) do create(:meeting, project:, title: "Sneaky meeting!", start_time: 1.day.from_now, location: "") end - let(:yesterdays_meeting) do + shared_let(:yesterdays_meeting) do create(:meeting, project:, title: "Awesome meeting yesterday!", start_time: 1.day.ago) end - let(:other_project_meeting) do + shared_let(:other_project_meeting) do create(:meeting, project: other_project, title: "Awesome other project meeting!", @@ -89,7 +89,7 @@ duration: 2.0, location: "not-a-url") end - let(:ongoing_meeting) do + shared_let(:ongoing_meeting) do create(:meeting, project:, title: "Awesome ongoing meeting!", start_time: 30.minutes.ago) end @@ -109,6 +109,22 @@ def invite_to_meeting(meeting) end shared_examples "sidebar filtering" do |context:| + context "when showing all meetings without invitations" do + it "does not show under My meetings, but in All meetings" do + meetings_page.visit! + expect(page).to have_content "There is currently nothing to display." + + meetings_page.set_sidebar_filter "All meetings" + + # It now includes the ongoing meeting I'm not invited to + if context == :global + [ongoing_meeting, meeting, tomorrows_meeting, other_project_meeting] + else + [ongoing_meeting, meeting, tomorrows_meeting] + end + end + end + context "when showing all meetings with the sidebar" do before do ongoing_meeting @@ -124,11 +140,13 @@ def invite_to_meeting(meeting) end it "shows all upcoming and ongoing meetings", :aggregate_failures do - expected_upcoming_meetings = if context == :global - [ongoing_meeting, meeting, tomorrows_meeting, other_project_meeting] - else - [ongoing_meeting, meeting, tomorrows_meeting] - end + expected_upcoming_meetings = + if context == :global + [ongoing_meeting, meeting, tomorrows_meeting, meeting_with_no_location, + meeting_with_malicious_location, other_project_meeting] + else + [ongoing_meeting, meeting, tomorrows_meeting, meeting_with_no_location, meeting_with_malicious_location] + end meetings_page.expect_meetings_listed_in_order(*expected_upcoming_meetings) meetings_page.expect_meetings_not_listed(yesterdays_meeting)