Merge pull request #6557 from artoscinote/ma_SCI_9608

Implement general notification mailer [SCI-9608]
This commit is contained in:
Martin Artnik 2023-11-21 14:49:06 +01:00 committed by GitHub
commit 720eceb59f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 27 deletions

View file

@ -1,10 +1,5 @@
# frozen_string_literal: true
# To deliver this notification:
#
# ActivityNotification.with(post: @post).deliver_later(current_user)
# ActivityNotification.with(post: @post).deliver(current_user)
class ActivityNotification < BaseNotification
include SearchHelper
include GlobalActivitiesHelper
@ -13,15 +8,6 @@ class ActivityNotification < BaseNotification
include ApplicationHelper
include ActiveRecord::Sanitization::ClassMethods
include Rails.application.routes.url_helpers
# Add your delivery methods
#
# deliver_by :email, mailer: "UserMailer"
# deliver_by :slack
# deliver_by :custom, class: "MyDeliveryMethod"
# Add required params
#
# param :post
def message
params[:message] if params[:legacy]
@ -38,9 +24,6 @@ class ActivityNotification < BaseNotification
def subject
activity.subject unless params[:legacy]
end
# def url
# post_path(params[:post])
# end
private

View file

@ -2,10 +2,11 @@
class BaseNotification < Noticed::Base
deliver_by :database, if: :database_notification?
deliver_by :email, mailer: 'NotificationMailer', method: :general_notification, if: :email_notification?
def self.send_notifications(params, later: false)
recipients_class =
"Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[subtype][:recipients_module]}".constantize
"Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[params[:type]][:recipients_module]}".constantize
recipients_class.new(params).recipients.each do |recipient|
if later
with(params).deliver_later(recipient)
@ -15,7 +16,7 @@ class BaseNotification < Noticed::Base
end
end
def self.subtype
def subtype
params[:type]
end
@ -27,9 +28,13 @@ class BaseNotification < Noticed::Base
recipient.notifications_settings.dig(notification_subgroup.to_s, 'in_app')
end
def email_notification?
recipient.notifications_settings.dig(notification_subgroup.to_s, 'email')
end
def notification_subgroup
NotificationExtends::NOTIFICATIONS_GROUPS.values.reduce({}, :merge).find do |_sg, n|
n.include?(self.class.subtype.to_sym)
n.include?(subtype.to_sym)
end[0]
end
end

View file

@ -3,16 +3,18 @@
class LowStockNotification < BaseNotification
def message
I18n.t(
'notifications.notification.item_low_stock_reminder_html',
'notifications.content.item_low_stock_reminder.message_html',
repository_row_name: subject.name
)
end
def self.subtype
def subtype
:item_low_stock_reminder
end
def title; end
def title
I18n.t('notifications.content.item_low_stock_reminder.title_html')
end
def subject
RepositoryRow.find(params[:repository_row_id])

View file

@ -3409,10 +3409,16 @@ en:
repository_date_reminder: "Date reminder"
other_smart_annotation: "You are mentioned (tagged) in any place of Scinote"
other_team_invitation: "You are invited or removed from the team"
notification:
my_module_due_date_reminder_html: "Due date for %{my_module_name} is coming up"
item_low_stock_reminder_html: "Item %{repository_row_name} is running low"
item_date_reminder_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}"
content:
my_module_due_date_reminder:
title_html: "Task due date reminder"
message_html: "Due date for %{my_module_name} is coming up"
item_low_stock_reminder:
title_html: "Item stock reminder"
message_html: "Item %{repository_row_name} is running low"
item_date_reminder:
title_html: "Item date reminder"
message_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}"
deliver:
download_link: "Download link:"
download_text: "Click the link to download the file."