REPP: Create domain statuses endpoints

This commit is contained in:
Karl Erik Õunapuu 2021-01-27 12:33:46 +02:00
parent 988af6c91c
commit 57df268d91
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,74 @@
module Repp
module V1
module Domains
class StatusesController < BaseController
before_action :set_domain, only: %i[update destroy]
before_action :verify_status
before_action :verify_status_removal, only: [:destroy]
before_action :verify_status_create, only: [:update]
api :DELETE, '/repp/v1/domains/:domain_name/statuses/:status'
desc 'Remove status from specific domain'
param :domain_name, String, required: true, desc: 'Domain name'
param :status, String, required: true, desc: 'Status to be removed'
def destroy
@domain.statuses = @domain.statuses.delete(params[:id])
if @domain.save
render_success
else
handle_errors(@domain)
end
end
api :PUT, '/repp/v1/domains/:domain_name/statuses/:status'
desc 'Add status to specific domain'
param :domain_name, String, required: true, desc: 'Domain name'
param :status, String, required: true, desc: 'Status to be added'
def update
@domain.statuses = @domain.statuses << params[:id]
handle_errors(@domain) and return unless @domain.save
render_success(data: { domain: @domain.name, status: params[:id] })
end
private
def set_domain
registrar = current_user.registrar
@domain = Epp::Domain.find_by(registrar: registrar, name: params[:domain_id])
@domain ||= Epp::Domain.find_by!(registrar: registrar, name_puny: params[:domain_id])
return @domain if @domain
raise(ActiveRecord::RecordNotFound)
end
def verify_status
allowed_statuses = [DomainStatus::CLIENT_HOLD].freeze
stat = params[:id]
return if allowed_statuses.include?(stat)
@domain.add_epp_error('2306', nil, nil, "#{I18n.t(:client_side_status_editing_error)}: status #{stat}")
handle_errors(@domain)
end
def verify_status_removal
stat = params[:id]
return if @domain.statuses.include?(stat)
@domain.add_epp_error('2306', nil, nil, "#{I18n.t(:client_side_status_editing_error)}: status #{stat}")
handle_errors(@domain)
end
def verify_status_create
stat = params[:id]
return unless @domain.statuses.include?(stat)
@domain.add_epp_error('2306', nil, nil, "#{I18n.t(:client_side_status_editing_error)}: status #{stat}")
handle_errors(@domain)
end
end
end
end
end

View file

@ -66,6 +66,7 @@ Rails.application.routes.draw do
resources :contacts, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/contacts'
resources :renew, only: %i[create], constraints: { id: /.*/ }, controller: 'domains/renews'
resources :transfer, only: %i[create], constraints: { id: /.*/ }, controller: 'domains/transfers'
resources :statuses, only: %i[update destroy], constraints: { id: /.*/ }, controller: 'domains/statuses'
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
match "contacts", to: "domains/contacts#destroy", via: "delete", defaults: { id: nil }
collection do