From 4f62bedced4935bf8e4b3be281c12d61a22a0c05 Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Thu, 14 Dec 2023 13:56:07 +0100 Subject: [PATCH 1/2] Enable the subscription of the reported request event --- src/api/app/services/notification_service/notifier.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/app/services/notification_service/notifier.rb b/src/api/app/services/notification_service/notifier.rb index 78184ea72ef..f7de6e99000 100644 --- a/src/api/app/services/notification_service/notifier.rb +++ b/src/api/app/services/notification_service/notifier.rb @@ -15,6 +15,7 @@ class Notifier 'Event::ReportForPackage', 'Event::ReportForComment', 'Event::ReportForUser', + 'Event::ReportForRequest', 'Event::ClearedDecision', 'Event::FavoredDecision', 'Event::WorkflowRunFail', @@ -40,6 +41,7 @@ class Notifier 'Event::ReportForPackage', 'Event::ReportForComment', 'Event::ReportForUser', + 'Event::ReportForRequest', 'Event::ClearedDecision', 'Event::FavoredDecision', 'Event::WorkflowRunFail'].freeze From 1a68fd01992610f46e637fa5a69b014d991033ab Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Thu, 14 Dec 2023 14:25:14 +0100 Subject: [PATCH 2/2] Implement the Notification of the Reported Request The notification contains the reason because the request was reported and the link pointing to the reported request. --- .../components/notification_action_description_component.rb | 2 ++ .../app/components/notification_notifiable_link_component.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/api/app/components/notification_action_description_component.rb b/src/api/app/components/notification_action_description_component.rb index 509e1adf9c3..fbd9ecb9e35 100644 --- a/src/api/app/components/notification_action_description_component.rb +++ b/src/api/app/components/notification_action_description_component.rb @@ -47,6 +47,8 @@ def description_text # TODO: Remove `Event::CreateReport` after all existing records are migrated to the new STI classes when 'Event::CreateReport', 'Event::ReportForProject', 'Event::ReportForPackage', 'Event::ReportForUser' "'#{@notification.notifiable.user.login}' created a report for a #{@notification.event_payload['reportable_type'].downcase}. This is the reason:" + when 'Event::ReportForRequest' + "'#{@notification.notifiable.user.login}' created a report for a request. This is the reason:" when 'Event::ReportForComment' "'#{@notification.notifiable.user.login}' created a report for a comment from #{@notification.event_payload['commenter']}. This is the reason:" when 'Event::ClearedDecision' diff --git a/src/api/app/components/notification_notifiable_link_component.rb b/src/api/app/components/notification_notifiable_link_component.rb index 4965e221431..0ce74fd7127 100644 --- a/src/api/app/components/notification_notifiable_link_component.rb +++ b/src/api/app/components/notification_notifiable_link_component.rb @@ -57,6 +57,8 @@ def notifiable_link_text end when 'Event::ReportForProject', 'Event::ReportForPackage' @notification.event_type.constantize.notification_link_text(@notification.event_payload) + when 'Event::ReportForRequest' + "Report for Request ##{@notification.notifiable.reportable.number}" when 'Event::ClearedDecision' # All reports should point to the same reportable. We will take care of that here: # https://trello.com/c/xrjOZGa7/45-ensure-all-reports-of-a-decision-point-to-the-same-reportable @@ -122,6 +124,9 @@ def notifiable_link_path @notification.event_type.constantize.notification_link_path(@notification) when 'Event::ReportForUser' Rails.application.routes.url_helpers.user_path(@notification.event_payload['user_login']) + when 'Event::ReportForRequest' + bs_request = @notification.notifiable.reportable + Rails.application.routes.url_helpers.request_show_path(bs_request.number, notification_id: @notification.id) when 'Event::ClearedDecision', 'Event::FavoredDecision' reportable = @notification.notifiable.reports.first.reportable link_for_reportables(reportable)