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
Add AlsoProjectMemberFilter for members
Klaus Zanders43545ef76f25
diff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rbindex 1de3f4f24e1..e17d90911f4 100644--- a/app/components/work_packages/share/modal_body_component.rb+++ b/app/components/work_packages/share/modal_body_component.rb@@ -89,7 +89,7 @@ module WorkPackages]end- def type_filter_option_active?(option)+ def type_filter_option_active?(_option)# Todofalseend@@ -109,11 +109,9 @@ module WorkPackagesunless type_option.nil? || type_filter_option_active?(type_option)if type_option[:value][:project_member]- # Todo- # filter.push({ entity_and_project_member: { operator: "=", values: [params[:work_package_id]] } })+ filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_TRUE] } })else- # Todo- # filter.push({ entity_and_no_project_member: { operator: "=", values: [params[:work_package_id]] } })+ filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_FALSE] } })endfilter.push({ principal_type: { operator: "=", values: [type_option[:value][:principal_type]] } })diff --git a/app/models/queries/members.rb b/app/models/queries/members.rbindex 67c35b6928b..f3611073e18 100644--- a/app/models/queries/members.rb+++ b/app/models/queries/members.rb@@ -41,6 +41,7 @@ module Queries::Membersfilter Filters::UpdatedAtFilterfilter Filters::EntityIdFilterfilter Filters::EntityTypeFilter+ filter Filters::AlsoProjectMemberFilterorder Orders::DefaultOrderorder Orders::NameOrderdiff --git a/app/models/queries/members/filters/also_project_member_filter.rb b/app/models/queries/members/filters/also_project_member_filter.rbnew file mode 100644index 00000000000..812782e1ad4--- /dev/null+++ b/app/models/queries/members/filters/also_project_member_filter.rb@@ -0,0 +1,62 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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.+#++++class Queries::Members::Filters::AlsoProjectMemberFilter < Queries::Members::Filters::MemberFilter+ include Queries::Filters::Shared::BooleanFilter++ def where+ if allowed_values.first.intersect?(values)+ "EXISTS (#{project_member_subquery})"+ else+ "NOT EXISTS (#{project_member_subquery})"++ end+ end++ def available_operators+ [::Queries::Operators::BooleanEquals]+ end++ def type_strategy+ @type_strategy ||= ::Queries::Filters::Strategies::BooleanListStrict.new self+ end++ private++ def project_member_subquery+ <<~SQL.squish+ SELECT 1 FROM "members" as "project_members"+ WHERE+ project_members.user_id = members.user_id AND+ project_members.project_id = members.project_id AND+ project_members.entity_type IS NULL AND+ project_members.entity_id IS NULL+ project_members.id != members.id+ SQL+ end+enddiff --git a/spec/models/queries/members/filters/also_project_member_filter_spec.rb b/spec/models/queries/members/filters/also_project_member_filter_spec.rbnew file mode 100644index 00000000000..b2083452ecc--- /dev/null+++ b/spec/models/queries/members/filters/also_project_member_filter_spec.rb@@ -0,0 +1,70 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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::Members::Filters::AlsoProjectMemberFilter do+ it_behaves_like 'boolean query filter', scope: false do+ let(:model) { Member }+ let(:attribute) { nil }++ let(:exists_query) do+ <<~SQL.squish+ SELECT 1 FROM "members" as "project_members"+ WHERE+ project_members.user_id = members.user_id AND+ project_members.project_id = members.project_id AND+ project_members.entity_type IS NULL AND+ project_members.entity_id IS NULL+ project_members.id != members.id+ SQL+ end++ describe '#where' do+ let(:operator) { '=' }++ context 'for true' do+ let(:values) { [OpenProject::Database::DB_VALUE_TRUE] }++ it 'is the same as handwriting the query' do+ expected = expected_base_scope.where("EXISTS (#{exists_query})")+ expect(instance.scope.to_sql).to eql expected.to_sql+ end+ end++ context 'for false' do+ let(:values) { [OpenProject::Database::DB_VALUE_FALSE] }++ it 'is the same as handwriting the query' do+ expected = expected_base_scope.where("NOT EXISTS (#{exists_query})")+ expect(instance.scope.to_sql).to eql expected.to_sql+ end+ end+ end+ end+end