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

Include detailsSchemas in the NotificationCollectionRepresenter

Dombi Attila1d53e91a69e6
diff --git a/lib/api/v3/notifications/notification_collection_representer.rb b/lib/api/v3/notifications/notification_collection_representer.rb
index 728506f34d7..2df15c5d2f3 100644
--- a/lib/api/v3/notifications/notification_collection_representer.rb
+++ b/lib/api/v3/notifications/notification_collection_representer.rb
@@ -30,6 +30,11 @@ module API
module V3
module Notifications
class NotificationCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
+ property :detailsSchemas,
+ getter: ->(*) { ::API::V3::Values::Schemas::ValueSchemaFactory.all },
+ exec_context: :decorator,
+ embedded: true
+
def initialize(models, self_link:, current_user:, query: {}, page: nil, per_page: nil, groups: nil)
super
diff --git a/lib/api/v3/values/schemas/value_schema_factory.rb b/lib/api/v3/values/schemas/value_schema_factory.rb
index 3956acb91ed..ca16c919e2f 100644
--- a/lib/api/v3/values/schemas/value_schema_factory.rb
+++ b/lib/api/v3/values/schemas/value_schema_factory.rb
@@ -29,6 +29,7 @@
module API::V3::Values::Schemas
module ValueSchemaFactory
extend ::API::V3::Utilities::PathHelper
+ SUPPORTED = %w(start_date due_date).freeze
module_function
@@ -41,10 +42,14 @@ module API::V3::Values::Schemas
self_link: api_v3_paths.value_schema(property))
end
+ def all
+ SUPPORTED.map { |property| self.for(property) }
+ end
+
def supported?(property)
# This is but a stub. Currently, only 'start_date' and 'due_date'
# need to be supported so this simple approach works.
- %w(start_date due_date).include?(property)
+ SUPPORTED.include?(property)
end
def model_for(property)
diff --git a/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb b/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
index c00bd0cef78..81fe6ca29f6 100644
--- a/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
+++ b/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
@@ -79,6 +79,11 @@ describe ::API::V3::Notifications::NotificationCollectionRepresenter do
it_behaves_like 'offset-paginated APIv3 collection', 3, 'notifications', 'Notification'
+ it 'renders the available detailsSchemas' do
+ details_schemas = ::API::V3::Values::Schemas::ValueSchemaFactory.all
+ expect(subject).to be_json_eql(details_schemas.to_json).at_path('_embedded/detailsSchemas')
+ end
+
context 'when passing groups' do
let(:groups) do
[