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

prevent overwriting _type property in SqlCollectionRepresenter subclasses

Christophe Bliard1e4b4f250c87
diff --git a/lib/api/decorators/sql/hal.rb b/lib/api/decorators/sql/hal.rb
index aeff7de219b..f2313a32f68 100644
--- a/lib/api/decorators/sql/hal.rb
+++ b/lib/api/decorators/sql/hal.rb
@@ -52,7 +52,7 @@ module API
selected_properties(select)
.map do |name, options|
representation = if options[:representation]
- options[:representation].call(walker_results)
+ instance_exec(walker_results, &options[:representation])
else
options[:column]
end
diff --git a/lib/api/decorators/sql_collection_representer.rb b/lib/api/decorators/sql_collection_representer.rb
index 11a958d8ddb..ebca2749cfb 100644
--- a/lib/api/decorators/sql_collection_representer.rb
+++ b/lib/api/decorators/sql_collection_representer.rb
@@ -44,7 +44,7 @@ module API
private
- def select_from(walker_result)
+ def select_from(_walker_result)
"projection"
end
@@ -81,10 +81,14 @@ module API
end
end
end
+
+ def _type
+ 'Collection'
+ end
end
property :_type,
- representation: ->(*) { "'Collection'" }
+ representation: ->(*) { "'#{_type}'" }
property :count,
representation: ->(*) { "COUNT(*)" }
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.rb
index 738375c5150..f7d05f51f69 100644
--- a/lib/api/v3/work_packages/work_package_sql_collection_representer.rb
+++ b/lib/api/v3/work_packages/work_package_sql_collection_representer.rb
@@ -32,8 +32,9 @@ module API
elements: WorkPackageSqlRepresenter
}.with_indifferent_access
- property :_type,
- representation: ->(*) { "'WorkPackageCollection'" }
+ def self._type
+ 'WorkPackageCollection'
+ end
end
end
end