[#40228] added linkable work packages filter

pull/10248/head
Eric Schubert 3 years ago
parent 1e9b6c5228
commit 1d7049a4e2
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 1
      app/models/work_package.rb
  2. 4
      modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb
  3. 49
      modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_id_filter.rb
  4. 50
      modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_url_filter.rb
  5. 5
      modules/storages/lib/open_project/storages/engine.rb

@ -61,6 +61,7 @@ class WorkPackage < ApplicationRecord
has_many :time_entries, dependent: :delete_all
has_many :file_links, dependent: :delete_all, class_name: 'Storages::FileLink', foreign_key: 'container_id'
has_many :storages, through: :project
has_and_belongs_to_many :changesets, -> {
order("#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC")

@ -32,10 +32,6 @@ module Queries::Storages::WorkPackages::Filter
:list
end
def available_operators
[::Queries::Operators::Equals]
end
def allowed_values
# Allow all input values that are given to the filter.
# If no result is found, an empty collection is returned.

@ -0,0 +1,49 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 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::Storages::WorkPackages::Filter
class LinkableToStorageIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
def type
:list
end
def allowed_values
# Allow all input values that are given to the filter.
# If no result is found, an empty collection is returned.
values.map { |value| [nil, value] }
end
def where
::Queries::Operators::Equals.sql_for_field(values, ::Storages::Storage.table_name, 'id')
end
def joins
:storages
end
end
end

@ -0,0 +1,50 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 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::Storages::WorkPackages::Filter
class LinkableToStorageUrlFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
def type
:list
end
def allowed_values
# Allow all input values that are given to the filter.
# If no result is found, an empty collection is returned.
values.map { |value| [nil, value] }
end
def where
canonical_url_values = values.map { |value| CGI.unescape(value).gsub(/\/+$/, '') }
::Queries::Operators::Equals.sql_for_field(canonical_url_values, ::Storages::Storage.table_name, 'host')
end
def joins
:storages
end
end
end

@ -80,9 +80,12 @@ module OpenProject::Storages
config.to_prepare do
::Queries::Register.filter ::Query, ::Queries::Storages::WorkPackages::Filter::FileLinkOriginIdFilter
::Queries::Register.filter ::Query, ::Queries::Storages::WorkPackages::Filter::LinkableToStorageIdFilter
::Queries::Register.filter ::Query, ::Queries::Storages::WorkPackages::Filter::LinkableToStorageUrlFilter
end
# ToDo: Why is there |storage_id|? Is this a kind of manual routes.rb?
# This helper methods adds a method on the `api_v3_paths` helper. It is created with one parameter (storage_id)
# and the return value is a string.
add_api_path :storage do |storage_id|
"#{root}/storages/#{storage_id}"
end

Loading…
Cancel
Save