mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
Move job to interactor
This commit is contained in:
parent
ccf91d306a
commit
f6a7a08b24
9 changed files with 107 additions and 43 deletions
23
app/interactions/domains/delete_confirm/base.rb
Normal file
23
app/interactions/domains/delete_confirm/base.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Domains
|
||||
module DeleteConfirm
|
||||
class Base < ActiveInteraction::Base
|
||||
object :domain,
|
||||
class: Domain,
|
||||
description: 'Domain to confirm release'
|
||||
string :action
|
||||
string :initiator,
|
||||
default: nil
|
||||
|
||||
validates :domain, :action, presence: true
|
||||
validates :action, inclusion: { in: [RegistrantVerification::CONFIRMED,
|
||||
RegistrantVerification::REJECTED] }
|
||||
|
||||
def raise_errors!(domain)
|
||||
return unless domain.errors.any?
|
||||
|
||||
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
||||
throw message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
app/interactions/domains/delete_confirm/process_action.rb
Normal file
17
app/interactions/domains/delete_confirm/process_action.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Domains
|
||||
module DeleteConfirm
|
||||
class ProcessAction < Base
|
||||
def execute
|
||||
::PaperTrail.request.whodunnit = "interaction - #{self.class.name} - #{action} by"\
|
||||
" #{initiator}"
|
||||
|
||||
case action
|
||||
when RegistrantVerification::CONFIRMED
|
||||
compose(ProcessDeleteConfirmed, inputs)
|
||||
when RegistrantVerification::REJECTED
|
||||
compose(ProcessDeleteRejected, inputs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
module Domains
|
||||
module DeleteConfirm
|
||||
class ProcessDeleteConfirmed < Base
|
||||
def execute
|
||||
domain.notify_registrar(:poll_pending_delete_confirmed_by_registrant)
|
||||
domain.apply_pending_delete!
|
||||
raise_errors!(domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
module Domains
|
||||
module DeleteConfirm
|
||||
class ProcessDeleteRejected < Base
|
||||
def execute
|
||||
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
domain.notify_registrar(:poll_pending_delete_rejected_by_registrant)
|
||||
|
||||
domain.cancel_pending_delete
|
||||
domain.save(validate: false)
|
||||
raise_errors!(domain)
|
||||
|
||||
send_domain_deleted_email
|
||||
end
|
||||
|
||||
def send_domain_deleted_email
|
||||
if domain.registrant_verification_token.blank?
|
||||
warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{domain.name}"
|
||||
elsif domain.registrant_verification_asked_at.blank?
|
||||
warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{domain.name}"
|
||||
else
|
||||
send_email
|
||||
end
|
||||
end
|
||||
|
||||
def warn(message)
|
||||
Rails.logger.warn(message)
|
||||
end
|
||||
|
||||
def send_email
|
||||
DomainDeleteMailer.rejected(domain).deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
2
app/jobs/application_job.rb
Normal file
2
app/jobs/application_job.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class ApplicationJob < ActiveJob::Base
|
||||
end
|
|
@ -1,39 +1,11 @@
|
|||
class DomainDeleteConfirmJob < Que::Job
|
||||
def run(domain_id, action, initiator = nil)
|
||||
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{action} by #{initiator}"
|
||||
# it's recommended to keep transaction against job table as short as possible.
|
||||
ActiveRecord::Base.transaction do
|
||||
domain = Epp::Domain.find(domain_id)
|
||||
class DomainDeleteConfirmJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
case action
|
||||
when RegistrantVerification::CONFIRMED
|
||||
domain.notify_registrar(:poll_pending_delete_confirmed_by_registrant)
|
||||
domain.apply_pending_delete!
|
||||
raise_errors!(domain)
|
||||
def perform(domain_id, action, initiator = nil)
|
||||
domain = Epp::Domain.find(domain_id)
|
||||
|
||||
when RegistrantVerification::REJECTED
|
||||
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
domain.notify_registrar(:poll_pending_delete_rejected_by_registrant)
|
||||
|
||||
domain.cancel_pending_delete
|
||||
domain.save(validate: false)
|
||||
raise_errors!(domain)
|
||||
|
||||
if domain.registrant_verification_token.blank?
|
||||
Rails.logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{domain.name}"
|
||||
elsif domain.registrant_verification_asked_at.blank?
|
||||
Rails.logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{domain.name}"
|
||||
else
|
||||
DomainDeleteMailer.rejected(domain).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
destroy # it's best to destroy the job in the same transaction
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def raise_errors!(domain)
|
||||
throw "domain #{domain.name} failed with errors #{domain.errors.full_messages}" if domain.errors.any?
|
||||
Domains::DeleteConfirm::ProcessAction.run(domain: domain,
|
||||
action: action,
|
||||
initiator: initiator)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,12 +30,12 @@ class RegistrantVerification < ApplicationRecord
|
|||
def domain_registrant_delete_confirm!(initiator)
|
||||
self.action_type = DOMAIN_DELETE
|
||||
self.action = CONFIRMED
|
||||
DomainDeleteConfirmJob.enqueue domain.id, CONFIRMED, initiator if save
|
||||
DomainDeleteConfirmJob.perform_later domain.id, CONFIRMED, initiator if save
|
||||
end
|
||||
|
||||
def domain_registrant_delete_reject!(initiator)
|
||||
self.action_type = DOMAIN_DELETE
|
||||
self.action = REJECTED
|
||||
DomainDeleteConfirmJob.enqueue domain.id, REJECTED, initiator if save
|
||||
DomainDeleteConfirmJob.perform_later domain.id, REJECTED, initiator if save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
new_registrant_email: @new_registrant.email,
|
||||
current_user_id: @user.id })
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
|
||||
|
||||
last_registrar_notification = @domain.registrar.notifications.last
|
||||
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
|
||||
|
@ -31,7 +31,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
new_registrant_email: @new_registrant.email,
|
||||
current_user_id: @user.id })
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
|
||||
last_registrar_notification = @domain.registrar.notifications.last
|
||||
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
|
||||
|
@ -51,7 +51,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
assert @domain.registrant_delete_confirmable?(@domain.registrant_verification_token)
|
||||
assert_equal @user.id, @domain.pending_json['current_user_id']
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
@domain.reload
|
||||
|
||||
assert @domain.statuses.include? DomainStatus::PENDING_DELETE
|
||||
|
@ -72,7 +72,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
assert @domain.registrant_delete_confirmable?(@domain.registrant_verification_token)
|
||||
assert_equal @user.id, @domain.pending_json['current_user_id']
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
|
||||
@domain.reload
|
||||
|
||||
assert_equal ['ok'], @domain.statuses
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'application_system_test_case'
|
||||
|
||||
class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
||||
include ActionMailer::TestHelper
|
||||
setup do
|
||||
@user = users(:registrant)
|
||||
sign_in @user
|
||||
|
@ -13,7 +14,9 @@ class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
|||
def test_enqueues_approve_job_after_verification
|
||||
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||
|
||||
click_on 'Confirm domain delete'
|
||||
perform_enqueued_jobs do
|
||||
click_on 'Confirm domain delete'
|
||||
end
|
||||
assert_text 'Domain registrant change has successfully received.'
|
||||
|
||||
@domain.reload
|
||||
|
@ -23,7 +26,9 @@ class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
|||
def test_enqueues_reject_job_after_verification
|
||||
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||
|
||||
click_on 'Reject domain delete'
|
||||
perform_enqueued_jobs do
|
||||
click_on 'Reject domain delete'
|
||||
end
|
||||
assert_text 'Domain registrant change has been rejected successfully.'
|
||||
|
||||
@domain.reload
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue