diff --git a/app/jobs/repository_item_date_reminder_job.rb b/app/jobs/repository_item_date_reminder_job.rb index cb0a72875..eadd8cfdc 100644 --- a/app/jobs/repository_item_date_reminder_job.rb +++ b/app/jobs/repository_item_date_reminder_job.rb @@ -21,10 +21,19 @@ class RepositoryItemDateReminderJob < ApplicationJob "(repository_columns.metadata->>'reminder_value')::int) || ' seconds' AS Interval))", comparison_value ).find_each do |value| + repository_row = RepositoryRow.find(value.repository_cell.repository_row_id) + repository_column = RepositoryColumn.find(value.repository_cell.repository_column_id) + RepositoryItemDateNotification - .send_notifications({ "#{value.class.name.underscore}_id": value.id, - repository_row_id: value.repository_cell.repository_row_id, - repository_column_id: value.repository_cell.repository_column_id }) + .send_notifications({ + "#{value.class.name.underscore}_id": value.id, + repository_row_id: repository_row.id, + repository_row_name: repository_row.name, + repository_column_id: repository_column.id, + repository_column_name: repository_column.name, + reminder_unit: repository_column.metadata['reminder_unit'], + reminder_value: repository_column.metadata['reminder_value'] + }) end end end diff --git a/app/models/non_existant_record.rb b/app/models/non_existant_record.rb new file mode 100644 index 000000000..c5e13f1d9 --- /dev/null +++ b/app/models/non_existant_record.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class NonExistantRecord + attr_reader :name + + def initialize(name) + @name = name + end +end diff --git a/app/models/repository_stock_value.rb b/app/models/repository_stock_value.rb index 3d634d52a..4c043d1a2 100644 --- a/app/models/repository_stock_value.rb +++ b/app/models/repository_stock_value.rb @@ -203,6 +203,14 @@ class RepositoryStockValue < ApplicationRecord end def send_low_stock_notification - LowStockNotification.send_notifications({ repository_row_id: repository_cell.repository_row_id }) + repository_row = RepositoryRow.find(repository_cell.repository_row_id) + repository = Repository.find(repository_row.repository_id) + + LowStockNotification.send_notifications({ + repository_row_id: repository_cell.repository_row_id, + repository_row_name: repository_row.name, + repository_id: repository_row.repository_id, + repository_name: repository.name + }) end end diff --git a/app/notifications/low_stock_notification.rb b/app/notifications/low_stock_notification.rb index 093de6e7c..fa0275e7f 100644 --- a/app/notifications/low_stock_notification.rb +++ b/app/notifications/low_stock_notification.rb @@ -23,9 +23,13 @@ class LowStockNotification < BaseNotification def subject RepositoryRow.find(params[:repository_row_id]) + rescue ActiveRecord::RecordNotFound + NonExistantRecord.new(params[:repository_row_name]) end def repository - Repository.find(subject.repository_id) + Repository.find(params[:repository_id]) + rescue ActiveRecord::RecordNotFound + NonExistantRecord.new(params[:repository_name]) end end diff --git a/app/notifications/repository_item_date_notification.rb b/app/notifications/repository_item_date_notification.rb index 2e94d0596..9857518ce 100644 --- a/app/notifications/repository_item_date_notification.rb +++ b/app/notifications/repository_item_date_notification.rb @@ -2,11 +2,11 @@ class RepositoryItemDateNotification < BaseNotification def message - unit = human_readable_unit(column.metadata['reminder_unit'], column.metadata['reminder_value']) + unit = human_readable_unit(params[:reminder_unit], params[:reminder_value]) I18n.t( 'notifications.content.item_date_reminder.message_html', repository_row_name: subject.name, - value: column.metadata['reminder_value'], + value: params[:reminder_value], units: unit ) end @@ -27,10 +27,14 @@ class RepositoryItemDateNotification < BaseNotification def subject RepositoryRow.find(params[:repository_row_id]) + rescue ActiveRecord::RecordNotFound + NonExistantRecord.new(params[:repository_row_name]) end def column RepositoryColumn.find(params[:repository_column_id]) + rescue ActiveRecord::RecordNotFound + NonExistantRecord.new(params[:repository_column_name]) end after_deliver do diff --git a/app/serializers/notification_serializer.rb b/app/serializers/notification_serializer.rb index ce671fbd8..9fd418140 100644 --- a/app/serializers/notification_serializer.rb +++ b/app/serializers/notification_serializer.rb @@ -33,6 +33,8 @@ class NotificationSerializer < ActiveModel::Serializer private def generate_breadcrumbs(subject, breadcrumbs) + return [] if subject.is_a?(NonExistantRecord) + case subject when Project parent = subject.team