Merge pull request #6561 from G-Chubinidze/gc_SCI_9562

Implement Task Due Date Reminder notification [SCI-9562]
This commit is contained in:
Martin Artnik 2023-11-03 13:23:11 +01:00 committed by GitHub
commit 08c817299d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class DueDateReminderJob < ApplicationJob
def perform
my_modules = MyModule.approaching_due_dates
my_modules.each do |task|
TaskDueDateNotification.send_notifications({ my_module_id: task.id })
end
end
end

View file

@ -20,6 +20,7 @@ class MyModule < ApplicationRecord
before_validation :archiving_and_restoring_extras, on: :update, if: :archived_changed?
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && experiment_id_changed? }
before_save :reset_due_date_notification_sent, if: -> { due_date_changed? }
around_save :exec_status_consequences, if: :my_module_status_id_changed?
before_create :create_blank_protocol
before_create :assign_default_status_flow
@ -139,6 +140,11 @@ class MyModule < ApplicationRecord
joins(experiment: :project).where(experiment: { projects: { team: teams } })
end
def self.approaching_due_dates
where(due_date_notification_sent: false)
.where('due_date > ? AND due_date <= ?', DateTime.current, DateTime.current + 1.day)
end
def parent
experiment
end
@ -529,6 +535,10 @@ class MyModule < ApplicationRecord
end
end
def reset_due_date_notification_sent
self.due_date_notification_sent = false
end
def archiving_and_restoring_extras
if archived?
# Removes connections with other modules

View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
class TaskDueDateNotification < BaseNotification
def message
I18n.t(
'notifications.notification.my_module_due_date_reminder_html',
my_module_name: subject.name
)
end
def self.subtype
:my_module_due_date_reminder
end
def title; end
def subject
MyModule.find(params[:my_module_id])
end
after_deliver do
MyModule.find(params[:my_module_id]).update(due_date_notification_sent: true)
end
end

View file

@ -21,3 +21,7 @@ if ENV['ENABLE_FLUICS_SYNC'] == 'true'
LabelPrinters::Fluics::SyncService.new.sync_templates! if LabelPrinter.fluics.any?
end
end
scheduler.every '1h' do
DueDateReminderJob.perform_now
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddTaskDueDateReminderNotification < ActiveRecord::Migration[7.0]
def change
add_column :my_modules, :due_date_notification_sent, :boolean, default: false
end
end