Merge pull request #6792 from ivanscinote/SCI-9825-ik

Make Date/Date&Time and Low Stock notifications work when deleting Repository/row record [SCI-9825]
This commit is contained in:
Martin Artnik 2023-12-11 13:40:26 +01:00 committed by GitHub
commit 91533a25ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 7 deletions

View file

@ -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

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class NonExistantRecord
attr_reader :name
def initialize(name)
@name = name
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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