mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 01:35:34 +08:00
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:
commit
91533a25ac
6 changed files with 43 additions and 7 deletions
|
@ -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
|
||||
|
|
9
app/models/non_existant_record.rb
Normal file
9
app/models/non_existant_record.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class NonExistantRecord
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue