mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-14 00:54:32 +08:00
Merge pull request #8448 from andrej-scinote/aj_SCI_11826
Add experiment due date notifications [SCI-11826]
This commit is contained in:
commit
fe69fafcd8
9 changed files with 99 additions and 1 deletions
26
app/jobs/experiment_due_date_reminder_job.rb
Normal file
26
app/jobs/experiment_due_date_reminder_job.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ExperimentDueDateReminderJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform
|
||||||
|
NewRelic::Agent.ignore_transaction
|
||||||
|
|
||||||
|
experiments_due.find_each do |experiment|
|
||||||
|
ExperimentDueDateNotification
|
||||||
|
.send_notifications({ experiment_id: experiment.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def experiments_due
|
||||||
|
Experiment.joins(:project)
|
||||||
|
.active
|
||||||
|
.where(
|
||||||
|
due_date_notification_sent: false,
|
||||||
|
projects: { archived: false }
|
||||||
|
)
|
||||||
|
.where('experiments.due_date > ? AND experiments.due_date <= ?', Date.current, Date.current + 1.day)
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,7 @@ class Experiment < ApplicationRecord
|
||||||
include TimeTrackable
|
include TimeTrackable
|
||||||
|
|
||||||
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && project_id_changed? }
|
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && project_id_changed? }
|
||||||
|
before_save :reset_due_date_notification_sent, if: -> { due_date_changed? }
|
||||||
|
|
||||||
belongs_to :project, inverse_of: :experiments, touch: true
|
belongs_to :project, inverse_of: :experiments, touch: true
|
||||||
delegate :team, to: :project
|
delegate :team, to: :project
|
||||||
|
@ -560,11 +561,15 @@ class Experiment < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def one_day_prior?(date = Date.current)
|
def one_day_prior?(date = Date.current)
|
||||||
due_date.present? && date < due_date && date > (due_date - 1.day)
|
due_date.present? && date < due_date && date >= (due_date - 1.day)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def reset_due_date_notification_sent
|
||||||
|
self.due_date_notification_sent = false
|
||||||
|
end
|
||||||
|
|
||||||
def log_activity(type_of, current_user, my_module)
|
def log_activity(type_of, current_user, my_module)
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: type_of,
|
.call(activity_type: type_of,
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Project < ApplicationRecord
|
||||||
validate :selected_user_role_validation, if: :bulk_assignment?
|
validate :selected_user_role_validation, if: :bulk_assignment?
|
||||||
|
|
||||||
before_validation :remove_project_folder, on: :update, if: :archived_changed?
|
before_validation :remove_project_folder, on: :update, if: :archived_changed?
|
||||||
|
before_save :reset_due_date_notification_sent, if: -> { due_date_changed? }
|
||||||
|
|
||||||
belongs_to :created_by,
|
belongs_to :created_by,
|
||||||
foreign_key: 'created_by_id',
|
foreign_key: 'created_by_id',
|
||||||
|
@ -395,4 +396,8 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
col_name
|
col_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_due_date_notification_sent
|
||||||
|
self.due_date_notification_sent = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
24
app/notifications/experiment_due_date_notification.rb
Normal file
24
app/notifications/experiment_due_date_notification.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ExperimentDueDateNotification < BaseNotification
|
||||||
|
def self.subtype
|
||||||
|
:experiments_due_date_reminder
|
||||||
|
end
|
||||||
|
|
||||||
|
def title
|
||||||
|
I18n.t(
|
||||||
|
'notifications.content.experiment_due_date_reminder.message_html',
|
||||||
|
experiment_name: subject.name
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def subject
|
||||||
|
Experiment.find(params[:experiment_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
after_deliver do
|
||||||
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
|
Experiment.find(params[:experiment_id]).update_column(:due_date_notification_sent, true)
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
|
end
|
||||||
|
end
|
19
app/notifications/recipients/due_date_recipients.rb
Normal file
19
app/notifications/recipients/due_date_recipients.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Recipients
|
||||||
|
class DueDateRecipients
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def recipients
|
||||||
|
if @params[:experiment_id].present?
|
||||||
|
experiment = Experiment.find_by(id: @params[:experiment_id])
|
||||||
|
User.where(id: experiment.user_assignments
|
||||||
|
.joins(:user_role)
|
||||||
|
.where('? = ANY(user_roles.permissions)',
|
||||||
|
ExperimentPermissions::MANAGE).select(:user_id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,6 +13,9 @@ class NotificationExtends
|
||||||
my_module_due_date_reminder: {
|
my_module_due_date_reminder: {
|
||||||
recipients_module: :MyModuleDesignatedRecipients
|
recipients_module: :MyModuleDesignatedRecipients
|
||||||
},
|
},
|
||||||
|
experiments_due_date_reminder: {
|
||||||
|
recipients_module: :DueDateRecipients
|
||||||
|
},
|
||||||
add_comment_to_module_activity: {
|
add_comment_to_module_activity: {
|
||||||
code: 35,
|
code: 35,
|
||||||
recipients_module: :MyModuleDesignatedRecipients
|
recipients_module: :MyModuleDesignatedRecipients
|
||||||
|
@ -140,6 +143,9 @@ class NotificationExtends
|
||||||
change_user_role_on_experiment_activity
|
change_user_role_on_experiment_activity
|
||||||
change_user_role_on_my_module_activity
|
change_user_role_on_my_module_activity
|
||||||
project_access_changed_all_team_members_activity
|
project_access_changed_all_team_members_activity
|
||||||
|
],
|
||||||
|
experiment_due_date: %I[
|
||||||
|
experiments_due_date_reminder
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
repository: {
|
repository: {
|
||||||
|
|
|
@ -30,6 +30,7 @@ if ENV['WORKER'].present?
|
||||||
|
|
||||||
reminder_job_interval = ENV['REMINDER_JOB_INTERVAL'] || '1h'
|
reminder_job_interval = ENV['REMINDER_JOB_INTERVAL'] || '1h'
|
||||||
schedule_task(scheduler, reminder_job_interval) do
|
schedule_task(scheduler, reminder_job_interval) do
|
||||||
|
ExperimentDueDateReminderJob.perform_now
|
||||||
MyModules::DueDateReminderJob.perform_now
|
MyModules::DueDateReminderJob.perform_now
|
||||||
RepositoryItemDateReminderJob.perform_now
|
RepositoryItemDateReminderJob.perform_now
|
||||||
end
|
end
|
||||||
|
|
|
@ -4139,6 +4139,7 @@ en:
|
||||||
repository_date_reminder: "Date reminder"
|
repository_date_reminder: "Date reminder"
|
||||||
other_smart_annotation: "You were tagged"
|
other_smart_annotation: "You were tagged"
|
||||||
other_team_invitation: "You were invited or removed from the team"
|
other_team_invitation: "You were invited or removed from the team"
|
||||||
|
experiment_due_date: "Due date reminder if you have Owner or User access role on a Experiment"
|
||||||
content:
|
content:
|
||||||
my_module_due_date_reminder:
|
my_module_due_date_reminder:
|
||||||
title_html: "Task due date reminder"
|
title_html: "Task due date reminder"
|
||||||
|
@ -4149,6 +4150,9 @@ en:
|
||||||
item_date_reminder:
|
item_date_reminder:
|
||||||
title_html: "Item date reminder"
|
title_html: "Item date reminder"
|
||||||
message_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}."
|
message_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}."
|
||||||
|
experiment_due_date_reminder:
|
||||||
|
title_html: "Experiment due date reminder"
|
||||||
|
message_html: "Due date for the experiment %{experiment_name} is coming up."
|
||||||
deliver:
|
deliver:
|
||||||
download_link: "Download link:"
|
download_link: "Download link:"
|
||||||
download_text: "Click the link to download the file."
|
download_text: "Click the link to download the file."
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddDueDateReminderNotificationColumns < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :projects, :due_date_notification_sent, :boolean, default: false, null: false
|
||||||
|
add_column :experiments, :due_date_notification_sent, :boolean, default: false, null: false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue