Fix some CC issues

This commit is contained in:
Karl Erik Õunapuu 2021-01-27 13:50:27 +02:00
parent 2ca9697b46
commit d1cd0867c8
No known key found for this signature in database
GPG key ID: C9DD647298A34764
13 changed files with 72 additions and 63 deletions

View file

@ -2,6 +2,7 @@ source 'https://rubygems.org'
# core # core
gem 'active_interaction', '~> 3.8' gem 'active_interaction', '~> 3.8'
gem 'apipie-rails', '~> 0.5.18'
gem 'bootsnap', '>= 1.1.0', require: false gem 'bootsnap', '>= 1.1.0', require: false
gem 'iso8601', '0.12.1' # for dates and times gem 'iso8601', '0.12.1' # for dates and times
gem 'rails', '~> 6.0' gem 'rails', '~> 6.0'
@ -78,7 +79,6 @@ gem 'wkhtmltopdf-binary', '~> 0.12.5.1'
gem 'directo', github: 'internetee/directo', branch: 'master' gem 'directo', github: 'internetee/directo', branch: 'master'
group :development, :test do group :development, :test do
gem 'pry', '0.10.1' gem 'pry', '0.10.1'
gem 'puma' gem 'puma'
@ -92,5 +92,3 @@ group :test do
gem 'webdrivers' gem 'webdrivers'
gem 'webmock' gem 'webmock'
end end
gem "apipie-rails", "~> 0.5.18"

View file

@ -1,7 +1,6 @@
module Repp module Repp
module V1 module V1
class AccountsController < BaseController class AccountsController < BaseController
api :GET, '/repp/v1/accounts/balance' api :GET, '/repp/v1/accounts/balance'
desc "Get account's balance" desc "Get account's balance"
def balance def balance

View file

@ -9,7 +9,8 @@ module Repp
before_action :set_paper_trail_whodunnit before_action :set_paper_trail_whodunnit
rescue_from ActionController::ParameterMissing, Apipie::ParamInvalid, Apipie::ParamMissing do |exception| rescue_from ActionController::ParameterMissing, Apipie::ParamInvalid,
Apipie::ParamMissing do |exception|
render json: { code: 2003, message: exception }, status: :bad_request render json: { code: 2003, message: exception }, status: :bad_request
end end

View file

@ -6,6 +6,13 @@ module Repp
before_action :set_new_contact, only: [:update] before_action :set_new_contact, only: [:update]
before_action :set_domain, only: %i[index create destroy] before_action :set_domain, only: %i[index create destroy]
def_param_group :contacts_apidoc do
param :contacts, Array, required: true, desc: 'Array of new linked contacts' do
param :code, String, required: true, desc: 'Contact code'
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
end
end
api :GET, '/repp/v1/domains/:domain_name/contacts' api :GET, '/repp/v1/domains/:domain_name/contacts'
desc "View domain's admin and tech contacts" desc "View domain's admin and tech contacts"
def index def index
@ -17,11 +24,8 @@ module Repp
end end
api :POST, '/repp/v1/domains/:domain_name/contacts' api :POST, '/repp/v1/domains/:domain_name/contacts'
desc "Link new contact(s) to domain" desc 'Link new contact(s) to domain'
param :contacts, Array, required: true, desc: 'Array of new linked contacts' do param_group :contacts_apidoc
param :code, String, required: true, desc: 'Contact code'
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
end
def create def create
contact_create_params[:contacts].each { |c| c[:action] = 'add' } contact_create_params[:contacts].each { |c| c[:action] = 'add' }
action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user) action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user)
@ -35,11 +39,8 @@ module Repp
end end
api :DELETE, '/repp/v1/domains/:domain_name/contacts' api :DELETE, '/repp/v1/domains/:domain_name/contacts'
desc "Remove contact(s) from domain" desc 'Remove contact(s) from domain'
param :contacts, Array, required: true, desc: 'Array of new linked contacts' do param_group :contacts_apidoc
param :code, String, required: true, desc: 'Contact code'
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
end
def destroy def destroy
contact_create_params[:contacts].each { |c| c[:action] = 'rem' } contact_create_params[:contacts].each { |c| c[:action] = 'rem' }
action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user) action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user)

View file

@ -4,6 +4,13 @@ module Repp
class DnssecController < BaseController class DnssecController < BaseController
before_action :set_domain, only: %i[index create destroy] before_action :set_domain, only: %i[index create destroy]
def_param_group :dns_keys_apidoc do
param :flags, String, required: true, desc: '256 (KSK) or 257 (ZSK)'
param :protocol, String, required: true, desc: 'Key protocol (3)'
param :alg, String, required: true, desc: 'DNSSEC key algorithm (3,5,6,7,8,10,13,14)'
param :public_key, String, required: true, desc: 'DNSSEC public key'
end
api :GET, '/repp/v1/domains/:domain_name/dnssec' api :GET, '/repp/v1/domains/:domain_name/dnssec'
desc "View specific domain's DNSSEC keys" desc "View specific domain's DNSSEC keys"
def index def index
@ -15,10 +22,7 @@ module Repp
api :POST, '/repp/v1/domains/:domain_name/dnssec' api :POST, '/repp/v1/domains/:domain_name/dnssec'
desc 'Create a new DNSSEC key(s) for domain' desc 'Create a new DNSSEC key(s) for domain'
param :dns_keys, Array, required: true, desc: 'Array of new DNSSEC keys' do param :dns_keys, Array, required: true, desc: 'Array of new DNSSEC keys' do
param :flags, String, required: true, desc: '256 (KSK) or 257 (ZSK)' param_group :dns_keys_apidoc, DnssecController
param :protocol, String, required: true, desc: 'Key protocol (3)'
param :alg, String, required: true, desc: 'DNSSEC key algorithm (3,5,6,7,8,10,13,14)'
param :public_key, String, required: true, desc: 'DNSSEC public key'
end end
def create def create
dnssec_params[:dnssec][:dns_keys].each { |n| n[:action] = 'add' } dnssec_params[:dnssec][:dns_keys].each { |n| n[:action] = 'add' }
@ -33,11 +37,8 @@ module Repp
end end
api :DELETE, 'repp/v1/domains/:domain_name/dnssec' api :DELETE, 'repp/v1/domains/:domain_name/dnssec'
param :dns_keys, Array, required: true, desc: 'Array of removable DNSSEC keys' do param :dns_keys, Array, required: true, desc: 'Array of new DNSSEC keys' do
param :flags, String, required: true, desc: '256 (KSK) or 257 (ZSK)' param_group :dns_keys_apidoc, DnssecController
param :protocol, String, required: true, desc: 'Key protocol (3)'
param :alg, String, required: true, desc: 'DNSSEC key algorithm (3,5,6,7,8,10,13,14)'
param :public_key, String, required: true, desc: 'DNSSEC public key'
end end
def destroy def destroy
dnssec_params[:dnssec][:dns_keys].each { |n| n[:action] = 'rem' } dnssec_params[:dnssec][:dns_keys].each { |n| n[:action] = 'rem' }

View file

@ -4,14 +4,14 @@ module Repp
class StatusesController < BaseController class StatusesController < BaseController
before_action :set_domain, only: %i[update destroy] before_action :set_domain, only: %i[update destroy]
before_action :verify_status 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' api :DELETE, '/repp/v1/domains/:domain_name/statuses/:status'
desc 'Remove status from specific domain' desc 'Remove status from specific domain'
param :domain_name, String, required: true, desc: 'Domain name' param :domain_name, String, required: true, desc: 'Domain name'
param :status, String, required: true, desc: 'Status to be removed' param :status, String, required: true, desc: 'Status to be removed'
def destroy def destroy
return editing_failed unless @domain.statuses.include?(params[:id])
@domain.statuses = @domain.statuses.delete(params[:id]) @domain.statuses = @domain.statuses.delete(params[:id])
if @domain.save if @domain.save
render_success render_success
@ -25,8 +25,12 @@ module Repp
param :domain_name, String, required: true, desc: 'Domain name' param :domain_name, String, required: true, desc: 'Domain name'
param :status, String, required: true, desc: 'Status to be added' param :status, String, required: true, desc: 'Status to be added'
def update def update
return editing_failed if @domain.statuses.include?(params[:id])
@domain.statuses = @domain.statuses << params[:id] @domain.statuses = @domain.statuses << params[:id]
# rubocop:disable Style/AndOr
handle_errors(@domain) and return unless @domain.save handle_errors(@domain) and return unless @domain.save
# rubocop:enable Style/AndOr
render_success(data: { domain: @domain.name, status: params[:id] }) render_success(data: { domain: @domain.name, status: params[:id] })
end end
@ -39,23 +43,16 @@ module Repp
return if allowed_statuses.include?(stat) return if allowed_statuses.include?(stat)
@domain.add_epp_error('2306', nil, nil, "#{I18n.t(:client_side_status_editing_error)}: status #{stat}") @domain.add_epp_error('2306', nil, nil,
"#{I18n.t(:client_side_status_editing_error)}: status #{stat}")
handle_errors(@domain) handle_errors(@domain)
end end
def verify_status_removal def editing_failed
stat = params[:id] 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}") @domain.add_epp_error('2306', nil, nil,
handle_errors(@domain) "#{I18n.t(:client_side_status_editing_error)}: status #{stat}")
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) handle_errors(@domain)
end end
end end

View file

@ -24,8 +24,9 @@ module Repp
private private
def set_domain def set_domain
domain_id = transfer_params[:domain_id]
h = {} h = {}
h[transfer_params[:domain_id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_params[:domain_id] h[domain_id.match?(/\A[0-9]+\z/) ? :id : :name] = domain_id
@domain = Epp::Domain.find_by!(h) @domain = Epp::Domain.find_by!(h)
end end

View file

@ -38,13 +38,12 @@ module Repp
param :ipv4, Array, desc: 'Array of IPv4 addresses' param :ipv4, Array, desc: 'Array of IPv4 addresses'
param :ipv6, Array, desc: 'Array of IPv4 addresses' param :ipv6, Array, desc: 'Array of IPv4 addresses'
end end
param :admin_domain_contacts_attributes, Array, required: false, desc: 'Admin domain contacts codes' param :admin_domain_contacts_attributes, Array, required: false,
param :tech_domain_contacts_attributes, Array, required: false, desc: 'Tech domain contacts codes' desc: 'Admin domain contacts codes'
param :tech_domain_contacts_attributes, Array, required: false,
desc: 'Tech domain contacts codes'
param :dnskeys_attributes, Array, required: false, desc: 'DNSSEC keys for domain' do param :dnskeys_attributes, Array, required: false, desc: 'DNSSEC keys for domain' do
param :flags, String, required: true, desc: 'Flag of DNSSEC key' param_group :dns_keys_apidoc, Repp::V1::Domains::DnssecController
param :protocol, String, required: true, desc: 'Protocol of DNSSEC key'
param :alg, String, required: true, desc: 'Algorithm of DNSSEC key'
param :public_key, String, required: true, desc: 'Public key of DNSSEC key'
end end
end end
returns code: 200, desc: 'Successful domain registration response' do returns code: 200, desc: 'Successful domain registration response' do
@ -61,7 +60,9 @@ module Repp
@domain = Epp::Domain.new @domain = Epp::Domain.new
action = Actions::DomainCreate.new(@domain, domain_create_params) action = Actions::DomainCreate.new(@domain, domain_create_params)
# rubocop:disable Style/AndOr
handle_errors(@domain) and return unless action.call handle_errors(@domain) and return unless action.call
# rubocop:enable Style/AndOr
render_success(data: { domain: { name: @domain.name } }) render_success(data: { domain: { name: @domain.name } })
end end
@ -72,7 +73,8 @@ module Repp
param :domain, Hash, required: true, desc: 'Changes of domain object' do param :domain, Hash, required: true, desc: 'Changes of domain object' do
param :registrant, Hash, required: false, desc: 'New registrant object' do param :registrant, Hash, required: false, desc: 'New registrant object' do
param :code, String, required: true, desc: 'New registrant contact code' param :code, String, required: true, desc: 'New registrant contact code'
param :verified, [true, false], required: false, desc: 'Registrant change is already verified' param :verified, [true, false], required: false,
desc: 'Registrant change is already verified'
end end
param :auth_info, String, required: false, desc: 'New authorization code' param :auth_info, String, required: false, desc: 'New authorization code'
end end
@ -119,13 +121,17 @@ module Repp
api :DELETE, '/repp/v1/domains/:domain_name' api :DELETE, '/repp/v1/domains/:domain_name'
desc 'Delete specific domain' desc 'Delete specific domain'
param :delete, Hash, required: true, desc: 'Object holding verified key' do param :delete, Hash, required: true, desc: 'Object holding verified key' do
param :verified, [true, false], required: true, desc: 'Whether to ask registrant verification or not' param :verified, [true, false], required: true,
desc: 'Whether to ask registrant verification or not'
end end
def destroy def destroy
action = Actions::DomainDelete.new(@domain, params, current_user.registrar) action = Actions::DomainDelete.new(@domain, params, current_user.registrar)
handle_errors(@domain) and return unless action.call
render_success(data: { domain: { name: @domain.name }}) # rubocop:disable Style/AndOr
handle_errors(@domain) and return unless action.call
# rubocop:enable Style/AndOr
render_success(data: { domain: { name: @domain.name } })
end end
private private
@ -202,8 +208,8 @@ module Repp
end end
def domain_create_params def domain_create_params
params.require(:domain).require([:name, :registrant_id, :period, :period_unit]) params.require(:domain).require(%i[name registrant_id period period_unit])
params.require(:domain).permit(:name, :registrant_id, :period, :period_unit, :registrar_id) params.require(:domain).permit(%i[name registrant_id period period_unit registrar_id])
end end
end end
end end

View file

@ -8,10 +8,12 @@ module Repp
desc 'Get the latest unread poll message' desc 'Get the latest unread poll message'
def index def index
@notification = current_user.unread_notifications.order('created_at DESC').take @notification = current_user.unread_notifications.order('created_at DESC').take
render_success(data: nil) and return unless @notification
data = @notification.as_json(only: [:id, :text, :attached_obj_id, # rubocop:disable Style/AndOr
:attached_obj_type]) render_success(data: nil) and return unless @notification
# rubocop:enable Style/AndOr
data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type])
render_success(data: data) render_success(data: data)
end end
@ -20,8 +22,7 @@ module Repp
desc 'Get a specific poll message' desc 'Get a specific poll message'
def show def show
@notification = current_user.registrar.notifications.find(params[:id]) @notification = current_user.registrar.notifications.find(params[:id])
data = @notification.as_json(only: [:id, :text, :attached_obj_id, data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type])
:attached_obj_type])
render_success(data: data) render_success(data: data)
end end
@ -29,10 +30,12 @@ module Repp
api :PUT, '/repp/v1/registrar/notifications' api :PUT, '/repp/v1/registrar/notifications'
desc 'Mark poll message as read' desc 'Mark poll message as read'
param :notification, Hash, required: true do param :notification, Hash, required: true do
param :read, [true], required: true, desc: "Set as true to mark as read" param :read, [true], required: true, desc: 'Set as true to mark as read'
end end
def update def update
# rubocop:disable Style/AndOr
handle_errors(@notification) and return unless @notification.mark_as_read handle_errors(@notification) and return unless @notification.mark_as_read
# rubocop:enable Style/AndOr
render_success(data: { notification_id: @notification.id, read: true }) render_success(data: { notification_id: @notification.id, read: true })
end end

View file

@ -82,7 +82,9 @@ module Actions
end end
def assign_nameservers def assign_nameservers
domain.nameservers_attributes = params[:nameservers_attributes] if params[:nameservers_attributes] return unless params[:nameservers_attributes]
domain.nameservers_attributes = params[:nameservers_attributes]
end end
def assign_contact(contact_code, admin: true) def assign_contact(contact_code, admin: true)

View file

@ -13,7 +13,7 @@ module Serializers
updated_at: obj.updated_at, expire_time: obj.expire_time, outzone_at: obj.outzone_at, updated_at: obj.updated_at, expire_time: obj.expire_time, outzone_at: obj.outzone_at,
delete_date: obj.delete_date, force_delete_date: obj.force_delete_date, delete_date: obj.delete_date, force_delete_date: obj.force_delete_date,
authorization_code: obj.auth_info, contacts: contacts, nameservers: nameservers, authorization_code: obj.auth_info, contacts: contacts, nameservers: nameservers,
dnssec_keys: dnssec_keys, statuses: obj.statuses, dnssec_keys: dnssec_keys, statuses: obj.statuses
} }
json json