mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 22:24:23 +08:00
Add project due date notification [SCI-11825]
This commit is contained in:
parent
fe69fafcd8
commit
bf9f9d9dec
6 changed files with 68 additions and 7 deletions
22
app/jobs/project_due_date_reminder_job.rb
Normal file
22
app/jobs/project_due_date_reminder_job.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ProjectDueDateReminderJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
NewRelic::Agent.ignore_transaction
|
||||
|
||||
projects_due.find_each do |project|
|
||||
ProjectDueDateNotification
|
||||
.send_notifications({ project_id: project.id })
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def projects_due
|
||||
Project.active
|
||||
.where(due_date_notification_sent: false)
|
||||
.where('projects.due_date > ? AND projects.due_date <= ?', Date.current, Date.current + 1.day)
|
||||
end
|
||||
end
|
24
app/notifications/project_due_date_notification.rb
Normal file
24
app/notifications/project_due_date_notification.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ProjectDueDateNotification < BaseNotification
|
||||
def self.subtype
|
||||
:projects_due_date_reminder
|
||||
end
|
||||
|
||||
def title
|
||||
I18n.t(
|
||||
'notifications.content.project_due_date_reminder.message_html',
|
||||
project_name: subject.name
|
||||
)
|
||||
end
|
||||
|
||||
def subject
|
||||
Project.find(params[:project_id])
|
||||
end
|
||||
|
||||
after_deliver do
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
Project.find(params[:project_id]).update_column(:due_date_notification_sent, true)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
|
@ -7,13 +7,17 @@ module Recipients
|
|||
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
|
||||
record, permission = if @params[:experiment_id].present?
|
||||
[Experiment.find_by(id: @params[:experiment_id]), ExperimentPermissions::MANAGE]
|
||||
elsif @params[:project_id].present?
|
||||
[Project.find_by(id: @params[:project_id]), ProjectPermissions::MANAGE]
|
||||
end
|
||||
return User.none unless record
|
||||
|
||||
User.where(id: record.user_assignments
|
||||
.joins(:user_role)
|
||||
.where('? = ANY(user_roles.permissions)', permission)
|
||||
.select(:user_id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,9 @@ class NotificationExtends
|
|||
my_module_due_date_reminder: {
|
||||
recipients_module: :MyModuleDesignatedRecipients
|
||||
},
|
||||
projects_due_date_reminder: {
|
||||
recipients_module: :DueDateRecipients
|
||||
},
|
||||
experiments_due_date_reminder: {
|
||||
recipients_module: :DueDateRecipients
|
||||
},
|
||||
|
@ -144,6 +147,9 @@ class NotificationExtends
|
|||
change_user_role_on_my_module_activity
|
||||
project_access_changed_all_team_members_activity
|
||||
],
|
||||
project_due_date: %I[
|
||||
projects_due_date_reminder
|
||||
],
|
||||
experiment_due_date: %I[
|
||||
experiments_due_date_reminder
|
||||
]
|
||||
|
|
|
@ -30,6 +30,7 @@ if ENV['WORKER'].present?
|
|||
|
||||
reminder_job_interval = ENV['REMINDER_JOB_INTERVAL'] || '1h'
|
||||
schedule_task(scheduler, reminder_job_interval) do
|
||||
ProjectDueDateReminderJob.perform_now
|
||||
ExperimentDueDateReminderJob.perform_now
|
||||
MyModules::DueDateReminderJob.perform_now
|
||||
RepositoryItemDateReminderJob.perform_now
|
||||
|
|
|
@ -4140,6 +4140,7 @@ en:
|
|||
other_smart_annotation: "You were tagged"
|
||||
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"
|
||||
project_due_date: "Due date reminder if you have Owner access role on a Project"
|
||||
content:
|
||||
my_module_due_date_reminder:
|
||||
title_html: "Task due date reminder"
|
||||
|
@ -4150,6 +4151,9 @@ en:
|
|||
item_date_reminder:
|
||||
title_html: "Item date reminder"
|
||||
message_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}."
|
||||
project_due_date_reminder:
|
||||
title_html: "Project due date reminder"
|
||||
message_html: "Due date for the project %{project_name} is coming up."
|
||||
experiment_due_date_reminder:
|
||||
title_html: "Experiment due date reminder"
|
||||
message_html: "Due date for the experiment %{experiment_name} is coming up."
|
||||
|
|
Loading…
Add table
Reference in a new issue