Skip to content

Commit

Permalink
Create web notifications for create_report event
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas authored and danidoni committed Sep 22, 2023
1 parent 5f7fcf8 commit 1fa67f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/api/app/services/notification_service/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class Notifier
'Event::CommentForPackage',
'Event::CommentForRequest',
'Event::RelationshipCreate',
'Event::RelationshipDelete'].freeze
'Event::RelationshipDelete',
'Event::CreateReport'].freeze
CHANNELS = [:web, :rss].freeze
ALLOWED_NOTIFIABLE_TYPES = {
'BsRequest' => ::BsRequest,
'Comment' => ::Comment,
'Project' => ::Project,
'Package' => ::Package
'Package' => ::Package,
'Report' => ::Report
}.freeze
ALLOWED_CHANNELS = {
web: NotificationService::WebChannel,
Expand Down Expand Up @@ -46,6 +48,7 @@ def create_notification_per_subscription(subscription, channel)
def create_notification?(subscriber, channel)
return false if subscriber.nil? || subscriber.away? || (channel == :rss && !subscriber.try(:rss_token))
return false unless notifiable_exists?
return false unless create_report_notification?(event: @event, subscriber: subscriber)

true
end
Expand All @@ -59,5 +62,14 @@ def notifiable_exists?
notifiable_id = @event.parameters_for_notification[:notifiable_id]
notifiable_type.exists?(notifiable_id)
end

def create_report_notification?(event:, subscriber:)
if event.is_a?(Event::CreateReport)
return false unless Flipper.enabled?(:content_moderation, subscriber)
return false unless subscriber.is_moderator?
end

true
end
end
end
3 changes: 2 additions & 1 deletion src/api/app/services/notification_service/web_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class WebChannel
'BsRequest' => OutdatedNotificationsFinder::BsRequest,
'Comment' => OutdatedNotificationsFinder::Comment,
'Project' => OutdatedNotificationsFinder::Project,
'Package' => OutdatedNotificationsFinder::Package
'Package' => OutdatedNotificationsFinder::Package,
'Report' => OutdatedNotificationsFinder::Report
}.freeze

def initialize(subscription, event)
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/services/notified_projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def call
@notifiable.project
when 'Project'
@notifiable
when 'Report'
[]
end
end
# rubocop:enable Metrics/CyclomaticComplexity
Expand Down

0 comments on commit 1fa67f6

Please sign in to comment.