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

[#36743] draft of wp ancestor filter

Tobias Dillmannfd26dc354f4c
diff --git a/app/models/queries/work_packages.rb b/app/models/queries/work_packages.rb
index d5f6540f6d7..1e584636859 100644
--- a/app/models/queries/work_packages.rb
+++ b/app/models/queries/work_packages.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -28,6 +30,7 @@
module Queries::WorkPackages
::Queries::Register.register(Query) do
+ filter Filter::AncestorFilter
filter Filter::AssignedToFilter
filter Filter::AssigneeOrGroupFilter
filter Filter::AttachmentContentFilter
diff --git a/app/models/queries/work_packages/filter/ancestor_filter.rb b/app/models/queries/work_packages/filter/ancestor_filter.rb
new file mode 100644
index 00000000000..786cda045de
--- /dev/null
+++ b/app/models/queries/work_packages/filter/ancestor_filter.rb
@@ -0,0 +1,47 @@
+# 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::WorkPackages::Filter::AncestorFilter <
+ Queries::WorkPackages::Filter::WorkPackageFilter
+ include ::Queries::WorkPackages::Filter::FilterForWpMixin
+
+ # TODO all of the below is just copied. Change!
+ def relation_type
+ # While this is not a relation (in the sense of it being stored in a different database table) we still
+ # want it to be used same as every other relation filter.
+ Relation::TYPE_PARENT
+ end
+
+ def where
+ # The filter had been called parent before and it is stored in the database like that.
+ # The other association filters all have _id in their self.key.
+ operator_strategy.sql_for_field(no_templated_values, self.class.model.table_name, :parent_id)
+ end
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ffa453101c6..5f2d38c7129 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1136,6 +1136,7 @@ en:
parent_title: "Parent page"
redirect_existing_links: "Redirect existing links"
work_package:
+ ancestor: "Ancestor"
begin_insertion: "Begin of the insertion"
begin_deletion: "Begin of the deletion"
children: "Subelements"
diff --git a/lib/api/v3/queries/schemas/ancestor_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/ancestor_filter_dependency_representer.rb
new file mode 100644
index 00000000000..18edabe60b2
--- /dev/null
+++ b/lib/api/v3/queries/schemas/ancestor_filter_dependency_representer.rb
@@ -0,0 +1,39 @@
+# 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 API
+ module V3
+ module Queries
+ module Schemas
+ class AncestorFilterDependencyRepresenter < ByWorkPackageFilterDependencyRepresenter; end
+ end
+ end
+ end
+end