mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
added mail contronller and job for notificate registrars and admins about accreditation expire date
This commit is contained in:
parent
c5719a35f1
commit
e74cf2bc7f
7 changed files with 78 additions and 4 deletions
|
@ -5,6 +5,7 @@ module Repp
|
||||||
before_action :authenticate_shared_key
|
before_action :authenticate_shared_key
|
||||||
|
|
||||||
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
||||||
|
EXPIRE_DEADLINE = 15.minutes.freeze
|
||||||
|
|
||||||
api :POST, 'repp/v1/registrar/accreditation/push_results'
|
api :POST, 'repp/v1/registrar/accreditation/push_results'
|
||||||
desc 'added datetime results'
|
desc 'added datetime results'
|
||||||
|
@ -26,12 +27,31 @@ module Repp
|
||||||
raise ActiveRecord::RecordNotFound if user.nil?
|
raise ActiveRecord::RecordNotFound if user.nil?
|
||||||
|
|
||||||
user.accreditation_date = DateTime.current
|
user.accreditation_date = DateTime.current
|
||||||
|
user.accreditation_expire_date = user.accreditation_date + EXPIRE_DEADLINE
|
||||||
|
|
||||||
return unless user.save
|
if user.save
|
||||||
|
notify_registrar(user)
|
||||||
|
notify_admins
|
||||||
|
render_success(data: { user: user,
|
||||||
|
result: result,
|
||||||
|
message: 'Accreditation info successfully added' })
|
||||||
|
else
|
||||||
|
render_failed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
render_success(data: { user: user,
|
def notify_registrar(user)
|
||||||
result: result,
|
AccreditationCenterMailer.test_was_successfully_passed_registrar(user.registrar.email).deliver_now
|
||||||
message: 'Accreditation info successfully added' })
|
end
|
||||||
|
|
||||||
|
def notify_admins
|
||||||
|
admin_users_emails = User.all.reject { |u| u.roles.nil? }.select { |u| u.roles.include? "admin" }.pluck(:email)
|
||||||
|
|
||||||
|
return if admin_users_emails.empty?
|
||||||
|
|
||||||
|
admin_users_emails.each do |email|
|
||||||
|
AccreditationCenterMailer.test_was_successfully_passed_admin(email).deliver_now
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate_shared_key
|
def authenticate_shared_key
|
||||||
|
|
29
app/jobs/notify_accreditation_admins_and_registrars_job.rb
Normal file
29
app/jobs/notify_accreditation_admins_and_registrars_job.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
|
||||||
|
MONTH_BEFORE = 5.minute.freeze
|
||||||
|
|
||||||
|
def perform
|
||||||
|
prepare_data_month_before.each do |user|
|
||||||
|
next if user.registrar.email.nil?
|
||||||
|
|
||||||
|
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now
|
||||||
|
end
|
||||||
|
|
||||||
|
prepare_data_expired_data.each do |user|
|
||||||
|
next if user.registrar.email.nil?
|
||||||
|
|
||||||
|
AccreditationCenterMailer.test_results_are_expired(user.registrar.email).deliver_now
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def prepare_data_month_before
|
||||||
|
ApiUser.where("accreditation_expire_date > ? AND accreditation_expire_date < ?",
|
||||||
|
Time.now.beginning_of_day + MONTH_BEFORE,
|
||||||
|
Time.now.end_of_day + MONTH_BEFORE).includes(:registrar)
|
||||||
|
end
|
||||||
|
|
||||||
|
def prepare_data_expired_data
|
||||||
|
ApiUser.where("accreditation_expire_date < ?", Time.now.beginning_of_day).includes(:registrar)
|
||||||
|
end
|
||||||
|
end
|
21
app/mailers/accreditation_center_mailer.rb
Normal file
21
app/mailers/accreditation_center_mailer.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
class AccreditationCenterMailer < ApplicationMailer
|
||||||
|
def test_was_successfully_passed_admin(email)
|
||||||
|
subject = 'Test passed admin'
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_was_successfully_passed_registrar(email)
|
||||||
|
subject = 'Test passed registrar'
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_results_will_expired_in_one_month(email)
|
||||||
|
subject = 'Test will expired in one month'
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_results_are_expired(email)
|
||||||
|
subject = 'Test are expired'
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>Test result are expired</h1>
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>Test result will expired in one month</h1>
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>Test was successfully passed (ADMIN)</h1>
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>Test was successfully passed (REGISTRAR)</h1>
|
Loading…
Add table
Add a link
Reference in a new issue