mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Add delete action to confirmations API endpoint
This commit is contained in:
parent
4eaa8065ba
commit
64d35a864f
4 changed files with 44 additions and 18 deletions
|
@ -6,7 +6,7 @@ module Api
|
||||||
class ConfirmsController < ::Api::V1::Registrant::BaseController
|
class ConfirmsController < ::Api::V1::Registrant::BaseController
|
||||||
skip_before_action :authenticate, :set_paper_trail_whodunnit
|
skip_before_action :authenticate, :set_paper_trail_whodunnit
|
||||||
before_action :set_domain, only: %i[index update]
|
before_action :set_domain, only: %i[index update]
|
||||||
before_action :verify_updateable, only: %i[index update]
|
before_action :verify_action, only: %i[index update]
|
||||||
before_action :verify_decision, only: %i[update]
|
before_action :verify_decision, only: %i[update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -21,7 +21,10 @@ module Api
|
||||||
verification = RegistrantVerification.new(domain_id: @domain.id,
|
verification = RegistrantVerification.new(domain_id: @domain.id,
|
||||||
verification_token: verify_params[:token])
|
verification_token: verify_params[:token])
|
||||||
|
|
||||||
head(:bad_request) and return unless update_action(verification)
|
unless delete_action? ? delete_action(verification) : change_action(verification)
|
||||||
|
head :bad_request
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
domain_name: @domain.name,
|
domain_name: @domain.name,
|
||||||
|
@ -32,21 +35,28 @@ module Api
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def current_registrant
|
def initiator
|
||||||
changes_registrant? ? @domain.registrant : @domain.pending_registrant
|
"email link, #{I18n.t(:user_not_authenticated)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def changes_registrant?
|
def current_registrant
|
||||||
|
approved? ? @domain.registrant : @domain.pending_registrant
|
||||||
|
end
|
||||||
|
|
||||||
|
def approved?
|
||||||
params[:decision] == 'confirmed'
|
params[:decision] == 'confirmed'
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_action(verification)
|
def change_action(verification)
|
||||||
initiator = "email link, #{I18n.t(:user_not_authenticated)}"
|
return verification.domain_registrant_change_confirm!(initiator) if approved?
|
||||||
if changes_registrant?
|
|
||||||
verification.domain_registrant_change_confirm!(initiator)
|
verification.domain_registrant_change_reject!(initiator)
|
||||||
else
|
end
|
||||||
verification.domain_registrant_change_reject!(initiator)
|
|
||||||
end
|
def delete_action(verification)
|
||||||
|
return verification.domain_registrant_delete_confirm!(initiator) if approved?
|
||||||
|
|
||||||
|
verification.domain_registrant_delete_reject!(initiator)
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialized_registrant(registrant)
|
def serialized_registrant(registrant)
|
||||||
|
@ -59,11 +69,18 @@ module Api
|
||||||
|
|
||||||
def verify_params
|
def verify_params
|
||||||
params do |p|
|
params do |p|
|
||||||
|
p.require(:template)
|
||||||
p.require(:name)
|
p.require(:name)
|
||||||
p.require(:token)
|
p.require(:token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_action?
|
||||||
|
return true if params[:template] == 'delete'
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def verify_decision
|
def verify_decision
|
||||||
return if %w[confirmed rejected].include?(params[:decision])
|
return if %w[confirmed rejected].include?(params[:decision])
|
||||||
|
|
||||||
|
@ -78,8 +95,12 @@ module Api
|
||||||
render json: { error: 'Domain not found' }, status: :not_found
|
render json: { error: 'Domain not found' }, status: :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_updateable
|
def verify_action
|
||||||
return if @domain.registrant_update_confirmable?(verify_params[:token])
|
if params[:template] == 'change'
|
||||||
|
return true if @domain.registrant_update_confirmable?(verify_params[:token])
|
||||||
|
elsif params[:template] == 'delete'
|
||||||
|
return true if @domain.registrant_delete_confirmable?(verify_params[:token])
|
||||||
|
end
|
||||||
|
|
||||||
render json: { error: 'Application expired or not found' }, status: :unauthorized
|
render json: { error: 'Application expired or not found' }, status: :unauthorized
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,7 @@ class DomainDeleteMailer < ApplicationMailer
|
||||||
if base_url.blank?
|
if base_url.blank?
|
||||||
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
|
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
|
||||||
else
|
else
|
||||||
"#{base_url}/confirmation/#{domain.name_puny}/#{domain.registrant_verification_token}"
|
"#{base_url}/confirmation/#{domain.name_puny}/delete/#{domain.registrant_verification_token}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,12 @@ class RegistrantChangeMailer < ApplicationMailer
|
||||||
private
|
private
|
||||||
|
|
||||||
def confirmation_url(domain)
|
def confirmation_url(domain)
|
||||||
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
|
base_url = ENV['registrant_portal_verifications_base_url']
|
||||||
|
if base_url.blank?
|
||||||
|
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
|
||||||
|
else
|
||||||
|
"#{base_url}/confirmation/#{domain.name_puny}/change/#{domain.registrant_verification_token}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def address_processing
|
def address_processing
|
||||||
|
|
|
@ -56,8 +56,8 @@ Rails.application.routes.draw do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
namespace :registrant do
|
namespace :registrant do
|
||||||
post 'auth/eid', to: 'auth#eid'
|
post 'auth/eid', to: 'auth#eid'
|
||||||
get 'confirms/:name/:token', to: 'confirms#index', constraints: { name: /[^\/]+/ }
|
get 'confirms/:name/:template/:token', to: 'confirms#index', constraints: { name: /[^\/]+/ }
|
||||||
post 'confirms/:name/:token/:decision', to: 'confirms#update', constraints: { name: /[^\/]+/ }
|
post 'confirms/:name/:template/:token/:decision', to: 'confirms#update', constraints: { name: /[^\/]+/ }
|
||||||
|
|
||||||
resources :domains, only: %i[index show], param: :uuid do
|
resources :domains, only: %i[index show], param: :uuid do
|
||||||
resource :registry_lock, only: %i[create destroy]
|
resource :registry_lock, only: %i[create destroy]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue