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

register api patches immediately and raise when too late (#8311)

ulferts3c7bf61b559e
diff --git a/config/constants/api_patch_registry.rb b/config/constants/api_patch_registry.rb
index b24b6da669b..da5b02b1d74 100644
--- a/config/constants/api_patch_registry.rb
+++ b/config/constants/api_patch_registry.rb
@@ -34,6 +34,11 @@ module Constants
patch_map = patch_maps_by_class[class_name]
path = ":#{path}" if path.is_a?(Symbol)
+
+ if Object.const_defined?(class_name)
+ raise "Adding patch #{block} to #{class_name} after it is already loaded has no effect."
+ end
+
patch_map[path] = [] unless patch_map[path]
patch_map[path] << block
end
diff --git a/lib/open_project/plugins/acts_as_op_engine.rb b/lib/open_project/plugins/acts_as_op_engine.rb
index 22352b4e8e4..3d40bef7b8b 100644
--- a/lib/open_project/plugins/acts_as_op_engine.rb
+++ b/lib/open_project/plugins/acts_as_op_engine.rb
@@ -225,13 +225,11 @@ module OpenProject::Plugins
end
def add_api_endpoint(base_endpoint, path = nil, &block)
- config.to_prepare do
- # we are expecting the base_endpoint as string for two reasons:
- # 1. it does not seem possible to pass it as constant (auto loader not ready yet)
- # 2. we can't constantize it here, because that would evaluate
- # the API before it can be patched
- ::Constants::APIPatchRegistry.add_patch base_endpoint, path, &block
- end
+ # we are expecting the base_endpoint as string for two reasons:
+ # 1. it does not seem possible to pass it as constant (auto loader not ready yet)
+ # 2. we can't constantize it here, because that would evaluate
+ # the API before it can be patched
+ ::Constants::APIPatchRegistry.add_patch base_endpoint, path, &block
end
def extend_api_response(*args, &block)