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
Implement status operator for versions, similar to work packages
Oliver Güntherc3a37508b5b5
diff --git a/app/models/queries/operators/versions/closed_status.rb b/app/models/queries/operators/versions/closed_status.rbnew file mode 100644index 00000000000..cf882c2a4a6--- /dev/null+++ b/app/models/queries/operators/versions/closed_status.rb@@ -0,0 +1,43 @@+# 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.+# ++++module Queries::Operators+ module Versions+ class ClosedStatus < ::Queries::Operators::Base+ label "closed"+ set_symbol "c"+ require_value false++ def self.sql_for_field(_values, _db_table, _db_field)+ "#{Version.table_name}.status = 'closed'"+ end+ end+ end+enddiff --git a/app/models/queries/operators/versions/locked_status.rb b/app/models/queries/operators/versions/locked_status.rbnew file mode 100644index 00000000000..4bd5779fad0--- /dev/null+++ b/app/models/queries/operators/versions/locked_status.rb@@ -0,0 +1,43 @@+# 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.+# ++++module Queries::Operators+ module Versions+ class LockedStatus < ::Queries::Operators::Base+ label "locked"+ set_symbol "l"+ require_value false++ def self.sql_for_field(_values, _db_table, _db_field)+ "#{Version.table_name}.status = 'locked'"+ end+ end+ end+enddiff --git a/app/models/queries/operators/versions/open_status.rb b/app/models/queries/operators/versions/open_status.rbnew file mode 100644index 00000000000..e30acae5fa6--- /dev/null+++ b/app/models/queries/operators/versions/open_status.rb@@ -0,0 +1,43 @@+# 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.+# ++++module Queries::Operators+ module Versions+ class OpenStatus < ::Queries::Operators::Base+ label "open"+ set_symbol "o"+ require_value false++ def self.sql_for_field(_values, _db_table, _db_field)+ "#{Version.table_name}.status = 'open'"+ end+ end+ end+enddiff --git a/app/models/queries/versions/filters/status_filter.rb b/app/models/queries/versions/filters/status_filter.rbnew file mode 100644index 00000000000..bdf53d71473--- /dev/null+++ b/app/models/queries/versions/filters/status_filter.rb@@ -0,0 +1,45 @@+# 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.+#++++class Queries::Versions::Filters::StatusFilter < Queries::Versions::Filters::VersionFilter+ def allowed_values+ Version::VERSION_STATUSES.map do |name|+ [I18n.t(:"version_status_#{name}"), name]+ end+ end++ def type+ :list+ end++ def self.key+ :status+ end+enddiff --git a/app/models/queries/work_packages/filter/version_filter.rb b/app/models/queries/work_packages/filter/version_filter.rbindex 45685835bf8..500ff681f0e 100644--- a/app/models/queries/work_packages/filter/version_filter.rb+++ b/app/models/queries/work_packages/filter/version_filter.rb@@ -35,6 +35,17 @@ class Queries::WorkPackages::Filter::VersionFilter <@allowed_values ||= versions.pluck(:id).map { |id| [id.to_s, id.to_s] }end+ def available_operators+ [+ Queries::Operators::EqualsOr,+ Queries::Operators::NotEquals,+ Queries::Operators::All,+ Queries::Operators::Versions::OpenStatus,+ Queries::Operators::Versions::LockedStatus,+ Queries::Operators::Versions::ClosedStatus+ ]+ end+def type:list_optionalend@@ -43,6 +54,13 @@ class Queries::WorkPackages::Filter::VersionFilter <WorkPackage.human_attribute_name("version")end+ def joins+ case operator+ when "o", "c", "l"+ :version+ end+ end+def self.key:version_idend@@ -58,6 +76,19 @@ class Queries::WorkPackages::Filter::VersionFilter <.filter_map { |version_id| available_versions[version_id.to_i] }end+ def operator_strategy+ case operator+ when "o"+ Queries::Operators::Versions::OpenStatus+ when "c"+ Queries::Operators::Versions::ClosedStatus+ when "l"+ Queries::Operators::Versions::LockedStatus+ else+ super+ end+ end+privatedef versionsdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 5a76305b5af..b1bf372a57b 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3082,6 +3082,7 @@ en:label_link_url: "Link (URL)"label_list: "List"label_loading: "Loading..."+ label_locked: "locked"label_lock_user: "Lock user"label_logged_as: "Logged in as"label_login: "Sign in"@@ -3176,6 +3177,8 @@ en:label_operator_equals_or: "is (OR)"label_operator_equals_all: "is (AND)"label_operator_shared_with_user_any: "any"+ label_open: "open"+ label_closed: "closed"label_open_menu: "Open menu"label_open_work_packages: "open"label_open_work_packages_plural: "open"diff --git a/spec/models/queries/operators/versions/closed_status_spec.rb b/spec/models/queries/operators/versions/closed_status_spec.rbnew file mode 100644index 00000000000..d560ddf247f--- /dev/null+++ b/spec/models/queries/operators/versions/closed_status_spec.rb@@ -0,0 +1,77 @@+# 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::Operators::Versions::ClosedStatus do+ describe ".label_key" do+ it "returns the correct label key" do+ expect(described_class.label_key).to eq("label_closed")+ end+ end++ describe ".symbol" do+ it "returns the correct symbol" do+ expect(described_class.symbol).to eq("c")+ end+ end++ describe ".requires_value?" do+ it "does not require a value" do+ expect(described_class.requires_value?).to be false+ end+ end++ describe ".sql_for_field" do+ it "returns the correct SQL condition" do+ expected_sql = "#{Version.table_name}.status = 'closed'"++ expect(described_class.sql_for_field([], nil, nil))+ .to eq(expected_sql)+ end+ end++ describe ".human_name" do+ it "returns the localized name" do+ expect(described_class.human_name).to eq(I18n.t("label_closed"))+ end+ end++ describe ".to_sym" do+ it "returns the symbol as a symbol" do+ expect(described_class.to_sym).to eq(:c)+ end+ end++ describe ".to_query" do+ it "returns the URL-escaped symbol" do+ expect(described_class.to_query).to eq("c")+ end+ end+enddiff --git a/spec/models/queries/operators/versions/locked_status_spec.rb b/spec/models/queries/operators/versions/locked_status_spec.rbnew file mode 100644index 00000000000..17538e5df57--- /dev/null+++ b/spec/models/queries/operators/versions/locked_status_spec.rb@@ -0,0 +1,77 @@+# 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::Operators::Versions::LockedStatus do+ describe ".label_key" do+ it "returns the correct label key" do+ expect(described_class.label_key).to eq("label_locked")+ end+ end++ describe ".symbol" do+ it "returns the correct symbol" do+ expect(described_class.symbol).to eq("l")+ end+ end++ describe ".requires_value?" do+ it "does not require a value" do+ expect(described_class.requires_value?).to be false+ end+ end++ describe ".sql_for_field" do+ it "returns the correct SQL condition" do+ expected_sql = "#{Version.table_name}.status = 'locked'"++ expect(described_class.sql_for_field([], nil, nil))+ .to eq(expected_sql)+ end+ end++ describe ".human_name" do+ it "returns the localized name" do+ expect(described_class.human_name).to eq(I18n.t("label_locked"))+ end+ end++ describe ".to_sym" do+ it "returns the symbol as a symbol" do+ expect(described_class.to_sym).to eq(:l)+ end+ end++ describe ".to_query" do+ it "returns the URL-escaped symbol" do+ expect(described_class.to_query).to eq("l")+ end+ end+enddiff --git a/spec/models/queries/operators/versions/open_status_spec.rb b/spec/models/queries/operators/versions/open_status_spec.rbnew file mode 100644index 00000000000..360074ef667--- /dev/null+++ b/spec/models/queries/operators/versions/open_status_spec.rb@@ -0,0 +1,77 @@+# 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::Operators::Versions::OpenStatus do+ describe ".label_key" do+ it "returns the correct label key" do+ expect(described_class.label_key).to eq("label_open")+ end+ end++ describe ".symbol" do+ it "returns the correct symbol" do+ expect(described_class.symbol).to eq("o")+ end+ end++ describe ".requires_value?" do+ it "does not require a value" do+ expect(described_class.requires_value?).to be false+ end+ end++ describe ".sql_for_field" do+ it "returns the correct SQL condition" do+ expected_sql = "#{Version.table_name}.status = 'open'"++ expect(described_class.sql_for_field([], nil, nil))+ .to eq(expected_sql)+ end+ end++ describe ".human_name" do+ it "returns the localized name" do+ expect(described_class.human_name).to eq(I18n.t("label_open"))+ end+ end++ describe ".to_sym" do+ it "returns the symbol as a symbol" do+ expect(described_class.to_sym).to eq(:o)+ end+ end++ describe ".to_query" do+ it "returns the URL-escaped symbol" do+ expect(described_class.to_query).to eq("o")+ end+ end+enddiff --git a/spec/models/queries/versions/filters/status_filter_spec.rb b/spec/models/queries/versions/filters/status_filter_spec.rbnew file mode 100644index 00000000000..bf5170cccc0--- /dev/null+++ b/spec/models/queries/versions/filters/status_filter_spec.rb@@ -0,0 +1,51 @@+# 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::Versions::Filters::StatusFilter do+ include_context "filter tests"+ let(:values) { ["open"] }+ let(:model) { Version }++ it_behaves_like "basic query filter" do+ let(:class_key) { :status }+ let(:human_name) { "Status" }+ let(:type) { :list }+ let(:model) { Version }++ describe "#allowed_values" do+ it "is nil" do+ expect(instance.allowed_values)+ .to eq [%w[open open], %w[locked locked], %w[closed closed]]+ end+ end+ end+enddiff --git a/spec/models/queries/work_packages/filter/version_filter_spec.rb b/spec/models/queries/work_packages/filter/version_filter_spec.rbindex 87835e18ae7..0a8cd4ff5e3 100644--- a/spec/models/queries/work_packages/filter/version_filter_spec.rb+++ b/spec/models/queries/work_packages/filter/version_filter_spec.rb@@ -123,5 +123,63 @@ RSpec.describe Queries::WorkPackages::Filter::VersionFilter do.to contain_exactly(version1)endend++ describe "#available_operators" do+ it "includes the version status operators" do+ expect(instance.available_operators).to include(+ Queries::Operators::Versions::OpenStatus,+ Queries::Operators::Versions::ClosedStatus,+ Queries::Operators::Versions::LockedStatus+ )+ end+ end++ describe "#operator_strategy" do+ context "for open status operator" do+ let(:operator) { "o" }++ it "returns OpenStatus operator" do+ expect(instance.operator_strategy).to eq(Queries::Operators::Versions::OpenStatus)+ end+ end++ context "for closed status operator" do+ let(:operator) { "c" }++ it "returns ClosedStatus operator" do+ expect(instance.operator_strategy).to eq(Queries::Operators::Versions::ClosedStatus)+ end+ end++ context "for locked status operator" do+ let(:operator) { "l" }++ it "returns LockedStatus operator" do+ expect(instance.operator_strategy).to eq(Queries::Operators::Versions::LockedStatus)+ end+ end+ end++ describe "#joins" do+ context "for status operators" do+ %w[o c l].each do |op|+ context "with operator '#{op}'" do+ let(:operator) { op }++ it "returns :version" do+ expect(instance.joins).to eq(:version)+ end+ end+ end+ end++ context "for other operators" do+ let(:operator) { "=" }++ it "returns nil" do+ expect(instance.joins).to be_nil+ end+ end+ endendend