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
stub for signaling on work package resource
ulfertsa80767f516a5
diff --git a/app/services/api/v3/work_package_collection_from_query_service.rb b/app/services/api/v3/work_package_collection_from_query_service.rbindex 1226013791e..0667fb23951 100644--- a/app/services/api/v3/work_package_collection_from_query_service.rb+++ b/app/services/api/v3/work_package_collection_from_query_service.rb@@ -30,7 +30,7 @@ module APImodule V3class WorkPackageCollectionFromQueryServiceinclude Utilities::PathHelper- include ::API::Utilities::PageSizeHelper+ include ::API::Utilities::UrlPropsParsingHelperdef initialize(query, user, scope: nil)self.query = query@@ -88,6 +88,8 @@ module APIparams[:offset] = to_i_or_nil(params[:offset])params[:pageSize] = pageSizeParam(params)end++ params[:select] = nested_from_csv(provided_params['select'])endend@@ -147,18 +149,27 @@ module APIdef collection_representer(work_packages, params:, project:, groups:, sums:)resulting_params = calculate_resulting_params(params)- ::API::V3::WorkPackages::WorkPackageCollectionRepresenter.new(- work_packages,- self_link: self_link(project),- project: project,- query: resulting_params,- page: resulting_params[:offset],- per_page: resulting_params[:pageSize],- groups: groups,- total_sums: sums,- embed_schemas: true,- current_user: current_user- )+ if resulting_params[:select]+ ::API::V3::Utilities::SqlRepresenterWalker+ .new(work_packages,+ current_user: current_user,+ self_path: self_link(project),+ url_query: resulting_params)+ .walk(::API::V3::WorkPackages::WorkPackageSqlCollectionRepresenter)+ else+ ::API::V3::WorkPackages::WorkPackageCollectionRepresenter.new(+ work_packages,+ self_link: self_link(project),+ project: project,+ query: resulting_params,+ page: resulting_params[:offset],+ per_page: resulting_params[:pageSize],+ groups: groups,+ total_sums: sums,+ embed_schemas: true,+ current_user: current_user+ )+ endenddef to_i_or_nil(value)diff --git a/docs/api/apiv3/paths/project_work_packages.yml b/docs/api/apiv3/paths/project_work_packages.ymlindex c50067e8fdf..dd22bd7d78b 100644--- a/docs/api/apiv3/paths/project_work_packages.yml+++ b/docs/api/apiv3/paths/project_work_packages.yml@@ -60,6 +60,14 @@ get:schema:default: 'false'type: boolean+ - description: |-+ Comma separated list of properties to include.+ example: 'total,elements/subject,elements/id,self'+ in: query+ name: select+ required: false+ schema:+ type: stringresponses:'200':content:diff --git a/docs/api/apiv3/paths/work_packages.yml b/docs/api/apiv3/paths/work_packages.ymlindex 2317662641d..be6b312366c 100644--- a/docs/api/apiv3/paths/work_packages.yml+++ b/docs/api/apiv3/paths/work_packages.yml@@ -111,6 +111,14 @@ get:schema:default: 'false'type: boolean+ - description: |-+ Comma separated list of properties to include.+ example: 'total,elements/subject,elements/id,self'+ in: query+ name: select+ required: false+ schema:+ type: stringresponses:'200':content:diff --git a/lib/api/decorators/offset_paginated_collection.rb b/lib/api/decorators/offset_paginated_collection.rbindex 124c5e7a8ca..6349c765833 100644--- a/lib/api/decorators/offset_paginated_collection.rb+++ b/lib/api/decorators/offset_paginated_collection.rb@@ -31,7 +31,7 @@module APImodule Decoratorsclass OffsetPaginatedCollection < ::API::Decorators::Collection- include ::API::Utilities::PageSizeHelper+ include ::API::Utilities::UrlPropsParsingHelperdef self.per_page_default(relation)relation.base_class.per_pagediff --git a/lib/api/decorators/sql_collection_representer.rb b/lib/api/decorators/sql_collection_representer.rbindex 87dc6cf944f..11a958d8ddb 100644--- a/lib/api/decorators/sql_collection_representer.rb+++ b/lib/api/decorators/sql_collection_representer.rb@@ -35,7 +35,10 @@ module APIdef ctes(walker_result){projection: walker_result.projection_scope.limit(sql_limit(walker_result)).offset(sql_offset(walker_result)).to_sql,- total: walker_result.filter_scope.reselect('COUNT(*)').except(:order).to_sql+ # Currently there does not appear to be a way to correctly transform the filter_scope into sql+ # (e.g. by calling #to_sql) so that the extra call to the database is avoided. The main problem+ # is that LEFT JOINS added via includes are not part of the SQL generated by #to_sql.+ total: "SELECT #{walker_result.filter_scope.count}"}enddiff --git a/lib/api/utilities/endpoints/index.rb b/lib/api/utilities/endpoints/index.rbindex 9b188c37cf6..33851ecbd97 100644--- a/lib/api/utilities/endpoints/index.rb+++ b/lib/api/utilities/endpoints/index.rb@@ -30,7 +30,7 @@ module APImodule Utilitiesmodule Endpointsclass Index- include ::API::Utilities::PageSizeHelper+ include ::API::Utilities::UrlPropsParsingHelperdef initialize(model:,api_name: model.name.demodulize,diff --git a/lib/api/utilities/page_size_helper.rb b/lib/api/utilities/url_props_parsing_helper.rbsimilarity index 74%rename from lib/api/utilities/page_size_helper.rbrename to lib/api/utilities/url_props_parsing_helper.rbindex eeef7bd13d9..c1c0d65615c 100644--- a/lib/api/utilities/page_size_helper.rb+++ b/lib/api/utilities/url_props_parsing_helper.rb@@ -30,7 +30,7 @@module APImodule Utilities- module PageSizeHelper+ module UrlPropsParsingHelper### Determine set page_size from stringdef resolve_page_size(string)@@ -68,6 +68,29 @@ module APIdef to_i_or_nil(string)string ? string.to_i : nilend++ # Parses a comma separated list of values and turns it into+ # a nested hash. e.g.:+ # = "a,b/c/d,e,b/f"+ # is turned into:+ # = { "a" => {}, "e" => {}, "b" => { "c" => { "d" => {} }, "f" => {} } }+ # The order of the values does not matter.+ # It also accepts an array of individual strings, e.g.:+ # = ["a","b/c/d","e","b/f"]+ def nested_from_csv(value)+ return unless value++ value+ .delete_prefix('[')+ .delete_suffix(']')+ .split(',')+ .map { |path| nested_hash(path.strip.tr("\"'", '').split('/')) }+ .inject({}) { |hash, nested| hash.deep_merge(nested) }+ end++ def nested_hash(path)+ { path[0] => path.length > 1 ? nested_hash(path[1..]) : {} }+ endendendenddiff --git a/lib/api/v3/memberships/memberships_api.rb b/lib/api/v3/memberships/memberships_api.rbindex ff678a7da42..1eb5129c008 100644--- a/lib/api/v3/memberships/memberships_api.rb+++ b/lib/api/v3/memberships/memberships_api.rb@@ -30,7 +30,7 @@ module APImodule V3module Membershipsclass MembershipsAPI < ::API::OpenProjectAPI- helpers ::API::Utilities::PageSizeHelper+ helpers ::API::Utilities::UrlPropsParsingHelperresources :memberships doget &::API::V3::Utilities::Endpoints::Indexdiff --git a/lib/api/v3/utilities/endpoints/sql_index.rb b/lib/api/v3/utilities/endpoints/sql_index.rbindex 0486c47e9b3..80c471c75b5 100644--- a/lib/api/v3/utilities/endpoints/sql_index.rb+++ b/lib/api/v3/utilities/endpoints/sql_index.rb@@ -54,26 +54,9 @@ module APIdef calculate_resulting_params(query, provided_params)super.tap do |params|- params[:select] = nested_from_params(provided_params, 'select') || { '*' => {}, 'elements' => { '*' => {} } }+ params[:select] = nested_from_csv(provided_params['select']) || { '*' => {}, 'elements' => { '*' => {} } }endend-- def nested_from_params(params, key)- key_params = params[key]-- return unless key_params-- key_params- .delete_prefix('[')- .delete_suffix(']')- .split(',')- .map { |path| nested_hash(path.strip.tr("\"'", '').split('/')) }- .inject({}) { |hash, nested| hash.deep_merge(nested) }- end-- def nested_hash(path)- { path[0] => path.length > 1 ? nested_hash(path[1..]) : {} }- endendendenddiff --git a/lib/api/v3/utilities/sql_representer_walker.rb b/lib/api/v3/utilities/sql_representer_walker.rbindex b30f4692d67..308df32e713 100644--- a/lib/api/v3/utilities/sql_representer_walker.rb+++ b/lib/api/v3/utilities/sql_representer_walker.rb@@ -32,7 +32,7 @@ module APImodule V3module Utilitiesclass SqlRepresenterWalker- include API::Utilities::PageSizeHelper+ include API::Utilities::UrlPropsParsingHelperdef initialize(scope,current_user:,diff --git a/lib/api/v3/work_packages/watchers_api.rb b/lib/api/v3/work_packages/watchers_api.rbindex 2fb4f359b8c..52d17d04622 100644--- a/lib/api/v3/work_packages/watchers_api.rb+++ b/lib/api/v3/work_packages/watchers_api.rb@@ -32,7 +32,7 @@ module APImodule V3module WorkPackagesclass WatchersAPI < ::API::OpenProjectAPI- helpers ::API::Utilities::PageSizeHelper+ helpers ::API::Utilities::UrlPropsParsingHelperget '/available_watchers' doauthorize(:add_work_package_watchers, context: @work_package.project)diff --git a/lib/api/v3/work_packages/work_package_sql_collection_representer.rb b/lib/api/v3/work_packages/work_package_sql_collection_representer.rbnew file mode 100644index 00000000000..d19a5301ad7--- /dev/null+++ b/lib/api/v3/work_packages/work_package_sql_collection_representer.rb@@ -0,0 +1,37 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-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 API+ module V3+ module WorkPackages+ class WorkPackageSqlCollectionRepresenter < API::Decorators::SqlCollectionRepresenter+ self.embed_map = {+ elements: WorkPackageSqlRepresenter+ }.with_indifferent_access+ end+ end+ end+enddiff --git a/lib/api/v3/work_packages/work_package_sql_representer.rb b/lib/api/v3/work_packages/work_package_sql_representer.rbnew file mode 100644index 00000000000..878449ac402--- /dev/null+++ b/lib/api/v3/work_packages/work_package_sql_representer.rb@@ -0,0 +1,47 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-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 API+ module V3+ module WorkPackages+ class WorkPackageSqlRepresenter+ include API::Decorators::Sql::Hal++ link :self,+ path: { api: :work_package, params: %w(id) },+ column: -> { :id },+ title: -> { 'subject' }++ property :_type,+ representation: ->(*) { "'WorkPackage'" }++ property :id++ property :subject+ end+ end+ end+enddiff --git a/modules/costs/lib/api/v3/time_entries/time_entries_api.rb b/modules/costs/lib/api/v3/time_entries/time_entries_api.rbindex eb90c6d7a42..2a413eaea0f 100644--- a/modules/costs/lib/api/v3/time_entries/time_entries_api.rb+++ b/modules/costs/lib/api/v3/time_entries/time_entries_api.rb@@ -30,7 +30,7 @@ module APImodule V3module TimeEntriesclass TimeEntriesAPI < ::API::OpenProjectAPI- helpers ::API::Utilities::PageSizeHelper+ helpers ::API::Utilities::UrlPropsParsingHelperresources :time_entries doget &::API::V3::Utilities::Endpoints::Index.new(model: TimeEntry).mountdiff --git a/modules/documents/lib/api/v3/documents/documents_api.rb b/modules/documents/lib/api/v3/documents/documents_api.rbindex abfe0bd0f07..64273c8f786 100644--- a/modules/documents/lib/api/v3/documents/documents_api.rb+++ b/modules/documents/lib/api/v3/documents/documents_api.rb@@ -30,7 +30,7 @@ module APImodule V3module Documentsclass DocumentsAPI < ::API::OpenProjectAPI- helpers ::API::Utilities::PageSizeHelper+ helpers ::API::Utilities::UrlPropsParsingHelperresources :documents doget dodiff --git a/modules/grids/app/controllers/api/v3/grids/grids_api.rb b/modules/grids/app/controllers/api/v3/grids/grids_api.rbindex 82cfaf78d58..7422f749ed5 100644--- a/modules/grids/app/controllers/api/v3/grids/grids_api.rb+++ b/modules/grids/app/controllers/api/v3/grids/grids_api.rb@@ -32,7 +32,7 @@ module APIclass GridsAPI < ::API::OpenProjectAPIresources :grids dohelpers do- include API::Utilities::PageSizeHelper+ include API::Utilities::UrlPropsParsingHelperendget dodiff --git a/spec/lib/api/utilities/page_size_helper_spec.rb b/spec/lib/api/utilities/url_props_parsing_helper_spec.rbsimilarity index 94%rename from spec/lib/api/utilities/page_size_helper_spec.rbrename to spec/lib/api/utilities/url_props_parsing_helper_spec.rbindex 322a084f78e..1f22ad4a867 100644--- a/spec/lib/api/utilities/page_size_helper_spec.rb+++ b/spec/lib/api/utilities/url_props_parsing_helper_spec.rb@@ -28,10 +28,10 @@require 'spec_helper'-describe ::API::Utilities::PageSizeHelper do+describe ::API::Utilities::UrlPropsParsingHelper dolet(:clazz) doClass.new do- include ::API::Utilities::PageSizeHelper+ include ::API::Utilities::UrlPropsParsingHelperendendlet(:subject) { clazz.new }diff --git a/spec/lib/api/v3/work_packages/work_package_sql_representer_rendering_spec.rb b/spec/lib/api/v3/work_packages/work_package_sql_representer_rendering_spec.rbnew file mode 100644index 00000000000..015aedf830b--- /dev/null+++ b/spec/lib/api/v3/work_packages/work_package_sql_representer_rendering_spec.rb@@ -0,0 +1,74 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-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.++require 'spec_helper'++describe ::API::V3::WorkPackages::WorkPackageSqlRepresenter, 'rendering' do+ include ::API::V3::Utilities::PathHelper++ subject(:json) do+ ::API::V3::Utilities::SqlRepresenterWalker+ .new(scope,+ current_user: current_user,+ url_query: { select: select })+ .walk(described_class)+ .to_json+ end++ let(:scope) do+ WorkPackage+ .where(id: rendered_work_package.id)+ end++ let(:rendered_work_package) { create(:work_package) }++ let(:select) { { '*' => {} } }++ current_user do+ create(:user)+ end++ context 'when rendering all supported properties' do+ let(:expected) do+ {+ _type: "WorkPackage",+ id: rendered_work_package.id,+ subject: rendered_work_package.subject,+ _links: {+ self: {+ href: api_v3_paths.work_package(rendered_work_package.id),+ title: rendered_work_package.subject+ }+ }+ }+ end++ it 'renders as expected' do+ expect(json)+ .to be_json_eql(expected.to_json)+ end+ end+end