Merge remote-tracking branch 'origin/master' into 105846070-merge-with-105842700-arireg-for-registrant-port

# Conflicts:
#	app/models/domain.rb
This commit is contained in:
Vladimir Krylov 2016-02-15 10:11:07 +02:00
commit afd3b06f62
94 changed files with 2001 additions and 720 deletions

View file

@ -12,11 +12,27 @@ class Admin::AccountActivitiesController < AdminController
logger.warn('Invalid date')
end
balance_params = params[:q].deep_dup
if balance_params[:created_at_gteq]
balance_params.delete('created_at_gteq')
end
@q = AccountActivity.includes(:invoice, account: :registrar).search(params[:q])
@b = AccountActivity.search(balance_params)
@q.sorts = 'id desc' if @q.sorts.empty?
@account_activities = @q.result.page(params[:page]).per(params[:results_per_page])
sort = @account_activities.orders.map(&:to_sql).join(",")
if params[:page] && params[:page].to_i > 1
@sum = @q.result.reorder(sort).limit(@account_activities.offset_value) + @b.result.where.not(id: @q.result.map(&:id))
else
@sum = @b.result.where.not(id: @q.result.map(&:id))
end
respond_to do |format|
format.html { @account_activities = @q.result.page(params[:page]) }
format.html
format.csv do
send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
end

View file

@ -2,22 +2,54 @@ class Admin::BlockedDomainsController < AdminController
load_and_authorize_resource
def index
bd = BlockedDomain.first_or_initialize
@blocked_domains = bd.names.join("\n")
params[:q] ||= {}
domains = BlockedDomain.all.order(:name)
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
def new
@domain = BlockedDomain.new
end
def create
names = params[:blocked_domains].split("\r\n").map(&:strip)
bd = BlockedDomain.first_or_create
@domain = BlockedDomain.new(blocked_domain_params)
if bd.update(names: names)
flash[:notice] = I18n.t('record_updated')
redirect_to :back
if @domain.save
flash[:notice] = I18n.t('domain_added')
redirect_to admin_blocked_domains_path
else
@blocked_domains = params[:blocked_domains]
flash.now[:alert] = I18n.t('failed_to_update_record')
render :index
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end
def delete
if BlockedDomain.find(params[:id]).destroy
flash[:notice] = I18n.t('domain_deleted')
redirect_to admin_blocked_domains_path
else
flash.now[:alert] = I18n.t('failed_to_delete_domain')
redirect_to admin_blocked_domains_path
end
end
end
def blocked_domain_params
params.require(:blocked_domain).permit(:name)
end
private
def set_domain
@domain = BlockedDomain.find(params[:id])
end
end

View file

@ -4,8 +4,14 @@ class Admin::ContactsController < AdminController
def index
params[:q] ||= {}
@q = Contact.includes(:registrar).search(params[:q])
@contacts = @q.result.page(params[:page])
search_params = params[:q].deep_dup
if search_params[:domain_contacts_type_in].is_a?(Array) && search_params[:domain_contacts_type_in].delete('registrant')
search_params[:registrant_domains_id_not_null] = 1
end
@q = Contact.includes(:registrar).search(search_params)
@contacts = @q.result(distinct: :true).page(params[:page])
if params[:statuses_contains]
contacts = Contact.includes(:registrar).where(
@ -16,8 +22,8 @@ class Admin::ContactsController < AdminController
end
normalize_search_parameters do
@q = contacts.search(params[:q])
@contacts = @q.result.page(params[:page])
@q = contacts.search(search_params)
@contacts = @q.result(distinct: :true).page(params[:page])
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0

View file

@ -23,7 +23,7 @@ class Admin::InvoicesController < AdminController
def index
@q = Invoice.includes(:account_activity).search(params[:q])
@q.sorts = 'id desc' if @q.sorts.empty?
@q.sorts = 'number desc' if @q.sorts.empty?
@invoices = @q.result.page(params[:page])
end

View file

@ -5,9 +5,7 @@ class Admin::PendingDeletesController < AdminController
def update
authorize! :update, :pending
@epp_domain = Epp::Domain.find(params[:domain_id]) # only epp domain has apply pending
@epp_domain.is_admin= true
if @epp_domain.apply_pending_delete!
if registrant_verification.domain_registrant_delete_confirm!
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
else
redirect_to admin_edit_domain_path(@domain.id), alert: t(:failure)
@ -17,7 +15,7 @@ class Admin::PendingDeletesController < AdminController
def destroy
authorize! :destroy, :pending
if @domain.clean_pendings!
if registrant_verification.domain_registrant_delete_reject!
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
else
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
@ -26,6 +24,14 @@ class Admin::PendingDeletesController < AdminController
private
def registrant_verification
# steal token
token = @domain.registrant_verification_token
@registrant_verification = RegistrantVerification.new(domain_id: @domain.id,
domain_name: @domain.name,
verification_token: token)
end
def find_domain
@domain = Domain.find(params[:domain_id])
end

View file

@ -5,8 +5,7 @@ class Admin::PendingUpdatesController < AdminController
def update
authorize! :update, :pending
@epp_domain = Epp::Domain.find(params[:domain_id]) # only epp domain has apply pending
if @epp_domain.apply_pending_update!
if registrant_verification.domain_registrant_change_confirm!
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
else
redirect_to edit_admin_domain_path(@domain.id), alert: t(:failure)
@ -15,14 +14,21 @@ class Admin::PendingUpdatesController < AdminController
def destroy
authorize! :destroy, :pending
if @domain.clean_pendings!
if registrant_verification.domain_registrant_change_reject!
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
else
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
end
end
def registrant_verification
# steal token
token = @domain.registrant_verification_token
@registrant_verification = RegistrantVerification.new(domain_id: @domain.id,
domain_name: @domain.name,
verification_token: token)
end
private
def find_domain

View file

@ -6,7 +6,7 @@ class Admin::RegistrarsController < AdminController
end
def index
@q = Registrar.ordered.search(params[:q])
@q = Registrar.joins(:accounts).ordered.search(params[:q])
@registrars = @q.result.page(params[:page])
end

View file

@ -1,51 +1,68 @@
class Admin::ReservedDomainsController < AdminController
load_and_authorize_resource
before_action :set_domain, only: [:edit, :update]
def index
names = ReservedDomain.pluck(:names).each_with_object({}){|e_h,h| h.merge!(e_h)}
names.names = nil if names.blank?
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
params[:q] ||= {}
domains = ReservedDomain.all.order(:name)
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
def new
@domain = ReservedDomain.new
end
def edit
end
def create
@reserved_domains = params[:reserved_domains]
begin
params[:reserved_domains] = "---\n" if params[:reserved_domains].blank?
names = YAML.load(params[:reserved_domains])
fail if names == false
rescue
flash.now[:alert] = I18n.t('invalid_yaml')
logger.warn 'Invalid YAML'
render :index and return
end
@domain = ReservedDomain.new(reserved_domain_params)
result = true
ReservedDomain.transaction do
# removing old ones
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
ReservedDomain.where.not(id: existing).delete_all
#updating and adding
names.each do |name, psw|
rec = ReservedDomain.by_domain(name).first
rec ||= ReservedDomain.new
rec.names = {name => psw}
unless rec.save
result = false
raise ActiveRecord::Rollback
end
end
end
if result
flash[:notice] = I18n.t('record_updated')
redirect_to :back
if @domain.save
flash[:notice] = I18n.t('domain_added')
redirect_to admin_reserved_domains_path
else
flash.now[:alert] = I18n.t('failed_to_update_record')
render :index
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end
def update
if @domain.update(reserved_domain_params)
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
render 'edit'
end
def delete
if ReservedDomain.find(params[:id]).destroy
flash[:notice] = I18n.t('domain_deleted')
redirect_to admin_reserved_domains_path
else
flash.now[:alert] = I18n.t('failed_to_delete_domain')
redirect_to admin_reserved_domains_path
end
end
private
def reserved_domain_params
params.require(:reserved_domain).permit(:name, :password)
end
def set_domain
@domain = ReservedDomain.find(params[:id])
end
end

View file

@ -67,8 +67,7 @@ class ApplicationController < ActionController::Base
end
def user_log_str(user)
return 'public' if user.nil?
"#{user.id}-#{user.class}: #{user.username}"
user.nil? ? 'public' : user.id_role_username
end
def comma_support_for(parent_key, key)

View file

@ -29,11 +29,6 @@ class Epp::DomainsController < EppController
handle_errors(@domain) and return if @domain.errors.any?
handle_errors and return unless balance_ok?('create') # loads pricelist in this method
if !@domain_pricelist.try(:price)#checking if pricelist is not found
@domain.add_epp_error('2306', nil, nil, 'No price list for domain')
handle_errors(@domain) and return if @domain.errors.any?
end
ActiveRecord::Base.transaction do
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
current_user.registrar.debit!({
@ -107,10 +102,6 @@ class Epp::DomainsController < EppController
period_unit = Epp::Domain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
balance_ok?('renew', period, period_unit) # loading pricelist
if !@domain_pricelist.try(:price)#checking if pricelist is not found
@domain.add_epp_error('2306', nil, nil, 'No price list for domain')
handle_errors(@domain) and return if @domain.errors.any?
end
ActiveRecord::Base.transaction do
success = @domain.renew(
@ -258,12 +249,19 @@ class Epp::DomainsController < EppController
def balance_ok?(operation, period = nil, unit = nil)
@domain_pricelist = @domain.pricelist(operation, period.try(:to_i), unit)
if current_user.registrar.balance < @domain_pricelist.price.amount
if @domain_pricelist.try(:price) # checking if price list is not found
if current_user.registrar.balance < @domain_pricelist.price.amount
epp_errors << {
code: '2104',
msg: I18n.t('billing_failure_credit_balance_low')
}
return false
end
else
epp_errors << {
code: '2104',
msg: I18n.t('billing_failure_credit_balance_low')
code: '2104',
msg: I18n.t(:active_price_missing_for_this_operation)
}
return false
end
true

View file

@ -3,18 +3,68 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
def index
authorize! :view, Depp::Contact
limit, offset = pagination_details
res = depp_current_user.repp_request('contacts', { details: true, limit: limit, offset: offset })
if res.code == '200'
@response = res.parsed_body.with_indifferent_access
@contacts = @response ? @response[:contacts] : []
params[:q] ||= {}
params[:q].delete_if { |_k, v| v.blank? }
@paginatable_array = Kaminari.paginate_array(
[], total_count: @response[:total_number_of_records]
).page(params[:page]).per(limit)
search_params = params[:q].deep_dup
if search_params[:domain_contacts_type_in].is_a?(Array) && search_params[:domain_contacts_type_in].delete('registrant')
search_params[:registrant_domains_id_not_null] = 1
end
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
if search_params.length == 1 && search_params[:name_matches].present?
@contacts = Contact.find_by(name: search_params[:name_matches])
end
if params[:statuses_contains]
contacts = current_user.registrar.contacts.includes(:registrar).where(
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
contacts = current_user.registrar.contacts.includes(:registrar)
end
normalize_search_parameters do
@q = contacts.search(search_params)
@contacts = @q.result(distinct: :true).page(params[:page])
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
def download_list
authorize! :view, Depp::Contact
params[:q] ||= {}
params[:q].delete_if { |_k, v| v.blank? }
if params[:q].length == 1 && params[:q][:name_matches].present?
@contacts = Contact.find_by(name: params[:q][:name_matches])
end
if params[:statuses_contains]
contacts = current_user.registrar.contacts.includes(:registrar).where(
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
contacts = current_user.registrar.contacts.includes(:registrar)
end
normalize_search_parameters do
@q = contacts.search(params[:q])
@contacts = @q.result.page(params[:page])
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
respond_to do |format|
format.csv { render text: @contacts.to_csv }
format.pdf do
pdf = @contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false))
send_data pdf, filename: 'contacts.pdf'
end
end
end
def new
@ -75,4 +125,18 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
def init_epp_contact
Depp::Contact.user = depp_current_user
end
def normalize_search_parameters
ca_cache = params[:q][:valid_to_lteq]
begin
end_time = params[:q][:valid_to_lteq].try(:to_date)
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
rescue
logger.warn('Invalid date')
end
yield
params[:q][:valid_to_lteq] = ca_cache
end
end