Skip to content

Commit

Permalink
Merge pull request #246 from internetee/registry-186
Browse files Browse the repository at this point in the history
Registry 186
  • Loading branch information
vohmar authored Nov 15, 2016
2 parents 49796c3 + df1aad5 commit 173407e
Show file tree
Hide file tree
Showing 126 changed files with 2,514 additions and 899 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/zonefiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Admin::ZonefilesController < ApplicationController
# TODO: Refactor this

def create
if ZonefileSetting.pluck(:origin).include?(params[:origin])
if ZonefileSetting.origins.include?(params[:origin])

@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('#{params[:origin]}')"
Expand Down
10 changes: 10 additions & 0 deletions app/jobs/domain_expiration_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DomainExpirationEmailJob < Que::Job
def run(domain_id:)
domain = Domain.find(domain_id)

return if domain.registered?

DomainMailer.expiration(domain: domain).deliver
destroy
end
end
4 changes: 3 additions & 1 deletion app/jobs/domain_update_confirm_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def run(domain_id, action, initiator = nil)
domain.clean_pendings!
raise_errors!(domain)
when RegistrantVerification::REJECTED
domain.send_mail :pending_update_rejected_notification_for_new_registrant
RegistrantChangeMailer.rejected(domain: domain, registrar: domain.registrar, registrant: domain.registrant)
.deliver

domain.poll_message!(:poll_pending_update_rejected_by_registrant)
domain.clean_pendings_lowlevel
end
Expand Down
Empty file removed app/mailers/.keep
Empty file.
18 changes: 18 additions & 0 deletions app/mailers/delete_domain_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class DeleteDomainMailer < ApplicationMailer
include Que::Mailer

def pending(domain:, old_registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@verification_url = verification_url(domain)

subject = default_i18n_subject(domain_name: domain.name)
mail(to: old_registrant.email, subject: subject)
end

private

def verification_url(domain)
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
end
end
69 changes: 10 additions & 59 deletions app/mailers/domain_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
class DomainMailer < ApplicationMailer
include Que::Mailer

def pending_update_request_for_old_registrant(params)
compose_from(params)
end

def pending_update_notification_for_new_registrant(params)
compose_from(params)
end


def registrant_updated_notification_for_new_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain
Expand Down Expand Up @@ -39,39 +30,6 @@ def registrant_updated_notification_for_old_registrant(domain_id, old_registrant
name: @domain.name)} [#{@domain.name}]")
end

def pending_update_rejected_notification_for_new_registrant(params)
compose_from(params)
end

def pending_update_expired_notification_for_new_registrant(params)
compose_from(params)
end

def pending_deleted(domain_id, old_registrant_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
@old_registrant = Registrant.find(old_registrant_id)
return unless @domain
return if delivery_off?(@domain, should_deliver)

if @domain.registrant_verification_token.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
return
end

if @domain.registrant_verification_asked_at.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}"
return
end

confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms"
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"

return if whitelist_blocked?(@old_registrant.email)
mail(to: format(@old_registrant.email),
subject: "#{I18n.t(:domain_pending_deleted_subject,
name: @domain.name)} [#{@domain.name}]")
end

def pending_delete_rejected_notification(domain_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain
Expand Down Expand Up @@ -117,27 +75,20 @@ def delete_confirmation(domain_id, should_deliver)
name: @domain.name)} [#{@domain.name}]")
end

def expiration_reminder(domain_id)
@domain = Domain.find_by(id: domain_id)
return if @domain.nil? || !@domain.statuses.include?(DomainStatus::EXPIRED) || whitelist_blocked?(@domain.registrant.email)
return if whitelist_blocked?(@domain.registrant.email)
def force_delete(domain:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: domain.registrant, view: view_context)

mail(to: format(@domain.registrant.email),
subject: "#{I18n.t(:expiration_remind_subject,
name: @domain.name)} [#{@domain.name}]")
mail(to: domain.primary_contact_emails)
end

def expiration(domain:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)

def force_delete(domain_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return if delivery_off?(@domain, should_deliver)
emails = ([@domain.registrant.email] + @domain.admin_contacts.map { |x| format(x.email) }).uniq
return if whitelist_blocked?(emails)

formatted_emails = emails.map { |x| format(x) }
mail(to: formatted_emails,
subject: "#{I18n.t(:force_delete_subject)}"
)
subject = default_i18n_subject(domain_name: domain.name)
mail(to: domain.primary_contact_emails, subject: subject)
end

private
Expand Down
48 changes: 48 additions & 0 deletions app/mailers/registrant_change_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class RegistrantChangeMailer < ApplicationMailer
include Que::Mailer

def confirm(domain:, registrar:, current_registrant:, new_registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context)
@confirm_url = confirm_url(domain)

subject = default_i18n_subject(domain_name: domain.name)
mail(to: current_registrant.email, subject: subject)
end

def notice(domain:, registrar:, current_registrant:, new_registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@current_registrant = RegistrantPresenter.new(registrant: current_registrant, view: view_context)
@new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context)
@confirm_url = confirm_url(domain)

subject = default_i18n_subject(domain_name: domain.name)
mail(to: new_registrant.email, subject: subject)
end

def rejected(domain:, registrar:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: registrant, view: view_context)

subject = default_i18n_subject(domain_name: domain.name)
mail(to: domain.new_registrant_email, subject: subject)
end

def expired(domain:, registrar:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: registrant, view: view_context)

subject = default_i18n_subject(domain_name: domain.name)
mail(to: domain.new_registrant_email, subject: subject)
end

private

def confirm_url(domain)
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
end
end
31 changes: 31 additions & 0 deletions app/models/concerns/domain/expirable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Concerns::Domain::Expirable
extend ActiveSupport::Concern

included do
alias_attribute :expire_time, :valid_to
end

class_methods do
def expired
where("#{attribute_alias(:expire_time)} <= ?", Time.zone.now)
end
end

def registered?
!expired?
end

def expired?
expire_time <= Time.zone.now
end

def expirable?
return false if expire_time > Time.zone.now

if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present?
return false
end

true
end
end
7 changes: 7 additions & 0 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def pdf(html)
kit.to_pdf
end

def names
pluck(:name)
end

def emails
pluck(:email)
end
end

def roid
Expand Down
Loading

0 comments on commit 173407e

Please sign in to comment.