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
[#40228] added file origin id filter
Eric Schubert1e9b6c522839
diff --git a/app/models/work_package.rb b/app/models/work_package.rbindex 0e5731860a3..94579eb4bf8 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -60,6 +60,8 @@ class WorkPackage < ApplicationRecordhas_many :time_entries, dependent: :delete_all+ has_many :file_links, dependent: :delete_all, class_name: 'Storages::FileLink', foreign_key: 'container_id'+has_and_belongs_to_many :changesets, -> {order("#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC")}diff --git a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb b/modules/storages/app/models/queries/storages/file_links/file_link_query.rbindex 82ae4ef00de..7b3418e4976 100644--- a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb+++ b/modules/storages/app/models/queries/storages/file_links/file_link_query.rb@@ -1,16 +1,45 @@-# ToDo: Copyright notice missing-# Purpose: ???+#-- 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.+#++++# Purpose: When returning a collection of file links, our standard index endpoint needs a query class to have a+# reference to the embedded model.# Used by: ???# Reference: ToDo: Link to documentation about queries-# Why is there a Queries::Storages namespace?+# The namespace is programmatically derived from the model name. See app/services/params_to_query_service.rb:130class Queries::Storages::FileLinks::FileLinkQuery < Queries::BaseQuery# What is class << self?class << self- # Why model?+ # We need to overwrite the model method, as the standard implementation cannot derive the name from nested+ # namespaces. See app/models/queries/base_query.rb:31def model- # Where is the model needed? From where is it called?- # ToDo: What is constantize?+ # '.constantize' finds a declared constant with the specified name.+ # A NameError is raised, if it is not initialized.@model ||= '::Storages::FileLink'.constantizeendenddiff --git a/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rbnew file mode 100644index 00000000000..2ffa64a9bd3--- /dev/null+++ b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb@@ -0,0 +1,53 @@+#-- 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 FileLinkOriginIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter+ def type+ :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.+ values.map { |value| [nil, value] }+ end++ def where+ ::Queries::Operators::Equals.sql_for_field(values, ::Storages::FileLink.table_name, 'origin_id')+ end++ def joins+ :file_links+ end+ end+enddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex f96be17300c..b5517fa69fd 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -78,6 +78,10 @@ module OpenProject::Storagesparent: :settingsend+ config.to_prepare do+ ::Queries::Register.filter ::Query, ::Queries::Storages::WorkPackages::Filter::FileLinkOriginIdFilter+ end+# ToDo: Why is there |storage_id|? Is this a kind of manual routes.rb?add_api_path :storage do |storage_id|"#{root}/storages/#{storage_id}"diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 686e956c0b5..a7a53f9bd20 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -237,18 +237,6 @@ describe 'API v3 file links resource', type: :request doendend- describe 'GET /api/v3/work_packages/:work_package_id/file_links/:file_link_id/download' do- let(:path) { api_v3_paths.file_link_download(work_package.id, file_link.id) }-- before do- get path- end-- it 'returns not implemented' do- expect(subject.status).to be 501- end- end-describe 'GET /api/v3/work_packages/:work_package_id/file_links/:file_link_id/open' dolet(:path) { api_v3_paths.file_link_open(work_package.id, file_link.id) }