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
use extension files for representer patching
ulferts7cebf2254cf8
diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rbindex 8e3f29006f0..22ee8f16ed6 100644--- a/modules/backlogs/lib/open_project/backlogs/engine.rb+++ b/modules/backlogs/lib/open_project/backlogs/engine.rb@@ -27,6 +27,10 @@#++require 'open_project/plugins'+require_relative './patches/api/work_package_representer'+require_relative './patches/api/work_package_schema_representer'+require_relative './patches/api/work_package_sums_representer'+require_relative './patches/api/work_package_sums_schema_representer'module OpenProject::Backlogsclass Engine < ::Rails::Engine@@ -133,100 +137,25 @@ module OpenProject::Backlogspatch_with_namespace :WorkPackages, :BaseContractconfig.to_prepare do- next if Versions::BaseContract.included_modules.include?(OpenProject::Backlogs::Patches::VersionBaseContractPatch)+ next if Versions::BaseContract.included_modules.include?(OpenProject::Backlogs::Patches::Versions::BaseContractPatch)- Versions::BaseContract.prepend(OpenProject::Backlogs::Patches::VersionBaseContractPatch)+ Versions::BaseContract.prepend(OpenProject::Backlogs::Patches::Versions::BaseContractPatch)end- extend_api_response(:v3, :work_packages, :work_package) do- property :position,- render_nil: true,- skip_render: ->(*) { !(backlogs_enabled? && type && type.passes_attribute_constraint?(:position)) }+ extend_api_response(:v3, :work_packages, :work_package,+ &::OpenProject::Backlogs::Patches::API::WorkPackageRepresenter.extension)- property :story_points,- render_nil: true,- skip_render: ->(*) { !(backlogs_enabled? && type && type.passes_attribute_constraint?(:story_points)) }+ extend_api_response(:v3, :work_packages, :work_package_payload,+ &::OpenProject::Backlogs::Patches::API::WorkPackageRepresenter.extension)- property :remaining_time,- exec_context: :decorator,- render_nil: true,- skip_render: ->(represented:, **) { !represented.backlogs_enabled? }+ extend_api_response(:v3, :work_packages, :schema, :work_package_schema,+ &::OpenProject::Backlogs::Patches::API::WorkPackageSchemaRepresenter.extension)- # cannot use def here as it wouldn't define the method on the representer- define_method :remaining_time do- datetime_formatter.format_duration_from_hours(represented.remaining_hours,- allow_nil: true)- end-- define_method :remaining_time= do |value|- remaining = datetime_formatter.parse_duration_to_hours(value,- 'remainingTime',- allow_nil: true)- represented.remaining_hours = remaining- end- end+ extend_api_response(:v3, :work_packages, :schema, :work_package_sums_schema,+ &::OpenProject::Backlogs::Patches::API::WorkPackageSumsSchemaRepresenter.extension)- extend_api_response(:v3, :work_packages, :schema, :work_package_schema) do- schema :position,- type: 'Integer',- required: false,- writable: false,- show_if: ->(*) {- represented.project && represented.project.backlogs_enabled? &&- (!represented.type || represented.type.passes_attribute_constraint?(:position))- }-- schema :story_points,- type: 'Integer',- required: false,- show_if: ->(*) {- represented.project && represented.project.backlogs_enabled? &&- (!represented.type || represented.type.passes_attribute_constraint?(:story_points))- }-- schema :remaining_time,- type: 'Duration',- name_source: :remaining_hours,- required: false,- show_if: ->(*) { represented.project && represented.project.backlogs_enabled? }- end-- extend_api_response(:v3, :work_packages, :schema, :work_package_sums_schema) do- schema :story_points,- type: 'Integer',- required: false,- show_if: ->(*) {- ::Setting.work_package_list_summable_columns.include?('story_points')- }-- schema :remaining_time,- type: 'Duration',- name_source: :remaining_hours,- required: false,- writable: false,- show_if: ->(*) {- ::Setting.work_package_list_summable_columns.include?('remaining_hours')- }- end-- extend_api_response(:v3, :work_packages, :work_package_sums) do- property :story_points,- render_nil: true,- if: ->(*) {- ::Setting.work_package_list_summable_columns.include?('story_points')- }-- property :remaining_time,- render_nil: true,- exec_context: :decorator,- getter: ->(*) {- datetime_formatter.format_duration_from_hours(represented.remaining_hours,- allow_nil: true)- },- if: ->(*) {- ::Setting.work_package_list_summable_columns.include?('remaining_hours')- }- end+ extend_api_response(:v3, :work_packages, :work_package_sums,+ &::OpenProject::Backlogs::Patches::API::WorkPackageSumsRepresenter.extension)add_api_attribute on: :work_package, ar_name: :story_pointsadd_api_attribute on: :work_package, ar_name: :remaining_hours, writeable: ->(*) { model.leaf? }diff --git a/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_representer.rb b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_representer.rbnew file mode 100644index 00000000000..763a5231fc7--- /dev/null+++ b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_representer.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module OpenProject::Backlogs+ module Patches+ module API+ module WorkPackageRepresenter+ module_function++ # rubocop:disable Metrics/AbcSize+ def extension+ ->(*) do+ property :position,+ render_nil: true,+ skip_render: ->(*) { !(backlogs_enabled? && type && type.passes_attribute_constraint?(:position)) }++ property :story_points,+ render_nil: true,+ skip_render: ->(*) { !(backlogs_enabled? && type && type.passes_attribute_constraint?(:story_points)) }++ property :remaining_time,+ exec_context: :decorator,+ render_nil: true,+ skip_render: ->(represented:, **) { !represented.backlogs_enabled? }++ # cannot use def here as it wouldn't define the method on the representer+ define_method :remaining_time do+ datetime_formatter.format_duration_from_hours(represented.remaining_hours,+ allow_nil: true)+ end++ define_method :remaining_time= do |value|+ remaining = datetime_formatter.parse_duration_to_hours(value,+ 'remainingTime',+ allow_nil: true)+ represented.remaining_hours = remaining+ end+ end+ end+ # rubocop:enable Metrics/AbcSize+ end+ end+ end+enddiff --git a/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_schema_representer.rb b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_schema_representer.rbnew file mode 100644index 00000000000..f3d35430cd7--- /dev/null+++ b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_schema_representer.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module OpenProject::Backlogs+ module Patches+ module API+ module WorkPackageSchemaRepresenter+ module_function++ # rubocop:disable Metrics/AbcSize+ def extension+ ->(*) do+ schema :position,+ type: 'Integer',+ required: false,+ writable: false,+ show_if: ->(*) {+ backlogs_constraint_passed?(:position)+ }++ schema :story_points,+ type: 'Integer',+ required: false,+ show_if: ->(*) {+ backlogs_constraint_passed?(:story_points)+ }++ schema :remaining_time,+ type: 'Duration',+ name_source: :remaining_hours,+ required: false,+ show_if: ->(*) { represented.project && represented.project.backlogs_enabled? }++ define_method :backlogs_constraint_passed? do |attribute|+ represented.project&.backlogs_enabled? &&+ (!represented.type || represented.type.passes_attribute_constraint?(attribute))+ end+ end+ end+ # rubocop:enable Metrics/AbcSize+ end+ end+ end+enddiff --git a/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_representer.rb b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_representer.rbnew file mode 100644index 00000000000..250c666cc23--- /dev/null+++ b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_representer.rb@@ -0,0 +1,58 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module OpenProject::Backlogs+ module Patches+ module API+ module WorkPackageSumsRepresenter+ module_function++ def extension+ ->(*) do+ property :story_points,+ render_nil: true,+ if: ->(*) {+ ::Setting.work_package_list_summable_columns.include?('story_points')+ }++ property :remaining_time,+ render_nil: true,+ exec_context: :decorator,+ getter: ->(*) {+ datetime_formatter.format_duration_from_hours(represented.remaining_hours,+ allow_nil: true)+ },+ if: ->(*) {+ ::Setting.work_package_list_summable_columns.include?('remaining_hours')+ }+ end+ end+ end+ end+ end+enddiff --git a/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_schema_representer.rb b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_schema_representer.rbnew file mode 100644index 00000000000..c9b7bad51c8--- /dev/null+++ b/modules/backlogs/lib/open_project/backlogs/patches/api/work_package_sums_schema_representer.rb@@ -0,0 +1,57 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module OpenProject::Backlogs+ module Patches+ module API+ module WorkPackageSumsSchemaRepresenter+ module_function++ def extension+ ->(*) do+ schema :story_points,+ type: 'Integer',+ required: false,+ show_if: ->(*) {+ ::Setting.work_package_list_summable_columns.include?('story_points')+ }++ schema :remaining_time,+ type: 'Duration',+ name_source: :remaining_hours,+ required: false,+ writable: false,+ show_if: ->(*) {+ ::Setting.work_package_list_summable_columns.include?('remaining_hours')+ }+ end+ end+ end+ end+ end+enddiff --git a/modules/backlogs/lib/open_project/backlogs/patches/version_base_contract_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/versions/base_contract_patch.rbsimilarity index 96%rename from modules/backlogs/lib/open_project/backlogs/patches/version_base_contract_patch.rbrename to modules/backlogs/lib/open_project/backlogs/patches/versions/base_contract_patch.rbindex cd9a1d6e829..c1b8b66903e 100644--- a/modules/backlogs/lib/open_project/backlogs/patches/version_base_contract_patch.rb+++ b/modules/backlogs/lib/open_project/backlogs/patches/versions/base_contract_patch.rb@@ -26,7 +26,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-module OpenProject::Backlogs::Patches::VersionBaseContractPatch+module OpenProject::Backlogs::Patches::Versions::BaseContractPatchprivatedef user_allowed_to_manage