mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Clean up verifications controller
This commit is contained in:
parent
377a95cc76
commit
55e66724cf
2 changed files with 32 additions and 10 deletions
|
@ -7,6 +7,7 @@ module Api
|
||||||
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_updateable, only: %i[index update]
|
||||||
|
before_action :verify_decision, only: %i[update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render json: {
|
render json: {
|
||||||
|
@ -18,16 +19,30 @@ module Api
|
||||||
|
|
||||||
def update
|
def update
|
||||||
verification = RegistrantVerification.new(domain_id: @domain.id,
|
verification = RegistrantVerification.new(domain_id: @domain.id,
|
||||||
verification_token: confirmation_params[:token])
|
verification_token: verify_params[:token])
|
||||||
|
|
||||||
head(update_action(verification) ? :ok : :bad_request)
|
head(:bad_request) and return unless update_action(verification)
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
domain_name: @domain.name,
|
||||||
|
current_registrant: serialized_registrant(current_registrant),
|
||||||
|
status: params[:decision]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def current_registrant
|
||||||
|
changes_registrant? ? @domain.registrant : @domain.pending_registrant
|
||||||
|
end
|
||||||
|
|
||||||
|
def changes_registrant?
|
||||||
|
params[:decision] == 'confirmed'
|
||||||
|
end
|
||||||
|
|
||||||
def update_action(verification)
|
def update_action(verification)
|
||||||
initiator = "email link, #{t(:user_not_authenticated)}"
|
initiator = "email link, #{I18n.t(:user_not_authenticated)}"
|
||||||
if params[:confirm].present?
|
if changes_registrant?
|
||||||
verification.domain_registrant_change_confirm!(initiator)
|
verification.domain_registrant_change_confirm!(initiator)
|
||||||
else
|
else
|
||||||
verification.domain_registrant_change_reject!(initiator)
|
verification.domain_registrant_change_reject!(initiator)
|
||||||
|
@ -42,25 +57,31 @@ module Api
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirmation_params
|
def verify_params
|
||||||
params do |p|
|
params do |p|
|
||||||
p.require(:name)
|
p.require(:name)
|
||||||
p.require(:token)
|
p.require(:token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_decision
|
||||||
|
return if %w[confirmed rejected].include?(params[:decision])
|
||||||
|
|
||||||
|
head :bad_request
|
||||||
|
end
|
||||||
|
|
||||||
def set_domain
|
def set_domain
|
||||||
@domain = Domain.find_by(name: confirmation_params[:name])
|
@domain = Domain.find_by(name: verify_params[:name])
|
||||||
|
@domain ||= Domain.find_by(name_puny: verify_params[:name])
|
||||||
return if @domain
|
return if @domain
|
||||||
|
|
||||||
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_updateable
|
||||||
return if @domain.registrant_update_confirmable?(confirmation_params[:token])
|
return if @domain.registrant_update_confirmable?(verify_params[:token])
|
||||||
|
|
||||||
render json: { error: 'Application expired or not found' },
|
render json: { error: 'Application expired or not found' }, status: :unauthorized
|
||||||
status: :unauthorized
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,8 @@ Rails.application.routes.draw 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/:token', to: 'confirms#index', constraints: { name: /[^\/]+/ }
|
||||||
post 'confirms/:name/:token', to: 'confirms#update', constraints: { name: /[^\/]+/ }
|
post 'confirms/:name/: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]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue