Merge branch 'master' into remove-lib-from-autoload-path

This commit is contained in:
Artur Beljajev 2018-06-06 21:48:02 +03:00
commit 9e2ce0351d
82 changed files with 1674 additions and 2976 deletions

View file

@ -0,0 +1,20 @@
class Registrar
class BulkChangeController < DeppController
helper_method :available_contacts
def new
authorize! :manage, :repp
render file: 'registrar/bulk_change/new', locals: { active_tab: default_tab }
end
private
def available_contacts
current_user.registrar.contacts.order(:name).pluck(:name, :code)
end
def default_tab
:technical_contact
end
end
end

View file

@ -1,5 +1,5 @@
class Registrar
class DomainTransfersController < DeppController
class DomainTransfersController < BulkChangeController
before_action do
authorize! :transfer, Depp::Domain
end
@ -58,7 +58,7 @@ class Registrar
redirect_to registrar_domains_url
else
@api_errors = parsed_response[:errors]
render :new
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer }
end
else
params[:request] = true # EPP domain:transfer "op" attribute

View file

@ -1,9 +1,5 @@
class Registrar
class RegistrarNameserversController < DeppController
def edit
authorize! :manage, :repp
end
class NameserversController < BulkChangeController
def update
authorize! :manage, :repp
@ -52,7 +48,7 @@ class Registrar
redirect_to registrar_domains_url
else
@api_errors = parsed_response[:errors]
render :edit
render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver }
end
end
end

View file

@ -1,30 +1,34 @@
class Registrar
class PaymentsController < BaseController
protect_from_forgery except: :back
protect_from_forgery except: [:back, :callback]
skip_authorization_check # actually anyone can pay, no problems at all
skip_before_action :authenticate_user!, :check_ip_restriction, only: [:back]
before_action :check_bank
skip_before_action :authenticate_user!, :check_ip_restriction, only: [:back, :callback]
before_action :check_supported_payment_method
# to handle existing model we should
# get invoice_id and then get number
# build BankTransaction without connection with right reference number
# do not connect transaction and invoice
def pay
invoice = Invoice.find(params[:invoice_id])
@bank_link = BankLink::Request.new(params[:bank], invoice, self)
@bank_link.make_transaction
bank = params[:bank]
opts = {
return_url: registrar_return_payment_with_url(
bank, invoice_id: invoice
),
response_url: registrar_response_payment_with_url(
bank, invoice_id: invoice
)
}
@payment = ::PaymentOrders.create_with_type(bank, invoice, opts)
@payment.create_transaction
end
# connect invoice and transaction
# both back and IPN
def back
@bank_link = BankLink::Response.new(params[:bank], params)
if @bank_link.valid? && @bank_link.ok?
@bank_link.complete_payment
invoice = Invoice.find(params[:invoice_id])
opts = { response: params }
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
@payment.complete_transaction
if @bank_link.invoice.binded?
if invoice.binded?
flash[:notice] = t(:pending_applied)
else
flash[:alert] = t(:something_wrong)
@ -32,17 +36,31 @@ class Registrar
else
flash[:alert] = t(:something_wrong)
end
redirect_to registrar_invoice_path(@bank_link.invoice)
redirect_to registrar_invoice_path(invoice)
end
def callback
invoice = Invoice.find(params[:invoice_id])
opts = { response: params }
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
@payment.complete_transaction
end
render status: 200, json: { status: 'ok' }
end
private
def banks
ENV['payments_banks'].split(",").map(&:strip)
def check_supported_payment_method
return if supported_payment_method?
raise StandardError.new("Not supported payment method")
end
def check_bank
raise StandardError.new("Not Implemented bank") unless banks.include?(params[:bank])
def supported_payment_method?
PaymentOrders::PAYMENT_METHODS.include?(params[:bank])
end
end
end

View file

@ -0,0 +1,59 @@
class Registrar
class TechContactsController < BulkChangeController
def update
authorize! :manage, :repp
uri = URI.parse("#{ENV['repp_url']}domains/contacts")
request = Net::HTTP::Patch.new(uri)
request.set_form_data(current_contact_id: params[:current_contact_id],
new_contact_id: params[:new_contact_id])
request.basic_auth(current_user.username, current_user.password)
if Rails.env.test?
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(request)
end
elsif Rails.env.development?
client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path'])
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
verify_mode: OpenSSL::SSL::VERIFY_NONE,
cert: OpenSSL::X509::Certificate.new(client_cert),
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
http.request(request)
end
else
client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path'])
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
cert: OpenSSL::X509::Certificate.new(client_cert),
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
http.request(request)
end
end
parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200'
notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: #{parsed_response[:affected_domains].join(', ')}"
if parsed_response[:skipped_domains]
notices << "#{t('.skipped_domains')}: #{parsed_response[:skipped_domains].join(', ')}"
end
flash[:notice] = notices
redirect_to registrar_domains_url
else
@error = parsed_response[:error]
render file: 'registrar/bulk_change/new', locals: { active_tab: :technical_contact }
end
end
end
end