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