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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix meeting participants filters
Oliver Günther8042738cad03
diff --git a/modules/meeting/app/models/queries/meetings/filters/attended_user_filter.rb b/modules/meeting/app/models/queries/meetings/filters/attended_user_filter.rbindex 1208d3ee04c..d2f9c64426f 100644--- a/modules/meeting/app/models/queries/meetings/filters/attended_user_filter.rb+++ b/modules/meeting/app/models/queries/meetings/filters/attended_user_filter.rb@@ -41,22 +41,42 @@ class Queries::Meetings::Filters::AttendedUserFilter < Queries::Meetings::Filterenddef where- "meeting_participants.user_id IN (#{values.join(',')}) AND meeting_participants.attended"+ condition = "#{MeetingParticipant.table_name}.attended"++ case operator+ when "="+ [operator_strategy.sql_for_field(values, MeetingParticipant.table_name, "user_id"), condition].join(" AND ")+ when "!"+ <<~SQL.squish+ NOT EXISTS (+ SELECT 1 FROM #{MeetingParticipant.table_name}+ WHERE #{MeetingParticipant.table_name}.meeting_id = meetings.id+ AND #{MeetingParticipant.table_name}.user_id = '#{MeetingParticipant.connection.quote_string(values.first)}'+ AND #{condition}+ )+ SQL+ when "*"+ ["#{MeetingParticipant.table_name}.user_id IS NOT NULL", condition].join(" AND ")+ when "!*"+ <<~SQL.squish+ NOT EXISTS (+ SELECT 1 FROM #{MeetingParticipant.table_name}+ WHERE #{MeetingParticipant.table_name}.meeting_id = meetings.id+ AND #{condition}+ )+ SQL+ endenddef human_nameI18n.t(:label_attended_user)end- def joins+ def left_outer_joins:participantsenddef self.key:attended_user_idend-- def available_operators- [::Queries::Operators::Equals]- endenddiff --git a/modules/meeting/app/models/queries/meetings/filters/invited_user_filter.rb b/modules/meeting/app/models/queries/meetings/filters/invited_user_filter.rbindex c9dd55b044e..101e39ed4ef 100644--- a/modules/meeting/app/models/queries/meetings/filters/invited_user_filter.rb+++ b/modules/meeting/app/models/queries/meetings/filters/invited_user_filter.rb@@ -41,17 +41,38 @@ class Queries::Meetings::Filters::InvitedUserFilter < Queries::Meetings::Filtersenddef where- [- operator_strategy.sql_for_field(values, MeetingParticipant.table_name, "user_id"),- "#{MeetingParticipant.table_name}.invited"- ].join(" AND ")+ condition = "#{MeetingParticipant.table_name}.invited"++ case operator+ when "="+ [operator_strategy.sql_for_field(values, MeetingParticipant.table_name, "user_id"), condition].join(" AND ")+ when "!"+ <<~SQL.squish+ NOT EXISTS (+ SELECT 1 FROM #{MeetingParticipant.table_name}+ WHERE #{MeetingParticipant.table_name}.meeting_id = meetings.id+ AND #{MeetingParticipant.table_name}.user_id = '#{MeetingParticipant.connection.quote_string(values.first)}'+ AND #{condition}+ )+ SQL+ when "*"+ ["#{MeetingParticipant.table_name}.user_id IS NOT NULL", condition].join(" AND ")+ when "!*"+ <<~SQL.squish+ NOT EXISTS (+ SELECT 1 FROM #{MeetingParticipant.table_name}+ WHERE #{MeetingParticipant.table_name}.meeting_id = meetings.id+ AND #{condition}+ )+ SQL+ endenddef human_nameI18n.t(:label_invited_user)end- def joins+ def left_outer_joins:participantsenddiff --git a/modules/meeting/spec/models/queries/meetings/filters/attended_user_filter_spec.rb b/modules/meeting/spec/models/queries/meetings/filters/attended_user_filter_spec.rbnew file mode 100644index 00000000000..618394128c6--- /dev/null+++ b/modules/meeting/spec/models/queries/meetings/filters/attended_user_filter_spec.rb@@ -0,0 +1,128 @@+# 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 Queries::Meetings::Filters::AttendedUserFilter do+ it_behaves_like "basic query filter" do+ let(:type) { :list_optional }+ let(:class_key) { :attended_user_id }+ let(:human_name) { I18n.t(:label_attended_user) }++ describe "#available?" do+ it "is true" do+ expect(instance).to be_available+ end+ end++ describe "#allowed_values" do+ it "is nil" do+ expect(instance.allowed_values).to be_nil+ end+ end+ end++ describe "#where clause" do+ let(:user1) { create(:user) }+ let(:user2) { create(:user) }+ let(:project) { create(:project) }+ let(:meeting1) { create(:meeting, project:) }+ let(:meeting2) { create(:meeting, project:) }+ let(:meeting3) { create(:meeting, project:) }+ let(:meeting4) { create(:meeting, project:) }+ let!(:empty_meeting) do+ create(:meeting, project:).tap { |meeting| meeting.participants.delete_all }+ end++ let!(:participant1) { create(:meeting_participant, :attendee, meeting: meeting1, user: user1) }+ let!(:participant2) { create(:meeting_participant, :attendee, meeting: meeting2, user: user2) }+ let!(:participant3) { create(:meeting_participant, :invitee, meeting: meeting3, user: user1) }+ let!(:participant4) { create(:meeting_participant, :invitee, meeting: meeting4, user: user2) }++ let(:instance) do+ described_class.create!(name: :attended_user_id, operator:, values:)+ end++ context 'for "="' do+ let(:operator) { "=" }+ let(:values) { [user1.id.to_s] }++ it "finds meetings where the user attended" do+ expect(instance.where).to include("#{MeetingParticipant.table_name}.user_id")++ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).to include(meeting1)+ expect(meetings).not_to include(meeting2)+ expect(meetings).not_to include(meeting3)+ expect(meetings).not_to include(meeting4)+ end+ end++ context 'for "!"' do+ let(:operator) { "!" }+ let(:values) { [user1.id.to_s] }++ it "finds meetings where the user did not attend" do+ expect(instance.where).to include("NOT")++ meetings = Meeting.left_outer_joins(:participants).where(instance.where)+ expect(meetings.pluck(:id)).to contain_exactly(meeting2.id, empty_meeting.id, meeting3.id, meeting4.id)+ end+ end++ context 'for "*"' do+ let(:operator) { "*" }+ let(:values) { [] }++ it "finds meetings with any attendee" do+ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).to include(meeting1)+ expect(meetings).to include(meeting2)+ expect(meetings).not_to include(meeting3)+ expect(meetings).not_to include(meeting4)+ end+ end++ context 'for "!*"' do+ let(:operator) { "!*" }+ let(:values) { [] }++ it "finds meetings with no attendees" do+ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).not_to include(meeting1)+ expect(meetings).not_to include(meeting2)+ expect(meetings).to include(meeting3)+ expect(meetings).to include(meeting4)+ end+ end+ end+enddiff --git a/modules/meeting/spec/models/queries/meetings/filters/invited_user_filter_spec.rb b/modules/meeting/spec/models/queries/meetings/filters/invited_user_filter_spec.rbnew file mode 100644index 00000000000..9d4c034de53--- /dev/null+++ b/modules/meeting/spec/models/queries/meetings/filters/invited_user_filter_spec.rb@@ -0,0 +1,128 @@+# 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 Queries::Meetings::Filters::InvitedUserFilter do+ it_behaves_like "basic query filter" do+ let(:type) { :list_optional }+ let(:class_key) { :invited_user_id }+ let(:human_name) { I18n.t(:label_invited_user) }++ describe "#available?" do+ it "is true" do+ expect(instance).to be_available+ end+ end++ describe "#allowed_values" do+ it "is nil" do+ expect(instance.allowed_values).to be_nil+ end+ end+ end++ describe "#where clause" do+ let(:user1) { create(:user) }+ let(:user2) { create(:user) }+ let(:project) { create(:project) }+ let(:meeting1) { create(:meeting, project:) }+ let(:meeting2) { create(:meeting, project:) }+ let(:meeting3) { create(:meeting, project:) }+ let(:meeting4) { create(:meeting, project:) }+ let!(:empty_meeting) do+ create(:meeting, project:).tap { |meeting| meeting.participants.delete_all }+ end++ let!(:participant1) { create(:meeting_participant, :invitee, meeting: meeting1, user: user1) }+ let!(:participant2) { create(:meeting_participant, :invitee, meeting: meeting2, user: user2) }+ let!(:participant3) { create(:meeting_participant, :attendee, meeting: meeting3, user: user1) }+ let!(:participant4) { create(:meeting_participant, meeting: meeting4, user: user2, invited: false, attended: false) }++ let(:instance) do+ described_class.create!(name: :invited_user_id, operator:, values:)+ end++ context 'for "="' do+ let(:operator) { "=" }+ let(:values) { [user1.id.to_s] }++ it "finds meetings where the user was invited" do+ expect(instance.where).to include("#{MeetingParticipant.table_name}.user_id")++ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).to include(meeting1)+ expect(meetings).not_to include(meeting2)+ expect(meetings).not_to include(meeting3)+ expect(meetings).not_to include(meeting4)+ end+ end++ context 'for "!"' do+ let(:operator) { "!" }+ let(:values) { [user1.id.to_s] }++ it "finds meetings where the user was not invited" do+ expect(instance.where).to include("NOT")++ meetings = Meeting.left_outer_joins(:participants).where(instance.where)+ expect(meetings.pluck(:id)).to contain_exactly(meeting2.id, empty_meeting.id, meeting3.id, meeting4.id)+ end+ end++ context 'for "*"' do+ let(:operator) { "*" }+ let(:values) { [] }++ it "finds meetings with any invitee" do+ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).to include(meeting1)+ expect(meetings).to include(meeting2)+ expect(meetings).not_to include(meeting3)+ expect(meetings).not_to include(meeting4)+ end+ end++ context 'for "!*"' do+ let(:operator) { "!*" }+ let(:values) { [] }++ it "finds meetings with no invitees" do+ meetings = Meeting.left_outer_joins(:participants).where(instance.where)++ expect(meetings).not_to include(meeting1)+ expect(meetings).not_to include(meeting2)+ expect(meetings).to include(meeting3)+ expect(meetings).to include(meeting4)+ end+ end+ end+end