Merge remote-tracking branch 'origin/master' into repp-domains

This commit is contained in:
Karl Erik Õunapuu 2020-12-29 12:47:50 +02:00
commit 221e4ba578
No known key found for this signature in database
GPG key ID: C9DD647298A34764
140 changed files with 2575 additions and 731 deletions

View file

@ -0,0 +1,30 @@
module Admin
class BouncedMailAddressesController < BaseController
before_action :set_bounced_mail_address, only: %i[show destroy]
load_and_authorize_resource
# GET /bounced_mail_addresses
def index
@bounced_mail_addresses = BouncedMailAddress.all.order(created_at: :desc)
end
# GET /bounced_mail_addresses/1
def show; end
# DELETE /bounced_mail_addresses/1
def destroy
@bounced_mail_address.destroy
redirect_to(
admin_bounced_mail_addresses_url,
notice: 'Bounced mail address was successfully destroyed.'
)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_bounced_mail_address
@bounced_mail_address = BouncedMailAddress.find(params[:id])
end
end
end

View file

@ -10,6 +10,11 @@ module Api
head :unauthorized unless ip_allowed
end
def authenticate_shared_key
api_key = "Basic #{ENV['api_shared_key']}"
head(:unauthorized) unless api_key == request.authorization
end
def not_found_error
uuid = params['uuid']
json = { error: 'Not Found', uuid: uuid, message: 'Record not found' }

View file

@ -0,0 +1,25 @@
module Api
module V1
class BouncesController < BaseController
before_action :authenticate_shared_key
# POST api/v1/bounces/
def create
return head(:bad_request) unless bounce_params[:bounce][:bouncedRecipients].any?
BouncedMailAddress.record(bounce_params)
head(:created)
rescue ActionController::ParameterMissing
head(:bad_request)
end
def bounce_params
params.require(:data).require(:bounce).require(:bouncedRecipients).each do |r|
r.require(:emailAddress)
end
params.require(:data)
end
end
end
end

View file

@ -19,15 +19,16 @@ module Api
end
contacts = current_user_contacts.limit(limit).offset(offset)
serialized_contacts = contacts.collect { |contact| serialize_contact(contact) }
serialized_contacts = contacts.collect { |contact| serialize_contact(contact, false) }
render json: serialized_contacts
end
def show
contact = current_user_contacts.find_by(uuid: params[:uuid])
links = params[:links] == 'true'
if contact
render json: serialize_contact(contact)
render json: serialize_contact(contact, links)
else
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
end
@ -85,7 +86,7 @@ module Api
contact.registrar.notify(action)
end
render json: serialize_contact(contact)
render json: serialize_contact(contact, false)
end
private
@ -96,8 +97,8 @@ module Api
current_registrant_user.direct_contacts
end
def serialize_contact(contact)
Serializers::RegistrantApi::Contact.new(contact).to_json
def serialize_contact(contact, links)
Serializers::RegistrantApi::Contact.new(contact, links).to_json
end
end
end

View file

@ -7,6 +7,7 @@ module Api
def index
limit = params[:limit] || 200
offset = params[:offset] || 0
simple = params[:simple] == 'true' || false
if limit.to_i > 200 || limit.to_i < 1
render(json: { errors: [{ limit: ['parameter is out of range'] }] },
@ -18,21 +19,20 @@ module Api
status: :bad_request) && return
end
@domains = current_user_domains.limit(limit).offset(offset)
serialized_domains = @domains.map do |item|
serializer = Serializers::RegistrantApi::Domain.new(item)
domains = current_user_domains
serialized_domains = domains.limit(limit).offset(offset).map do |item|
serializer = Serializers::RegistrantApi::Domain.new(item, simplify: simple)
serializer.to_json
end
render json: serialized_domains
render json: { count: domains.count, domains: serialized_domains }
end
def show
@domain = current_user_domains.find_by(uuid: params[:uuid])
if @domain
serializer = Serializers::RegistrantApi::Domain.new(@domain)
serializer = Serializers::RegistrantApi::Domain.new(@domain, simplify: false)
render json: serializer.to_json
else
render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found

View file

@ -4,11 +4,38 @@ class Registrar
def new
authorize! :manage, :repp
@expire_date = Time.zone.now.to_date
render file: 'registrar/bulk_change/new', locals: { active_tab: default_tab }
end
def bulk_renew
authorize! :manage, :repp
set_form_data
if ready_to_renew?
res = ReppApi.bulk_renew(domain_ids_for_bulk_renew, params[:period],
current_registrar_user)
flash_message(JSON.parse(res))
else
flash[:notice] = nil
end
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew }
end
private
def ready_to_renew?
domain_ids_for_bulk_renew.present? && params[:renew].present?
end
def set_form_data
@expire_date = params[:expire_date].to_date
@domains = domains_by_date(@expire_date)
@period = params[:period]
end
def available_contacts
current_registrar_user.registrar.contacts.order(:name).pluck(:name, :code)
end
@ -16,5 +43,27 @@ class Registrar
def default_tab
:technical_contact
end
def domains_scope
current_registrar_user.registrar.domains
end
def domains_by_date(date)
domains_scope.where('valid_to <= ?', date)
end
def domain_ids_for_bulk_renew
params.dig('domain_ids')&.reject { |id| id.blank? }
end
def renew_task(domains)
Domains::BulkRenew::Start.run(domains: domains,
period_element: @period,
registrar: current_registrar_user.registrar)
end
def flash_message(res)
flash[:notice] = res['code'] == 1000 ? t(:bulk_renew_completed) : res['message']
end
end
end

