mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 15:34:41 +02:00
Merge pull request #1742 from internetee/registrant-confirmation-api
Registrant API: domain registrant confirmations
This commit is contained in:
commit
854878ebdf
8 changed files with 436 additions and 11 deletions
119
app/controllers/api/v1/registrant/confirms_controller.rb
Normal file
119
app/controllers/api/v1/registrant/confirms_controller.rb
Normal file
|
@ -0,0 +1,119 @@
|
|||
require 'serializers/registrant_api/domain'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
module Registrant
|
||||
class ConfirmsController < ::Api::V1::Registrant::BaseController
|
||||
skip_before_action :authenticate, :set_paper_trail_whodunnit
|
||||
before_action :set_domain, only: %i[index update]
|
||||
before_action :verify_action, only: %i[index update]
|
||||
before_action :verify_decision, only: %i[update]
|
||||
|
||||
def index
|
||||
res = {
|
||||
domain_name: @domain.name,
|
||||
current_registrant: serialized_registrant(@domain.registrant),
|
||||
}
|
||||
|
||||
unless delete_action?
|
||||
res[:new_registrant] = serialized_registrant(@domain.pending_registrant)
|
||||
end
|
||||
|
||||
render json: res, status: :ok
|
||||
end
|
||||
|
||||
def update
|
||||
verification = RegistrantVerification.new(domain_id: @domain.id,
|
||||
verification_token: verify_params[:token])
|
||||
|
||||
unless delete_action? ? delete_action(verification) : change_action(verification)
|
||||
head :bad_request
|
||||
return
|
||||
end
|
||||
|
||||
render json: { domain_name: @domain.name,
|
||||
current_registrant: serialized_registrant(current_registrant),
|
||||
status: params[:decision] }, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initiator
|
||||
"email link, #{I18n.t(:user_not_authenticated)}"
|
||||
end
|
||||
|
||||
def current_registrant
|
||||
confirmed? && !delete_action? ? @domain.pending_registrant : @domain.registrant
|
||||
end
|
||||
|
||||
def confirmed?
|
||||
verify_params[:decision] == 'confirmed'
|
||||
end
|
||||
|
||||
def change_action(verification)
|
||||
if confirmed?
|
||||
verification.domain_registrant_change_confirm!(initiator)
|
||||
else
|
||||
verification.domain_registrant_change_reject!(initiator)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_action(verification)
|
||||
if confirmed?
|
||||
verification.domain_registrant_delete_confirm!(initiator)
|
||||
else
|
||||
verification.domain_registrant_delete_reject!(initiator)
|
||||
end
|
||||
end
|
||||
|
||||
def serialized_registrant(registrant)
|
||||
{
|
||||
name: registrant.try(:name),
|
||||
ident: registrant.try(:ident),
|
||||
country: registrant.try(:ident_country_code),
|
||||
}
|
||||
end
|
||||
|
||||
def verify_params
|
||||
params do |p|
|
||||
p.require(:name)
|
||||
p.require(:token)
|
||||
p.permit(:decision)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_action?
|
||||
return true if params[:template] == 'delete'
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def verify_decision
|
||||
return if %w[confirmed rejected].include?(params[:decision])
|
||||
|
||||
head :not_found
|
||||
end
|
||||
|
||||
def set_domain
|
||||
@domain = Domain.find_by(name: verify_params[:name])
|
||||
@domain ||= Domain.find_by(name_puny: verify_params[:name])
|
||||
return if @domain
|
||||
|
||||
render json: { error: 'Domain not found' }, status: :not_found
|
||||
end
|
||||
|
||||
def verify_action
|
||||
action = if params[:template] == 'change'
|
||||
@domain.registrant_update_confirmable?(verify_params[:token])
|
||||
elsif params[:template] == 'delete'
|
||||
@domain.registrant_delete_confirmable?(verify_params[:token])
|
||||
end
|
||||
|
||||
return if action
|
||||
|
||||
render json: { error: 'Application expired or not found' }, status: :unauthorized
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,15 @@
|
|||
class ApplicationMailer < ActionMailer::Base
|
||||
append_view_path Rails.root.join('app', 'views', 'mailers')
|
||||
layout 'mailer'
|
||||
end
|
||||
|
||||
def registrant_confirm_url(domain:, method:)
|
||||
token = domain.registrant_verification_token
|
||||
base_url = ENV['registrant_portal_verifications_base_url']
|
||||
|
||||
url = registrant_domain_delete_confirm_url(domain, token: token) if method == 'delete'
|
||||
url ||= registrant_domain_update_confirm_url(domain, token: token)
|
||||
return url if base_url.blank?
|
||||
|
||||
"#{base_url}/confirmation/#{domain.name_puny}/#{method}/#{token}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class DomainDeleteMailer < ApplicationMailer
|
|||
def confirmation_request(domain:, registrar:, registrant:)
|
||||
@domain = DomainPresenter.new(domain: domain, view: view_context)
|
||||
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
|
||||
@confirmation_url = confirmation_url(domain)
|
||||
@confirmation_url = registrant_confirm_url(domain: domain, method: 'delete')
|
||||
|
||||
subject = default_i18n_subject(domain_name: domain.name)
|
||||
mail(to: registrant.email, subject: subject)
|
||||
|
@ -48,10 +48,6 @@ class DomainDeleteMailer < ApplicationMailer
|
|||
|
||||
private
|
||||
|
||||
def confirmation_url(domain)
|
||||
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
|
||||
end
|
||||
|
||||
def forced_email_from
|
||||
ENV['action_mailer_force_delete_from'] || self.class.default[:from]
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class RegistrantChangeMailer < ApplicationMailer
|
|||
@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)
|
||||
@confirmation_url = confirmation_url(domain)
|
||||
@confirmation_url = registrant_confirm_url(domain: domain, method: 'change')
|
||||
|
||||
subject = default_i18n_subject(domain_name: domain.name)
|
||||
mail(to: current_registrant.email, subject: subject)
|
||||
|
@ -49,10 +49,6 @@ class RegistrantChangeMailer < ApplicationMailer
|
|||
|
||||
private
|
||||
|
||||
def confirmation_url(domain)
|
||||
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
|
||||
end
|
||||
|
||||
def address_processing
|
||||
Contact.address_processing?
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ class RegistrantChange
|
|||
end
|
||||
|
||||
def confirm
|
||||
Dispute.close_by_domain(@domain.name) if @domain.disputed?
|
||||
notify_registrant
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue