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

[#43677] Extend Notification representer to include the date lines

Dombi Attilab0ce64e6ac14
diff --git a/docs/api/apiv3/components/schemas/notification_collection_model.yml b/docs/api/apiv3/components/schemas/notification_collection_model.yml
index b3c6be3e606..59c0e5d3020 100644
--- a/docs/api/apiv3/components/schemas/notification_collection_model.yml
+++ b/docs/api/apiv3/components/schemas/notification_collection_model.yml
@@ -17,21 +17,21 @@ allOf:
- $ref: "./link.yml"
- description: |-
This notification collection
-
+
**Resource**: NotificationCollectionModel
jumpTo:
allOf:
- $ref: "./link.yml"
- description: |-
The notification collection at another offset
-
+
**Resource**: NotificationCollectionModel
changeSize:
allOf:
- $ref: "./link.yml"
- description: |-
The notification collection with another size
-
+
**Resource**: NotificationCollectionModel
_embedded:
type: object
@@ -58,7 +58,12 @@ example:
- _hint: Notification resource shortened for brevity
id: 2
readIAN: false
- reason: mentioned
+ reason: date_alert
+ message:
+ - property: 'startDate'
+ value: '2022-10-05'
+ - property: 'stopDate'
+ value: '2022-10-10'
_links:
self:
href: '/api/v3/notifications?offset=1&pageSize=20'
diff --git a/docs/api/apiv3/components/schemas/notification_model.yml b/docs/api/apiv3/components/schemas/notification_model.yml
index 776d7f93a5f..0482fb36368 100644
--- a/docs/api/apiv3/components/schemas/notification_model.yml
+++ b/docs/api/apiv3/components/schemas/notification_model.yml
@@ -12,10 +12,42 @@ properties:
minimum: 1
reason:
type: string
- description: The reason for the notification (such as mentioned, involved, watched)
+ description: The reason for the notification
+ enum:
+ - assigned
+ - commented
+ - created
+ - date_alert
+ - mentioned
+ - prioritized
+ - processed
+ - responsible
+ - subscribed
+ - scheduled
+ - watched
readIAN:
type: boolean
description: Whether the notification is marked as read
+ message:
+ type: array
+ items:
+ allOf:
+ - type: object
+ properties:
+ property:
+ type: string
+ description: |-
+ The name of the message's property. It can vary based on the reason provided.
+ For example, the "date_alert" reason can be associated with either a "startDate" or a "dueDate".
+ value:
+ type: string
+ description: |-
+ The value associated with the property, it can hold any arbitrary string
+ or a datetime value in ISO 8601 format.
+ - description: |-
+ It provides additional information on constructing a user friendly message.
+ One or more properties can be associated with a message, their number can vary depending
+ on the reason provided.
createdAt:
type: string
format: date-time
@@ -100,6 +132,9 @@ example:
id: 1
readIAN: false
reason: mentioned
+ message:
+ - property: 'startDate'
+ value: '2022-04-06'
createdAt: '2022-04-05T14:38:28Z'
updatedAt: '2022-04-06T09:03:24Z'
_embedded:
diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb
index 42eb4c05b2d..48dccec7fec 100644
--- a/lib/api/v3/notifications/notification_representer.rb
+++ b/lib/api/v3/notifications/notification_representer.rb
@@ -43,6 +43,21 @@ module API
property :reason
+ property :message,
+ exec_context: :decorator,
+ getter: ->(*) do
+ next unless represented.reason == 'date_alert'
+
+ changes = represented.journal.get_changes
+ if changes[:start_date]
+ [{ startDate: datetime_formatter.format_date(changes[:start_date].last) }]
+ elsif changes[:due_date]
+ [{ dueDate: datetime_formatter.format_date(changes[:due_date].last) }]
+ else
+ []
+ end
+ end
+
date_time_property :created_at
date_time_property :updated_at
diff --git a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
index 29537dd57c2..c53a097db22 100644
--- a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
@@ -39,6 +39,7 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
let(:recipient) { build_stubbed(:user) }
let(:journal) { nil }
let(:actor) { nil }
+ let(:reason) { :mentioned }
let(:notification) do
build_stubbed :notification,
recipient:,
@@ -46,6 +47,7 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
resource:,
journal:,
actor:,
+ reason:,
read_ian:
end
let(:representer) do
@@ -112,6 +114,45 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
it_behaves_like 'datetime property', :updatedAt do
let(:value) { notification.updated_at }
end
+
+ it 'is expected to not have a message' do
+ expect(subject).not_to have_json_path('message')
+ end
+
+ context 'when the reason is date alert' do
+ let(:journal) { resource.journals.last }
+ let(:reason) { :date_alert }
+
+ context 'when the startDate is happening soon' do
+ before do
+ journal.data.update!(start_date: Date.tomorrow)
+ end
+
+ it_behaves_like 'date property', 'message/0/startDate' do
+ let(:value) { Date.tomorrow }
+ end
+ end
+
+ context 'when the dueDate is happening soon' do
+ before do
+ journal.data.update!(due_date: Date.tomorrow)
+ end
+
+ it_behaves_like 'date property', 'message/0/dueDate' do
+ let(:value) { Date.tomorrow }
+ end
+ end
+
+ context 'when the dueDate is in the past (overdue)' do
+ before do
+ journal.data.update!(due_date: Date.yesterday)
+ end
+
+ it_behaves_like 'date property', 'message/0/dueDate' do
+ let(:value) { Date.yesterday }
+ end
+ end
+ end
end
describe 'project' do