View file

@ -55,10 +55,12 @@ class Registrar
parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200'
flash[:notice] = t '.transferred', count: parsed_response[:data].size
failed = parsed_response[:data][:failed].each(&:domain_name).join(', ')
flash[:notice] = t('.transferred', count: parsed_response[:data][:success].size,
failed: failed)
redirect_to registrar_domains_url
else
@api_errors = parsed_response[:errors]
@api_errors = parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer }
end
else

View file

@ -49,12 +49,13 @@ class Registrar
if response.code == '200'
notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: #{parsed_response[:affected_domains].join(', ')}"
notices << "#{t('.affected_domains')}: " \
"#{parsed_response[:data][:affected_domains].join(', ')}"
flash[:notice] = notices
flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url
else
@api_errors = parsed_response[:errors]
@api_errors = parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver }
end
end

View file

@ -62,6 +62,7 @@ class Registrar
def find_user_by_idc_and_allowed(idc)
return User.new unless idc
possible_users = ApiUser.where(identity_code: idc) || User.new
possible_users.each do |selected_user|
if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip)

View file

@ -43,16 +43,18 @@ class Registrar
if response.code == '200'
notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: #{parsed_response[:affected_domains].join(', ')}"
notices << "#{t('.affected_domains')}: " \
"#{parsed_response[:data][:affected_domains].join(', ')}"
if parsed_response[:skipped_domains]
notices << "#{t('.skipped_domains')}: #{parsed_response[:skipped_domains].join(', ')}"
if parsed_response[:data][:skipped_domains]
notices << "#{t('.skipped_domains')}: " \
"#{parsed_response[:data][:skipped_domains].join(', ')}"
end
flash[:notice] = notices
flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url
else
@error = parsed_response[:error]
@error = response.code == '404' ? 'Contact(s) not found' : parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :technical_contact }
end
end

View file

@ -3,6 +3,7 @@ module Repp
class BaseController < ActionController::API
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
before_action :authenticate_user
before_action :validate_webclient_ca
before_action :check_ip_restriction
attr_reader :current_user
@ -93,15 +94,33 @@ module Repp
end
def check_ip_restriction
allowed = @current_user.registrar.api_ip_white?(request.ip)
return if allowed
return if webclient_request?
return if @current_user.registrar.api_ip_white?(request.ip)
@response = { code: 2202,
message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) }
render(json: @response, status: :unauthorized)
end
def webclient_request?
return if Rails.env.test?
ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
end
def validate_webclient_ca
return unless webclient_request?
request_name = request.env['HTTP_SSL_CLIENT_S_DN_CN']
webclient_cn = ENV['webclient_cert_common_name'] || 'webclient'
return if request_name == webclient_cn
@response = { code: 2202,
message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) }
render(json: @response, status: :unauthorized)
end
def not_found_error
@response = { code: 2303, message: 'Object does not exist' }
render(json: @response, status: :not_found)

View file

@ -0,0 +1,65 @@
module Repp
module V1
module Domains
class RenewsController < BaseController
before_action :validate_renew_period, only: [:bulk_renew]
before_action :select_renewable_domains, only: [:bulk_renew]
def bulk_renew
renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period])
return render_success(data: { updated_domains: @domains.map(&:name) }) if renew.valid?
@epp_errors << { code: 2002,
msg: renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ') }
handle_errors
end
private
def validate_renew_period
@epp_errors ||= []
periods = Depp::Domain::PERIODS.map { |p| p[1] }
return if periods.include? bulk_renew_params[:renew_period]
@epp_errors << { code: 2005, msg: 'Invalid renew period' }
end
def select_renewable_domains
@epp_errors ||= []
if bulk_renew_params[:domains].instance_of?(Array)
@domains = bulk_renew_domains
else
@epp_errors << { code: 2005, msg: 'Domains attribute must be an array' }
end
return handle_errors if @epp_errors.any?
end
def run_bulk_renew_task(domains, period)
::Domains::BulkRenew::Start.run(domains: domains, period_element: period,
registrar: current_user.registrar)
end
def bulk_renew_params
params do
params.require(%i[domains renew_period])
params.permit(:domains, :renew_period)
end
end
def bulk_renew_domains
@epp_errors ||= []
domains = []
bulk_renew_params[:domains].each do |idn|
domain = Epp::Domain.find_by(name: idn)
domains << domain if domain
@epp_errors << { code: 2304, msg: "Object does not exist: #{idn}" } unless domain
end
domains
end
end
end
end
end