mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Merge branch 'master' into registry-569
# Conflicts: # app/controllers/admin/contacts_controller.rb
This commit is contained in:
commit
e4740f3f32
40 changed files with 1287 additions and 1236 deletions
|
@ -1,60 +1,62 @@
|
|||
class Admin::AccountActivitiesController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_default_dates, only: [:index]
|
||||
module Admin
|
||||
class AccountActivitiesController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_default_dates, only: [:index]
|
||||
|
||||
def index # rubocop: disable Metrics/AbcSize
|
||||
def index # rubocop: disable Metrics/AbcSize
|
||||
|
||||
ca_cache = params[:q][:created_at_lteq]
|
||||
begin
|
||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
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(",")
|
||||
|
||||
# can do here inline SQL as it's our
|
||||
if params[:page] && params[:page].to_i > 1
|
||||
@sum = @q.result.reorder(sort).limit(@account_activities.offset_value).sum(:sum) + @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||
else
|
||||
@sum = @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.csv do
|
||||
send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
end
|
||||
end
|
||||
|
||||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
ca_cache = params[:q][:created_at_lteq]
|
||||
begin
|
||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
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(",")
|
||||
|
||||
# can do here inline SQL as it's our
|
||||
if params[:page] && params[:page].to_i > 1
|
||||
@sum = @q.result.reorder(sort).limit(@account_activities.offset_value).sum(:sum) + @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||
else
|
||||
@sum = @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.csv do
|
||||
send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
end
|
||||
end
|
||||
|
||||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,63 +1,67 @@
|
|||
class Admin::AdminUsersController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
||||
module Admin
|
||||
class AdminUsersController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@q = AdminUser.search(params[:q])
|
||||
@admin_users = @q.result.page(params[:page]).order(:username)
|
||||
end
|
||||
|
||||
def new
|
||||
@admin_user = AdminUser.new
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
@admin_user = AdminUser.new(admin_user_params)
|
||||
|
||||
if @admin_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def index
|
||||
@q = AdminUser.search(params[:q])
|
||||
@admin_users = @q.result.page(params[:page]).order(:username)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
params[:admin_user].delete(:password) if params[:admin_user][:password].blank?
|
||||
params[:admin_user].delete(:password_confirmation) if params[:admin_user][:password_confirmation].blank?
|
||||
|
||||
if @admin_user.update_attributes(admin_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
def new
|
||||
@admin_user = AdminUser.new
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @admin_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_admin_users_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
def show;
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def edit;
|
||||
end
|
||||
|
||||
def set_user
|
||||
@admin_user = AdminUser.find(params[:id])
|
||||
end
|
||||
def create
|
||||
@admin_user = AdminUser.new(admin_user_params)
|
||||
|
||||
def admin_user_params
|
||||
params.require(:admin_user).permit(:username,
|
||||
:password, :password_confirmation, :identity_code, :email, :country_code, { roles: [] })
|
||||
if @admin_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
params[:admin_user].delete(:password) if params[:admin_user][:password].blank?
|
||||
params[:admin_user].delete(:password_confirmation) if params[:admin_user][:password_confirmation].blank?
|
||||
|
||||
if @admin_user.update_attributes(admin_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @admin_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_admin_users_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_user
|
||||
@admin_user = AdminUser.find(params[:id])
|
||||
end
|
||||
|
||||
def admin_user_params
|
||||
params.require(:admin_user).permit(:username,
|
||||
:password, :password_confirmation, :identity_code, :email, :country_code, { roles: [] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,63 +1,67 @@
|
|||
class Admin::ApiUsersController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_api_user, only: [:show, :edit, :update, :destroy]
|
||||
module Admin
|
||||
class ApiUsersController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_api_user, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@q = ApiUser.includes(:registrar).search(params[:q])
|
||||
@api_users = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||
@api_user = ApiUser.new(registrar: @registrar)
|
||||
end
|
||||
|
||||
def create
|
||||
@api_user = ApiUser.new(api_user_params)
|
||||
|
||||
if @api_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @api_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def index
|
||||
@q = ApiUser.includes(:registrar).search(params[:q])
|
||||
@api_users = @q.result.page(params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
params[:api_user].delete(:password) if params[:api_user][:password].blank?
|
||||
if @api_user.update(api_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
def new
|
||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||
@api_user = ApiUser.new(registrar: @registrar)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @api_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_api_users_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
def create
|
||||
@api_user = ApiUser.new(api_user_params)
|
||||
|
||||
if @api_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @api_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def show;
|
||||
end
|
||||
|
||||
def set_api_user
|
||||
@api_user = ApiUser.find(params[:id])
|
||||
end
|
||||
def edit;
|
||||
end
|
||||
|
||||
def api_user_params
|
||||
params.require(:api_user).permit(:username, :password, :active,
|
||||
:registrar_id, :registrar_typeahead,
|
||||
:identity_code, { roles: [] })
|
||||
def update
|
||||
params[:api_user].delete(:password) if params[:api_user][:password].blank?
|
||||
if @api_user.update(api_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @api_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_api_users_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_api_user
|
||||
@api_user = ApiUser.find(params[:id])
|
||||
end
|
||||
|
||||
def api_user_params
|
||||
params.require(:api_user).permit(:username, :password, :active,
|
||||
:registrar_id, :registrar_typeahead,
|
||||
:identity_code, { roles: [] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,87 +1,89 @@
|
|||
class Admin::BankStatementsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class BankStatementsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_bank_statement, only: [:show, :download_import_file, :bind_invoices]
|
||||
before_action :set_bank_statement, only: [:show, :download_import_file, :bind_invoices]
|
||||
|
||||
def index
|
||||
@q = BankStatement.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
@bank_statements = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@q = @bank_statement.bank_transactions.includes(:account_activity).search(params[:q])
|
||||
@q.sorts = 'account_activity_id desc' if @q.sorts.empty?
|
||||
@bank_transactions = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@bank_statement = BankStatement.new(
|
||||
bank_code: Setting.registry_bank_code,
|
||||
iban: Setting.registry_iban
|
||||
)
|
||||
@invoice = Invoice.find_by(id: params[:invoice_id])
|
||||
@bank_transaction = @bank_statement.bank_transactions.build(
|
||||
description: @invoice.to_s,
|
||||
sum: @invoice.sum,
|
||||
reference_no: @invoice.reference_no,
|
||||
paid_at: Time.zone.now.to_date,
|
||||
currency: 'EUR'
|
||||
) if @invoice
|
||||
end
|
||||
|
||||
def create
|
||||
@bank_statement = BankStatement.new(bank_statement_params)
|
||||
|
||||
if @bank_statement.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_statement]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def index
|
||||
@q = BankStatement.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
@bank_statements = @q.result.page(params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def import
|
||||
@bank_statement = BankStatement.new
|
||||
end
|
||||
|
||||
def create_from_import
|
||||
@bank_statement = BankStatement.new(bank_statement_params)
|
||||
|
||||
if @bank_statement.import
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_statement]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def show
|
||||
@q = @bank_statement.bank_transactions.includes(:account_activity).search(params[:q])
|
||||
@q.sorts = 'account_activity_id desc' if @q.sorts.empty?
|
||||
@bank_transactions = @q.result.page(params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def bind_invoices
|
||||
@bank_statement.bind_invoices
|
||||
def new
|
||||
@bank_statement = BankStatement.new(
|
||||
bank_code: Setting.registry_bank_code,
|
||||
iban: Setting.registry_iban
|
||||
)
|
||||
@invoice = Invoice.find_by(id: params[:invoice_id])
|
||||
@bank_transaction = @bank_statement.bank_transactions.build(
|
||||
description: @invoice.to_s,
|
||||
sum: @invoice.sum,
|
||||
reference_no: @invoice.reference_no,
|
||||
paid_at: Time.zone.now.to_date,
|
||||
currency: 'EUR'
|
||||
) if @invoice
|
||||
end
|
||||
|
||||
flash[:notice] = t('invoices_were_fully_binded') if @bank_statement.fully_binded?
|
||||
flash[:warning] = t('invoices_were_partially_binded') if @bank_statement.partially_binded?
|
||||
flash[:alert] = t('no_invoices_were_binded') if @bank_statement.not_binded?
|
||||
def create
|
||||
@bank_statement = BankStatement.new(bank_statement_params)
|
||||
|
||||
redirect_to [:admin, @bank_statement]
|
||||
end
|
||||
if @bank_statement.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_statement]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def download_import_file
|
||||
filename = @bank_statement.import_file_path.split('/').last
|
||||
send_data File.open(@bank_statement.import_file_path, 'r').read, filename: filename
|
||||
end
|
||||
def import
|
||||
@bank_statement = BankStatement.new
|
||||
end
|
||||
|
||||
private
|
||||
def create_from_import
|
||||
@bank_statement = BankStatement.new(bank_statement_params)
|
||||
|
||||
def set_bank_statement
|
||||
@bank_statement = BankStatement.find(params[:id])
|
||||
end
|
||||
if @bank_statement.import
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_statement]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def bank_statement_params
|
||||
params.require(:bank_statement).permit(:th6_file, :bank_code, :iban, bank_transactions_attributes: [
|
||||
:description, :sum, :currency, :reference_no, :paid_at
|
||||
])
|
||||
def bind_invoices
|
||||
@bank_statement.bind_invoices
|
||||
|
||||
flash[:notice] = t('invoices_were_fully_binded') if @bank_statement.fully_binded?
|
||||
flash[:warning] = t('invoices_were_partially_binded') if @bank_statement.partially_binded?
|
||||
flash[:alert] = t('no_invoices_were_binded') if @bank_statement.not_binded?
|
||||
|
||||
redirect_to [:admin, @bank_statement]
|
||||
end
|
||||
|
||||
def download_import_file
|
||||
filename = @bank_statement.import_file_path.split('/').last
|
||||
send_data File.open(@bank_statement.import_file_path, 'r').read, filename: filename
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_bank_statement
|
||||
@bank_statement = BankStatement.find(params[:id])
|
||||
end
|
||||
|
||||
def bank_statement_params
|
||||
params.require(:bank_statement).permit(:th6_file, :bank_code, :iban, bank_transactions_attributes: [
|
||||
:description, :sum, :currency, :reference_no, :paid_at
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,54 +1,56 @@
|
|||
class Admin::BankTransactionsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class BankTransactionsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def new
|
||||
@bank_statement = BankStatement.find(params[:bank_statement_id])
|
||||
@bank_transaction = BankTransaction.new(currency: 'EUR')
|
||||
end
|
||||
|
||||
def create
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
@bank_transaction = BankTransaction.new(
|
||||
bank_transaction_params.merge(bank_statement_id: params[:bank_statement_id])
|
||||
)
|
||||
|
||||
if @bank_transaction.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def new
|
||||
@bank_statement = BankStatement.find(params[:bank_statement_id])
|
||||
@bank_transaction = BankTransaction.new(currency: 'EUR')
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
if @bank_transaction.update(bank_transaction_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
def create
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
@bank_transaction = BankTransaction.new(
|
||||
bank_transaction_params.merge(bank_statement_id: params[:bank_statement_id])
|
||||
)
|
||||
|
||||
if @bank_transaction.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def bind
|
||||
if @bank_transaction.bind_invoice(params[:invoice_no])
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'show'
|
||||
def update
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
if @bank_transaction.update(bank_transaction_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def bind
|
||||
if @bank_transaction.bind_invoice(params[:invoice_no])
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def bank_transaction_params
|
||||
params.require(:bank_transaction).permit(
|
||||
:description, :sum, :reference_no, :document_no,
|
||||
:bank_reference, :iban, :buyer_bank_code, :buyer_iban,
|
||||
:buyer_name, :currency, :paid_at
|
||||
)
|
||||
private
|
||||
|
||||
def bank_transaction_params
|
||||
params.require(:bank_transaction).permit(
|
||||
:description, :sum, :reference_no, :document_no,
|
||||
:bank_reference, :iban, :buyer_bank_code, :buyer_iban,
|
||||
:buyer_name, :currency, :paid_at
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
10
app/controllers/admin/base_controller.rb
Normal file
10
app/controllers/admin/base_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Admin
|
||||
class BaseController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
helper_method :head_title_sufix
|
||||
|
||||
def head_title_sufix
|
||||
t(:admin_head_title_sufix)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module Admin
|
||||
module Billing
|
||||
class PricesController < AdminController
|
||||
class PricesController < BaseController
|
||||
authorize_resource(class: 'Billing::Price')
|
||||
before_action :load_price, only: %i[edit update expire]
|
||||
helper_method :zones
|
||||
|
|
|
@ -1,55 +1,57 @@
|
|||
class Admin::BlockedDomainsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class BlockedDomainsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
def index
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
@domain = BlockedDomain.new(blocked_domain_params)
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('domain_added')
|
||||
redirect_to admin_blocked_domains_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_add_domain')
|
||||
render 'new'
|
||||
end
|
||||
|
||||
end
|
||||
def new
|
||||
|
||||
def delete
|
||||
@domain = BlockedDomain.new
|
||||
|
||||
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
|
||||
|
||||
def create
|
||||
|
||||
@domain = BlockedDomain.new(blocked_domain_params)
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('domain_added')
|
||||
redirect_to admin_blocked_domains_path
|
||||
else
|
||||
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
|
||||
|
||||
|
||||
def blocked_domain_params
|
||||
params.require(:blocked_domain).permit(:name)
|
||||
end
|
||||
def blocked_domain_params
|
||||
params.require(:blocked_domain).permit(:name)
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def set_domain
|
||||
@domain = BlockedDomain.find(params[:id])
|
||||
def set_domain
|
||||
@domain = BlockedDomain.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +1,87 @@
|
|||
class Admin::CertificatesController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_certificate, :set_api_user, only: [:sign, :show, :download_csr, :download_crt, :revoke, :destroy]
|
||||
module Admin
|
||||
class CertificatesController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_certificate, :set_api_user, only: [:sign, :show, :download_csr, :download_crt, :revoke, :destroy]
|
||||
|
||||
def show; end
|
||||
def show;
|
||||
end
|
||||
|
||||
def new
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
@certificate = Certificate.new(api_user: @api_user)
|
||||
end
|
||||
def new
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
@certificate = Certificate.new(api_user: @api_user)
|
||||
end
|
||||
|
||||
def create
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
def create
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
|
||||
crt = certificate_params[:crt].open.read if certificate_params[:crt]
|
||||
csr = certificate_params[:csr].open.read if certificate_params[:csr]
|
||||
crt = certificate_params[:crt].open.read if certificate_params[:crt]
|
||||
csr = certificate_params[:csr].open.read if certificate_params[:csr]
|
||||
|
||||
@certificate = @api_user.certificates.build(csr: csr, crt: crt)
|
||||
if @api_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
@certificate = @api_user.certificates.build(csr: csr, crt: crt)
|
||||
if @api_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @certificate.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_api_user_path(@api_user)
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def sign
|
||||
if @certificate.sign!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def revoke
|
||||
if @certificate.revoke!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
else
|
||||
flash[:alert] = I18n.t('failed_to_update_record')
|
||||
end
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @certificate.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_api_user_path(@api_user)
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
def download_csr
|
||||
send_data @certificate.csr, filename: "#{@api_user.username}.csr.pem"
|
||||
end
|
||||
end
|
||||
|
||||
def sign
|
||||
if @certificate.sign!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'show'
|
||||
def download_crt
|
||||
send_data @certificate.crt, filename: "#{@api_user.username}.crt.pem"
|
||||
end
|
||||
end
|
||||
|
||||
def revoke
|
||||
if @certificate.revoke!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
else
|
||||
flash[:alert] = I18n.t('failed_to_update_record')
|
||||
private
|
||||
|
||||
def set_certificate
|
||||
@certificate = Certificate.find(params[:id])
|
||||
@csr = OpenSSL::X509::Request.new(@certificate.csr) if @certificate.csr
|
||||
@crt = OpenSSL::X509::Certificate.new(@certificate.crt) if @certificate.crt
|
||||
end
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
end
|
||||
|
||||
def download_csr
|
||||
send_data @certificate.csr, filename: "#{@api_user.username}.csr.pem"
|
||||
end
|
||||
def set_api_user
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
end
|
||||
|
||||
def download_crt
|
||||
send_data @certificate.crt, filename: "#{@api_user.username}.crt.pem"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_certificate
|
||||
@certificate = Certificate.find(params[:id])
|
||||
@csr = OpenSSL::X509::Request.new(@certificate.csr) if @certificate.csr
|
||||
@crt = OpenSSL::X509::Certificate.new(@certificate.crt) if @certificate.crt
|
||||
end
|
||||
|
||||
def set_api_user
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
end
|
||||
|
||||
def certificate_params
|
||||
if params[:certificate]
|
||||
params.require(:certificate).permit(:crt, :csr)
|
||||
else
|
||||
{}
|
||||
def certificate_params
|
||||
if params[:certificate]
|
||||
params.require(:certificate).permit(:crt, :csr)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,56 +1,57 @@
|
|||
class Admin::ContactVersionsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class ContactVersionsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
|
||||
@q = ContactVersion.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
search_params = params[:q].deep_dup
|
||||
@q = ContactVersion.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
search_params = params[:q].deep_dup
|
||||
|
||||
whereS = "1=1"
|
||||
whereS = "1=1"
|
||||
|
||||
search_params.each do |key, value|
|
||||
next if value.empty?
|
||||
case key
|
||||
when 'event'
|
||||
whereS += " AND event = '#{value}'"
|
||||
else
|
||||
whereS += create_where_string(key, value)
|
||||
search_params.each do |key, value|
|
||||
next if value.empty?
|
||||
case key
|
||||
when 'event'
|
||||
whereS += " AND event = '#{value}'"
|
||||
else
|
||||
whereS += create_where_string(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
versions = ContactVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
|
||||
@q = versions.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
|
||||
end
|
||||
|
||||
versions = ContactVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
|
||||
@q = versions.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
def show
|
||||
per_page = 7
|
||||
@version = ContactVersion.find(params[:id])
|
||||
@versions = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
|
||||
@versions_map = @versions.all.map(&:id)
|
||||
|
||||
end
|
||||
# what we do is calc amount of results until needed version
|
||||
# then we cacl which page it is
|
||||
if params[:page].blank?
|
||||
counter = @versions_map.index(@version.id) + 1
|
||||
page = counter / per_page
|
||||
page += 1 if (counter % per_page) != 0
|
||||
params[:page] = page
|
||||
end
|
||||
|
||||
def show
|
||||
per_page = 7
|
||||
@version = ContactVersion.find(params[:id])
|
||||
@versions = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
|
||||
@versions_map = @versions.all.map(&:id)
|
||||
|
||||
# what we do is calc amount of results until needed version
|
||||
# then we cacl which page it is
|
||||
if params[:page].blank?
|
||||
counter = @versions_map.index(@version.id) + 1
|
||||
page = counter / per_page
|
||||
page += 1 if (counter % per_page) != 0
|
||||
params[:page] = page
|
||||
@versions = @versions.page(params[:page]).per(per_page)
|
||||
end
|
||||
|
||||
@versions = @versions.page(params[:page]).per(per_page)
|
||||
end
|
||||
def search
|
||||
render json: ContactVersion.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def search
|
||||
render json: ContactVersion.search_by_query(params[:q])
|
||||
def create_where_string(key, value)
|
||||
" AND object->>'#{key}' ~* '#{value}'"
|
||||
end
|
||||
end
|
||||
|
||||
def create_where_string(key, value)
|
||||
" AND object->>'#{key}' ~* '#{value}'"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,86 +1,88 @@
|
|||
class Admin::ContactsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_contact, only: [:show]
|
||||
helper_method :ident_types
|
||||
module Admin
|
||||
class ContactsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_contact, only: [:show]
|
||||
helper_method :ident_types
|
||||
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
search_params = params[:q].deep_dup
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
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
|
||||
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
|
||||
|
||||
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name')
|
||||
contacts = contacts.filter_by_states(params[:statuses_contains].join(',')) if params[:statuses_contains]
|
||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''") if params[:only_no_country_code].eql?('1')
|
||||
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = contacts.search(search_params)
|
||||
@contacts = @q.result.uniq.page(params[:page])
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
|
||||
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name')
|
||||
contacts = contacts.filter_by_states(params[:statuses_contains].join(',')) if params[:statuses_contains]
|
||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''") if params[:only_no_country_code].eql?('1')
|
||||
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = contacts.search(search_params)
|
||||
@contacts = @q.result.uniq.page(params[:page])
|
||||
def search
|
||||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
|
||||
def search
|
||||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
cp = ignore_empty_statuses
|
||||
|
||||
if @contact.update(cp)
|
||||
flash[:notice] = I18n.t('contact_updated')
|
||||
redirect_to [:admin, @contact]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_contact')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_contact
|
||||
@contact = Contact.find(params[:id])
|
||||
end
|
||||
|
||||
def contact_params
|
||||
if params[:contact]
|
||||
params.require(:contact).permit({ statuses: [], status_notes_array: [] })
|
||||
else
|
||||
{ statuses: [] }
|
||||
end
|
||||
end
|
||||
|
||||
def ignore_empty_statuses
|
||||
dp = contact_params
|
||||
dp[:statuses].reject!(&:blank?)
|
||||
dp
|
||||
end
|
||||
|
||||
def normalize_search_parameters
|
||||
ca_cache = params[:q][:created_at_lteq]
|
||||
begin
|
||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||
# updated at
|
||||
end_time = params[:q][:updated_at_gteq].try(:to_date)
|
||||
params[:q][:updated_at_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
def edit
|
||||
end
|
||||
|
||||
yield
|
||||
def update
|
||||
cp = ignore_empty_statuses
|
||||
|
||||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
if @contact.update(cp)
|
||||
flash[:notice] = I18n.t('contact_updated')
|
||||
redirect_to [:admin, @contact]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_contact')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def ident_types
|
||||
Contact::Ident.types
|
||||
private
|
||||
|
||||
def set_contact
|
||||
@contact = Contact.find(params[:id])
|
||||
end
|
||||
|
||||
def contact_params
|
||||
if params[:contact]
|
||||
params.require(:contact).permit({ statuses: [], status_notes_array: [] })
|
||||
else
|
||||
{ statuses: [] }
|
||||
end
|
||||
end
|
||||
|
||||
def ignore_empty_statuses
|
||||
dp = contact_params
|
||||
dp[:statuses].reject!(&:blank?)
|
||||
dp
|
||||
end
|
||||
|
||||
def normalize_search_parameters
|
||||
ca_cache = params[:q][:created_at_lteq]
|
||||
begin
|
||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||
# updated at
|
||||
end_time = params[:q][:updated_at_gteq].try(:to_date)
|
||||
params[:q][:updated_at_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
end
|
||||
|
||||
yield
|
||||
|
||||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
|
||||
def ident_types
|
||||
Contact::Ident.types
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class Admin::DashboardsController < AdminController
|
||||
authorize_resource class: false
|
||||
module Admin
|
||||
class DashboardsController < BaseController
|
||||
authorize_resource class: false
|
||||
|
||||
def show
|
||||
redirect_to [:admin, :domains] if can? :show, Domain
|
||||
def show
|
||||
redirect_to [:admin, :domains] if can? :show, Domain
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class Admin::DelayedJobsController < AdminController
|
||||
authorize_resource class: false
|
||||
module Admin
|
||||
class DelayedJobsController < BaseController
|
||||
authorize_resource class: false
|
||||
|
||||
def index
|
||||
@jobs = Delayed::Job.all
|
||||
def index
|
||||
@jobs = Delayed::Job.all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Admin
|
||||
module DNS
|
||||
class ZonesController < AdminController
|
||||
class ZonesController < BaseController
|
||||
authorize_resource(class: 'DNS::Zone')
|
||||
before_action :load_zone, only: %i[edit update destroy]
|
||||
|
||||
|
|
|
@ -1,75 +1,75 @@
|
|||
class Admin::DomainVersionsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class DomainVersionsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
|
||||
@q = DomainVersion.includes(:item).search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
search_params = params[:q].deep_dup
|
||||
@q = DomainVersion.includes(:item).search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
search_params = params[:q].deep_dup
|
||||
|
||||
if search_params[:registrant].present?
|
||||
registrants = Contact.where("name ilike ?", "%#{search_params[:registrant].strip}%")
|
||||
search_params.delete(:registrant)
|
||||
end
|
||||
|
||||
if search_params[:registrar].present?
|
||||
registrars = Registrar.where("name ilike ?", "%#{search_params[:registrar].strip}%")
|
||||
search_params.delete(:registrar)
|
||||
end
|
||||
|
||||
whereS = "1=1"
|
||||
|
||||
search_params.each do |key, value|
|
||||
next if value.empty?
|
||||
case key
|
||||
when 'event'
|
||||
whereS += " AND event = '#{value}'"
|
||||
when 'name'
|
||||
whereS += " AND (object->>'name' ~* '#{value}' OR object_changes->>'name' ~* '#{value}')"
|
||||
else
|
||||
whereS += create_where_string(key, value)
|
||||
if search_params[:registrant].present?
|
||||
registrants = Contact.where("name ilike ?", "%#{search_params[:registrant].strip}%")
|
||||
search_params.delete(:registrant)
|
||||
end
|
||||
|
||||
if search_params[:registrar].present?
|
||||
registrars = Registrar.where("name ilike ?", "%#{search_params[:registrar].strip}%")
|
||||
search_params.delete(:registrar)
|
||||
end
|
||||
|
||||
whereS = "1=1"
|
||||
|
||||
search_params.each do |key, value|
|
||||
next if value.empty?
|
||||
case key
|
||||
when 'event'
|
||||
whereS += " AND event = '#{value}'"
|
||||
when 'name'
|
||||
whereS += " AND (object->>'name' ~* '#{value}' OR object_changes->>'name' ~* '#{value}')"
|
||||
else
|
||||
whereS += create_where_string(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
whereS += " AND object->>'registrant_id' IN (#{registrants.map { |r| "'#{r.id.to_s}'" }.join ','})" if registrants.present?
|
||||
whereS += " AND 1=0" if registrants == []
|
||||
whereS += " AND object->>'registrar_id' IN (#{registrars.map { |r| "'#{r.id.to_s}'" }.join ','})" if registrars.present?
|
||||
whereS += " AND 1=0" if registrars == []
|
||||
|
||||
versions = DomainVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
|
||||
@q = versions.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
render "admin/domain_versions/archive"
|
||||
|
||||
end
|
||||
|
||||
whereS += " AND object->>'registrant_id' IN (#{registrants.map { |r| "'#{r.id.to_s}'" }.join ','})" if registrants.present?
|
||||
whereS += " AND 1=0" if registrants == []
|
||||
whereS += " AND object->>'registrar_id' IN (#{registrars.map { |r| "'#{r.id.to_s}'" }.join ','})" if registrars.present?
|
||||
whereS += " AND 1=0" if registrars == []
|
||||
def show
|
||||
per_page = 7
|
||||
@version = DomainVersion.find(params[:id])
|
||||
@versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
|
||||
@versions_map = @versions.all.map(&:id)
|
||||
|
||||
versions = DomainVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
|
||||
@q = versions.search(params[:q])
|
||||
@versions = @q.result.page(params[:page])
|
||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
render "admin/domain_versions/archive"
|
||||
# what we do is calc amount of results until needed version
|
||||
# then we cacl which page it is
|
||||
if params[:page].blank?
|
||||
counter = @versions_map.index(@version.id) + 1
|
||||
page = counter / per_page
|
||||
page += 1 if (counter % per_page) != 0
|
||||
params[:page] = page
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
per_page = 7
|
||||
@version = DomainVersion.find(params[:id])
|
||||
@versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
|
||||
@versions_map = @versions.all.map(&:id)
|
||||
|
||||
# what we do is calc amount of results until needed version
|
||||
# then we cacl which page it is
|
||||
if params[:page].blank?
|
||||
counter = @versions_map.index(@version.id) + 1
|
||||
page = counter / per_page
|
||||
page += 1 if (counter % per_page) != 0
|
||||
params[:page] = page
|
||||
@versions = @versions.page(params[:page]).per(per_page)
|
||||
end
|
||||
|
||||
@versions = @versions.page(params[:page]).per(per_page)
|
||||
def search
|
||||
render json: DomainVersion.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def create_where_string(key, value)
|
||||
" AND object->>'#{key}' ~* '#{value}'"
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
render json: DomainVersion.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def create_where_string(key, value)
|
||||
" AND object->>'#{key}' ~* '#{value}'"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -1,133 +1,136 @@
|
|||
class Admin::DomainsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:show, :edit, :update, :zonefile]
|
||||
helper_method :force_delete_templates
|
||||
module Admin
|
||||
class DomainsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:show, :edit, :update, :zonefile]
|
||||
helper_method :force_delete_templates
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
if params[:statuses_contains]
|
||||
domains = Domain.includes(:registrar, :registrant).where(
|
||||
"domains.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
)
|
||||
else
|
||||
domains = Domain.includes(:registrar, :registrant)
|
||||
end
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
if params[:statuses_contains]
|
||||
domains = Domain.includes(:registrar, :registrant).where(
|
||||
"domains.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
)
|
||||
else
|
||||
domains = Domain.includes(:registrar, :registrant)
|
||||
end
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
if @domains.count == 1 && params[:q][:name_matches].present?
|
||||
redirect_to [:admin, @domains.first] and return
|
||||
elsif @domains.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
|
||||
# if we do not get any results, add wildcards to the name field and search again
|
||||
n_cache = params[:q][:name_matches]
|
||||
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
|
||||
normalize_search_parameters do
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
|
||||
if @domains.count == 1 && params[:q][:name_matches].present?
|
||||
redirect_to [:admin, @domains.first] and return
|
||||
elsif @domains.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
|
||||
# if we do not get any results, add wildcards to the name field and search again
|
||||
n_cache = params[:q][:name_matches]
|
||||
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
|
||||
end
|
||||
end
|
||||
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
|
||||
def show
|
||||
@domain.valid?
|
||||
end
|
||||
|
||||
def edit
|
||||
build_associations
|
||||
end
|
||||
|
||||
def update
|
||||
dp = ignore_empty_statuses
|
||||
@domain.is_admin = true
|
||||
@domain.admin_status_update dp[:statuses]
|
||||
|
||||
if @domain.update(dp)
|
||||
flash[:notice] = I18n.t('domain_updated')
|
||||
redirect_to [:admin, @domain]
|
||||
else
|
||||
build_associations
|
||||
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(", ")
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
def schedule_force_delete
|
||||
raise 'Template param cannot be empty' if params[:template_name].blank?
|
||||
|
||||
def show
|
||||
@domain.valid?
|
||||
end
|
||||
@domain.transaction do
|
||||
@domain.schedule_force_delete
|
||||
@domain.registrar.messages.create!(body: I18n.t('force_delete_set_on_domain', domain_name: @domain.name))
|
||||
DomainDeleteForcedEmailJob.enqueue(@domain.id, params[:template_name])
|
||||
end
|
||||
|
||||
def edit
|
||||
build_associations
|
||||
end
|
||||
|
||||
def update
|
||||
dp = ignore_empty_statuses
|
||||
@domain.is_admin = true
|
||||
@domain.admin_status_update dp[:statuses]
|
||||
|
||||
if @domain.update(dp)
|
||||
flash[:notice] = I18n.t('domain_updated')
|
||||
redirect_to [:admin, @domain]
|
||||
else
|
||||
build_associations
|
||||
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(", ")
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def schedule_force_delete
|
||||
raise 'Template param cannot be empty' if params[:template_name].blank?
|
||||
|
||||
@domain.transaction do
|
||||
@domain.schedule_force_delete
|
||||
@domain.registrar.messages.create!(body: I18n.t('force_delete_set_on_domain', domain_name: @domain.name))
|
||||
DomainDeleteForcedEmailJob.enqueue(@domain.id, params[:template_name])
|
||||
redirect_to edit_admin_domain_path(@domain), notice: t('.scheduled')
|
||||
end
|
||||
|
||||
redirect_to edit_admin_domain_path(@domain), notice: t('.scheduled')
|
||||
end
|
||||
def cancel_force_delete
|
||||
if @domain.cancel_force_delete
|
||||
flash[:notice] = t('.cancelled')
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_domain')
|
||||
end
|
||||
|
||||
def cancel_force_delete
|
||||
if @domain.cancel_force_delete
|
||||
flash[:notice] = t('.cancelled')
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_domain')
|
||||
redirect_to edit_admin_domain_path(@domain)
|
||||
end
|
||||
|
||||
redirect_to edit_admin_domain_path(@domain)
|
||||
end
|
||||
|
||||
def versions
|
||||
@domain = Domain.where(id: params[:domain_id]).includes({versions: :item}).first
|
||||
@versions = @domain.versions
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_domain
|
||||
@domain = Domain.find(params[:id])
|
||||
end
|
||||
|
||||
def domain_params
|
||||
if params[:domain]
|
||||
params.require(:domain).permit({ statuses: [], status_notes_array: [] })
|
||||
else
|
||||
{ statuses: [] }
|
||||
end
|
||||
end
|
||||
|
||||
def build_associations
|
||||
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@server_statuses = [nil] if @server_statuses.empty?
|
||||
@other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
end
|
||||
|
||||
def ignore_empty_statuses
|
||||
dp = domain_params
|
||||
dp[:statuses].reject!(&:blank?)
|
||||
dp
|
||||
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')
|
||||
def versions
|
||||
@domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first
|
||||
@versions = @domain.versions
|
||||
end
|
||||
|
||||
yield
|
||||
private
|
||||
|
||||
params[:q][:valid_to_lteq] = ca_cache
|
||||
end
|
||||
def set_domain
|
||||
@domain = Domain.find(params[:id])
|
||||
end
|
||||
|
||||
def force_delete_templates
|
||||
%w(removed_company death)
|
||||
def domain_params
|
||||
if params[:domain]
|
||||
params.require(:domain).permit({ statuses: [], status_notes_array: [] })
|
||||
else
|
||||
{ statuses: [] }
|
||||
end
|
||||
end
|
||||
|
||||
def build_associations
|
||||
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@server_statuses = [nil] if @server_statuses.empty?
|
||||
@other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
end
|
||||
|
||||
def ignore_empty_statuses
|
||||
dp = domain_params
|
||||
dp[:statuses].reject!(&:blank?)
|
||||
dp
|
||||
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
|
||||
|
||||
def force_delete_templates
|
||||
%w(removed_company death)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
class Admin::EppLogsController < AdminController
|
||||
load_and_authorize_resource class: ApiLog::EppLog
|
||||
before_action :set_default_dates, only: [:index]
|
||||
module Admin
|
||||
class EppLogsController < BaseController
|
||||
load_and_authorize_resource class: ApiLog::EppLog
|
||||
before_action :set_default_dates, only: [:index]
|
||||
|
||||
def index
|
||||
@q = ApiLog::EppLog.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
def index
|
||||
@q = ApiLog::EppLog.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
||||
@epp_logs = @q.result
|
||||
@epp_logs = @epp_logs.where("extract(epoch from created_at) >= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_gteq])) if params[:q][:created_at_gteq].present?
|
||||
@epp_logs = @epp_logs.where("extract(epoch from created_at) <= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_lteq])) if params[:q][:created_at_lteq].present?
|
||||
@epp_logs = @epp_logs.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@epp_log = ApiLog::EppLog.find(params[:id])
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
@epp_logs = @q.result
|
||||
@epp_logs = @epp_logs.where("extract(epoch from created_at) >= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_gteq])) if params[:q][:created_at_gteq].present?
|
||||
@epp_logs = @epp_logs.where("extract(epoch from created_at) <= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_lteq])) if params[:q][:created_at_lteq].present?
|
||||
@epp_logs = @epp_logs.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@epp_log = ApiLog::EppLog.find(params[:id])
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,73 +1,75 @@
|
|||
class Admin::InvoicesController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class InvoicesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_invoice, only: [:forward, :download_pdf]
|
||||
before_action :set_invoice, only: [:forward, :download_pdf]
|
||||
|
||||
def new
|
||||
@deposit = Deposit.new
|
||||
end
|
||||
|
||||
def create
|
||||
r = Registrar.find_by(id: deposit_params[:registrar_id])
|
||||
@deposit = Deposit.new(deposit_params.merge(registrar: r))
|
||||
@invoice = @deposit.issue_prepayment_invoice
|
||||
|
||||
if @invoice && @invoice.persisted?
|
||||
flash[:notice] = t(:record_created)
|
||||
redirect_to [:admin, @invoice]
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_create_record)
|
||||
render 'new'
|
||||
def new
|
||||
@deposit = Deposit.new
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@q = Invoice.includes(:account_activity).search(params[:q])
|
||||
@q.sorts = 'number desc' if @q.sorts.empty?
|
||||
@invoices = @q.result.page(params[:page])
|
||||
end
|
||||
def create
|
||||
r = Registrar.find_by(id: deposit_params[:registrar_id])
|
||||
@deposit = Deposit.new(deposit_params.merge(registrar: r))
|
||||
@invoice = @deposit.issue_prepayment_invoice
|
||||
|
||||
def show
|
||||
@invoice = Invoice.find(params[:id])
|
||||
end
|
||||
|
||||
def cancel
|
||||
if @invoice.cancel
|
||||
flash[:notice] = t(:record_updated)
|
||||
redirect_to([:admin, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_update_record)
|
||||
render :show
|
||||
if @invoice && @invoice.persisted?
|
||||
flash[:notice] = t(:record_created)
|
||||
redirect_to [:admin, @invoice]
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_create_record)
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def forward
|
||||
@invoice.billing_email = @invoice.buyer.billing_email
|
||||
|
||||
return unless request.post?
|
||||
|
||||
@invoice.billing_email = params[:invoice][:billing_email]
|
||||
|
||||
if @invoice.forward(render_to_string('registrar/invoices/pdf', layout: false))
|
||||
flash[:notice] = t(:invoice_forwared)
|
||||
redirect_to([:admin, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_forward_invoice)
|
||||
def index
|
||||
@q = Invoice.includes(:account_activity).search(params[:q])
|
||||
@q.sorts = 'number desc' if @q.sorts.empty?
|
||||
@invoices = @q.result.page(params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
pdf = @invoice.pdf(render_to_string('registrar/invoices/pdf', layout: false))
|
||||
send_data pdf, filename: @invoice.pdf_name
|
||||
end
|
||||
def show
|
||||
@invoice = Invoice.find(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
def cancel
|
||||
if @invoice.cancel
|
||||
flash[:notice] = t(:record_updated)
|
||||
redirect_to([:admin, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_update_record)
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
def deposit_params
|
||||
params.require(:deposit).permit(:amount, :description, :registrar_id)
|
||||
end
|
||||
def forward
|
||||
@invoice.billing_email = @invoice.buyer.billing_email
|
||||
|
||||
def set_invoice
|
||||
@invoice = Invoice.find(params[:invoice_id])
|
||||
return unless request.post?
|
||||
|
||||
@invoice.billing_email = params[:invoice][:billing_email]
|
||||
|
||||
if @invoice.forward(render_to_string('registrar/invoices/pdf', layout: false))
|
||||
flash[:notice] = t(:invoice_forwared)
|
||||
redirect_to([:admin, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t(:failed_to_forward_invoice)
|
||||
end
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
pdf = @invoice.pdf(render_to_string('registrar/invoices/pdf', layout: false))
|
||||
send_data pdf, filename: @invoice.pdf_name
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def deposit_params
|
||||
params.require(:deposit).permit(:amount, :description, :registrar_id)
|
||||
end
|
||||
|
||||
def set_invoice
|
||||
@invoice = Invoice.find(params[:invoice_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
class Admin::KeyrelaysController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class KeyrelaysController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@q = Keyrelay.includes(:requester, :accepter).search(params[:q])
|
||||
@keyrelays = @q.result.page(params[:page])
|
||||
def index
|
||||
@q = Keyrelay.includes(:requester, :accepter).search(params[:q])
|
||||
@keyrelays = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def show;
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
class Admin::LegalDocumentsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class LegalDocumentsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def show
|
||||
@ld = LegalDocument.find(params[:id])
|
||||
filename = @ld.path.split('/').last
|
||||
send_data File.open(@ld.path).read, filename: filename
|
||||
def show
|
||||
@ld = LegalDocument.find(params[:id])
|
||||
filename = @ld.path.split('/').last
|
||||
send_data File.open(@ld.path).read, filename: filename
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,61 +1,63 @@
|
|||
class Admin::MailTemplatesController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class MailTemplatesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@q = MailTemplate.search(params[:q])
|
||||
@mail_templates = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@mail_tempalte = MailTemplate.new
|
||||
end
|
||||
|
||||
def show
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
@subject = Liquid::Template.parse(@mail_template.subject).render.html_safe
|
||||
@html_body = Liquid::Template.parse(@mail_template.body).render.html_safe
|
||||
@text_body = Liquid::Template.parse(@mail_template.text_body).render.html_safe
|
||||
end
|
||||
|
||||
def edit
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@mail_template = MailTemplate.new(mail_template_params)
|
||||
|
||||
if @mail_template.save
|
||||
redirect_to [:admin, @mail_template]
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'new'
|
||||
def index
|
||||
@q = MailTemplate.search(params[:q])
|
||||
@mail_templates = @q.result.page(params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
|
||||
if @mail_template.update_attributes(mail_template_params)
|
||||
redirect_to [:admin, @mail_template]
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'edit'
|
||||
def new
|
||||
@mail_tempalte = MailTemplate.new
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
if @mail_template.destroy
|
||||
redirect_to admin_mail_templates_path, notise: t(:deleted)
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'show'
|
||||
def show
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
@subject = Liquid::Template.parse(@mail_template.subject).render.html_safe
|
||||
@html_body = Liquid::Template.parse(@mail_template.body).render.html_safe
|
||||
@text_body = Liquid::Template.parse(@mail_template.text_body).render.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def edit
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
end
|
||||
|
||||
def mail_template_params
|
||||
params.require(:mail_template).permit(:name, :subject, :from, :bcc, :cc, :body, :text_body)
|
||||
def create
|
||||
@mail_template = MailTemplate.new(mail_template_params)
|
||||
|
||||
if @mail_template.save
|
||||
redirect_to [:admin, @mail_template]
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
|
||||
if @mail_template.update_attributes(mail_template_params)
|
||||
redirect_to [:admin, @mail_template]
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@mail_template = MailTemplate.find(params[:id])
|
||||
if @mail_template.destroy
|
||||
redirect_to admin_mail_templates_path, notise: t(:deleted)
|
||||
else
|
||||
flash.now[:alert] = I18n.t(:failure)
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mail_template_params
|
||||
params.require(:mail_template).permit(:name, :subject, :from, :bcc, :cc, :body, :text_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,42 +1,44 @@
|
|||
class Admin::PendingDeletesController < AdminController
|
||||
before_action :find_domain
|
||||
before_action :check_status
|
||||
module Admin
|
||||
class PendingDeletesController < BaseController
|
||||
before_action :find_domain
|
||||
before_action :check_status
|
||||
|
||||
def update
|
||||
authorize! :update, :pending
|
||||
def update
|
||||
authorize! :update, :pending
|
||||
|
||||
if registrant_verification.domain_registrant_delete_confirm!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
if registrant_verification.domain_registrant_delete_confirm!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :destroy, :pending
|
||||
def destroy
|
||||
authorize! :destroy, :pending
|
||||
|
||||
if registrant_verification.domain_registrant_delete_reject!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
if registrant_verification.domain_registrant_delete_reject!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
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 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
|
||||
def find_domain
|
||||
@domain = Domain.find(params[:domain_id])
|
||||
end
|
||||
|
||||
def check_status
|
||||
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_delete?
|
||||
def check_status
|
||||
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_delete?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,41 +1,43 @@
|
|||
class Admin::PendingUpdatesController < AdminController
|
||||
before_action :find_domain
|
||||
before_action :check_status
|
||||
module Admin
|
||||
class PendingUpdatesController < BaseController
|
||||
before_action :find_domain
|
||||
before_action :check_status
|
||||
|
||||
def update
|
||||
authorize! :update, :pending
|
||||
def update
|
||||
authorize! :update, :pending
|
||||
|
||||
if registrant_verification.domain_registrant_change_confirm!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
|
||||
else
|
||||
redirect_to edit_admin_domain_path(@domain.id), alert: t(:failure)
|
||||
if registrant_verification.domain_registrant_change_confirm!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied)
|
||||
else
|
||||
redirect_to edit_admin_domain_path(@domain.id), alert: t(:failure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :destroy, :pending
|
||||
if registrant_verification.domain_registrant_change_reject!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
def destroy
|
||||
authorize! :destroy, :pending
|
||||
if registrant_verification.domain_registrant_change_reject!("admin #{current_user.username}")
|
||||
redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed)
|
||||
else
|
||||
redirect_to admin_domain_path(@domain.id), alert: t(:failure)
|
||||
end
|
||||
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
|
||||
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
|
||||
private
|
||||
|
||||
def find_domain
|
||||
@domain = Domain.find(params[:domain_id])
|
||||
end
|
||||
def find_domain
|
||||
@domain = Domain.find(params[:domain_id])
|
||||
end
|
||||
|
||||
def check_status
|
||||
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_update?
|
||||
def check_status
|
||||
return redirect_to admin_domain_path(@domain.id), alert: t(:something_wrong) unless @domain.pending_update?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,68 +1,72 @@
|
|||
class Admin::RegistrarsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
|
||||
def search
|
||||
render json: Registrar.search_by_query(params[:q])
|
||||
end
|
||||
module Admin
|
||||
class RegistrarsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@q = Registrar.joins(:accounts).ordered.search(params[:q])
|
||||
@registrars = @q.result.page(params[:page])
|
||||
end
|
||||
def search
|
||||
render json: Registrar.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def new
|
||||
@registrar = Registrar.new
|
||||
end
|
||||
def index
|
||||
@q = Registrar.joins(:accounts).ordered.search(params[:q])
|
||||
@registrars = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def create
|
||||
@registrar = Registrar.new(registrar_params)
|
||||
def new
|
||||
@registrar = Registrar.new
|
||||
end
|
||||
|
||||
begin
|
||||
@registrar.transaction do
|
||||
@registrar.save!
|
||||
@registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR')
|
||||
def create
|
||||
@registrar = Registrar.new(registrar_params)
|
||||
|
||||
begin
|
||||
@registrar.transaction do
|
||||
@registrar.save!
|
||||
@registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR')
|
||||
end
|
||||
|
||||
flash[:notice] = t('.created')
|
||||
redirect_to [:admin, @registrar]
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
flash.now[:alert] = t('.not_created')
|
||||
render 'new'
|
||||
end
|
||||
|
||||
flash[:notice] = t('.created')
|
||||
redirect_to [:admin, @registrar]
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
flash.now[:alert] = t('.not_created')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @registrar.update(registrar_params)
|
||||
flash[:notice] = t('.updated')
|
||||
redirect_to [:admin, @registrar]
|
||||
else
|
||||
flash.now[:alert] = t('.not_updated')
|
||||
render 'edit'
|
||||
def edit;
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @registrar.destroy
|
||||
flash[:notice] = I18n.t('registrar_deleted')
|
||||
redirect_to admin_registrars_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_registrar')
|
||||
render 'show'
|
||||
def update
|
||||
if @registrar.update(registrar_params)
|
||||
flash[:notice] = t('.updated')
|
||||
redirect_to [:admin, @registrar]
|
||||
else
|
||||
flash.now[:alert] = t('.not_updated')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def destroy
|
||||
if @registrar.destroy
|
||||
flash[:notice] = I18n.t('registrar_deleted')
|
||||
redirect_to admin_registrars_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_registrar')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def set_registrar
|
||||
@registrar = Registrar.find(params[:id])
|
||||
end
|
||||
private
|
||||
|
||||
def registrar_params
|
||||
params.require(:registrar).permit(
|
||||
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address,
|
||||
:country_code, :email, :phone, :website, :billing_email, :code, :test_registrar
|
||||
)
|
||||
def set_registrar
|
||||
@registrar = Registrar.find(params[:id])
|
||||
end
|
||||
|
||||
def registrar_params
|
||||
params.require(:registrar).permit(
|
||||
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address,
|
||||
:country_code, :email, :phone, :website, :billing_email, :code, :test_registrar
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +1,36 @@
|
|||
class Admin::ReppLogsController < AdminController
|
||||
load_and_authorize_resource class: ApiLog::ReppLog
|
||||
before_action :set_default_dates, only: [:index]
|
||||
module Admin
|
||||
class ReppLogsController < BaseController
|
||||
load_and_authorize_resource class: ApiLog::ReppLog
|
||||
before_action :set_default_dates, only: [:index]
|
||||
|
||||
def index
|
||||
@q = ApiLog::ReppLog.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
def index
|
||||
@q = ApiLog::ReppLog.search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
||||
@repp_logs = @q.result
|
||||
@repp_logs = @repp_logs.where("extract(epoch from created_at) >= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_gteq])) if params[:q][:created_at_gteq].present?
|
||||
@repp_logs = @repp_logs.where("extract(epoch from created_at) <= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_lteq])) if params[:q][:created_at_lteq].present?
|
||||
@repp_logs = @repp_logs.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@repp_log = ApiLog::ReppLog.find(params[:id])
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
@repp_logs = @q.result
|
||||
@repp_logs = @repp_logs.where("extract(epoch from created_at) >= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_gteq])) if params[:q][:created_at_gteq].present?
|
||||
@repp_logs = @repp_logs.where("extract(epoch from created_at) <= extract(epoch from ?::timestamp)", Time.parse(params[:q][:created_at_lteq])) if params[:q][:created_at_lteq].present?
|
||||
@repp_logs = @repp_logs.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@repp_log = ApiLog::ReppLog.find(params[:id])
|
||||
end
|
||||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
|
||||
default_date = params[:created_after]
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,68 +1,70 @@
|
|||
class Admin::ReservedDomainsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:edit, :update]
|
||||
module Admin
|
||||
class ReservedDomainsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
def index
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
@domain = ReservedDomain.new(reserved_domain_params)
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('domain_added')
|
||||
redirect_to admin_reserved_domains_path
|
||||
else
|
||||
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
|
||||
def new
|
||||
@domain = ReservedDomain.new
|
||||
end
|
||||
|
||||
end
|
||||
def edit
|
||||
end
|
||||
|
||||
private
|
||||
def create
|
||||
|
||||
def reserved_domain_params
|
||||
params.require(:reserved_domain).permit(:name, :password)
|
||||
end
|
||||
@domain = ReservedDomain.new(reserved_domain_params)
|
||||
|
||||
def set_domain
|
||||
@domain = ReservedDomain.find(params[:id])
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('domain_added')
|
||||
redirect_to admin_reserved_domains_path
|
||||
else
|
||||
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
|
||||
end
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
class Admin::SessionsController < Devise::SessionsController
|
||||
skip_authorization_check only: :create
|
||||
module Admin
|
||||
class SessionsController < Devise::SessionsController
|
||||
skip_authorization_check only: :create
|
||||
|
||||
def login
|
||||
@admin_user = AdminUser.new
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:admin_user].blank?
|
||||
def login
|
||||
@admin_user = AdminUser.new
|
||||
flash[:alert] = 'Something went wrong'
|
||||
return render 'login'
|
||||
end
|
||||
|
||||
@admin_user = AdminUser.find_by(username: params[:admin_user][:username])
|
||||
@admin_user ||= AdminUser.new(username: params[:admin_user][:username])
|
||||
def create
|
||||
if params[:admin_user].blank?
|
||||
@admin_user = AdminUser.new
|
||||
flash[:alert] = 'Something went wrong'
|
||||
return render 'login'
|
||||
end
|
||||
|
||||
if @admin_user.valid_password?(params[:admin_user][:password])
|
||||
sign_in @admin_user, event: :authentication
|
||||
redirect_to admin_root_url, notice: I18n.t(:welcome)
|
||||
else
|
||||
flash[:alert] = 'Authorization error'
|
||||
render 'login'
|
||||
@admin_user = AdminUser.find_by(username: params[:admin_user][:username])
|
||||
@admin_user ||= AdminUser.new(username: params[:admin_user][:username])
|
||||
|
||||
if @admin_user.valid_password?(params[:admin_user][:password])
|
||||
sign_in @admin_user, event: :authentication
|
||||
redirect_to admin_root_url, notice: I18n.t(:welcome)
|
||||
else
|
||||
flash[:alert] = 'Authorization error'
|
||||
render 'login'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,95 +1,98 @@
|
|||
class Admin::SettingsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_setting_group, only: [:show, :update]
|
||||
module Admin
|
||||
class SettingsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_setting_group, only: [:show, :update]
|
||||
|
||||
def index
|
||||
@settings = Setting.unscoped
|
||||
end
|
||||
def index
|
||||
@settings = Setting.unscoped
|
||||
end
|
||||
|
||||
def create
|
||||
@errors = Setting.params_errors(casted_settings)
|
||||
if @errors.empty?
|
||||
casted_settings.each do |k, v|
|
||||
Setting[k] = v
|
||||
def create
|
||||
@errors = Setting.params_errors(casted_settings)
|
||||
if @errors.empty?
|
||||
casted_settings.each do |k, v|
|
||||
Setting[k] = v
|
||||
end
|
||||
|
||||
flash[:notice] = I18n.t('records_updated')
|
||||
redirect_to [:admin, :settings]
|
||||
else
|
||||
flash[:alert] = @errors.values.uniq.join(", ")
|
||||
render "admin/settings/index"
|
||||
end
|
||||
end
|
||||
|
||||
def show;
|
||||
end
|
||||
|
||||
def update
|
||||
if @setting_group.update(setting_group_params)
|
||||
flash[:notice] = I18n.t('setting_updated')
|
||||
redirect_to [:admin, @setting_group]
|
||||
else
|
||||
flash[:alert] = I18n.t('failed_to_update_setting')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_setting_group
|
||||
@setting_group = SettingGroup.find(params[:id])
|
||||
end
|
||||
|
||||
def setting_group_params
|
||||
params.require(:setting_group).permit(settings_attributes: [:value, :id])
|
||||
end
|
||||
|
||||
def casted_settings # rubocop:disable Metrics/MethodLength
|
||||
settings = {}
|
||||
|
||||
ints = [
|
||||
:admin_contacts_min_count,
|
||||
:admin_contacts_max_count,
|
||||
:tech_contacts_min_count,
|
||||
:tech_contacts_max_count,
|
||||
:orphans_contacts_in_months,
|
||||
:ds_digest_type,
|
||||
:dnskeys_min_count,
|
||||
:dnskeys_max_count,
|
||||
:ns_min_count,
|
||||
:ns_max_count,
|
||||
:transfer_wait_time,
|
||||
:invoice_number_min,
|
||||
:invoice_number_max,
|
||||
:days_to_keep_business_registry_cache,
|
||||
:days_to_keep_invoices_active,
|
||||
:days_to_keep_overdue_invoices_active,
|
||||
:days_to_renew_domain_before_expire,
|
||||
:expire_warning_period,
|
||||
:redemption_grace_period,
|
||||
:expire_pending_confirmation
|
||||
]
|
||||
|
||||
floats = [:registry_vat_prc, :minimum_deposit]
|
||||
|
||||
booleans = [
|
||||
:ds_data_allowed,
|
||||
:key_data_allowed,
|
||||
:client_side_status_editing_enabled,
|
||||
:registrar_ip_whitelist_enabled,
|
||||
:api_ip_whitelist_enabled,
|
||||
:request_confrimation_on_registrant_change_enabled,
|
||||
:request_confirmation_on_domain_deletion_enabled,
|
||||
:nameserver_required,
|
||||
:address_processing
|
||||
]
|
||||
|
||||
params[:settings].each do |k, v|
|
||||
settings[k] = v
|
||||
settings[k] = v.to_i if ints.include?(k.to_sym)
|
||||
settings[k] = v.to_f if floats.include?(k.to_sym)
|
||||
settings[k] = (v == 'true' ? true : false) if booleans.include?(k.to_sym)
|
||||
end
|
||||
|
||||
flash[:notice] = I18n.t('records_updated')
|
||||
redirect_to [:admin, :settings]
|
||||
else
|
||||
flash[:alert] = @errors.values.uniq.join(", ")
|
||||
render "admin/settings/index"
|
||||
settings
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
if @setting_group.update(setting_group_params)
|
||||
flash[:notice] = I18n.t('setting_updated')
|
||||
redirect_to [:admin, @setting_group]
|
||||
else
|
||||
flash[:alert] = I18n.t('failed_to_update_setting')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_setting_group
|
||||
@setting_group = SettingGroup.find(params[:id])
|
||||
end
|
||||
|
||||
def setting_group_params
|
||||
params.require(:setting_group).permit(settings_attributes: [:value, :id])
|
||||
end
|
||||
|
||||
def casted_settings # rubocop:disable Metrics/MethodLength
|
||||
settings = {}
|
||||
|
||||
ints = [
|
||||
:admin_contacts_min_count,
|
||||
:admin_contacts_max_count,
|
||||
:tech_contacts_min_count,
|
||||
:tech_contacts_max_count,
|
||||
:orphans_contacts_in_months,
|
||||
:ds_digest_type,
|
||||
:dnskeys_min_count,
|
||||
:dnskeys_max_count,
|
||||
:ns_min_count,
|
||||
:ns_max_count,
|
||||
:transfer_wait_time,
|
||||
:invoice_number_min,
|
||||
:invoice_number_max,
|
||||
:days_to_keep_business_registry_cache,
|
||||
:days_to_keep_invoices_active,
|
||||
:days_to_keep_overdue_invoices_active,
|
||||
:days_to_renew_domain_before_expire,
|
||||
:expire_warning_period,
|
||||
:redemption_grace_period,
|
||||
:expire_pending_confirmation
|
||||
]
|
||||
|
||||
floats = [:registry_vat_prc, :minimum_deposit]
|
||||
|
||||
booleans = [
|
||||
:ds_data_allowed,
|
||||
:key_data_allowed,
|
||||
:client_side_status_editing_enabled,
|
||||
:registrar_ip_whitelist_enabled,
|
||||
:api_ip_whitelist_enabled,
|
||||
:request_confrimation_on_registrant_change_enabled,
|
||||
:request_confirmation_on_domain_deletion_enabled,
|
||||
:nameserver_required,
|
||||
:address_processing
|
||||
]
|
||||
|
||||
params[:settings].each do |k, v|
|
||||
settings[k] = v
|
||||
settings[k] = v.to_i if ints.include?(k.to_sym)
|
||||
settings[k] = v.to_f if floats.include?(k.to_sym)
|
||||
settings[k] = (v == 'true' ? true : false) if booleans.include?(k.to_sym)
|
||||
end
|
||||
|
||||
settings
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,56 +1,60 @@
|
|||
class Admin::WhiteIpsController < AdminController
|
||||
load_and_authorize_resource
|
||||
module Admin
|
||||
class WhiteIpsController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_registrar, only: [:new, :show, :edit, :destroy, :update]
|
||||
before_action :set_registrar, only: [:new, :show, :edit, :destroy, :update]
|
||||
|
||||
def new
|
||||
@white_ip = WhiteIp.new(registrar: @registrar)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def destroy
|
||||
if @white_ip.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_registrar_path(@registrar)
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
def new
|
||||
@white_ip = WhiteIp.new(registrar: @registrar)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@white_ip = WhiteIp.new(white_ip_params)
|
||||
@registrar = @white_ip.registrar
|
||||
|
||||
if @white_ip.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
def show;
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @white_ip.update(white_ip_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
def edit;
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def destroy
|
||||
if @white_ip.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_registrar_path(@registrar)
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def set_registrar
|
||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||
end
|
||||
def create
|
||||
@white_ip = WhiteIp.new(white_ip_params)
|
||||
@registrar = @white_ip.registrar
|
||||
|
||||
def white_ip_params
|
||||
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] })
|
||||
if @white_ip.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @white_ip.update(white_ip_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_registrar
|
||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||
end
|
||||
|
||||
def white_ip_params
|
||||
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
class Admin::ZonefilesController < ApplicationController
|
||||
authorize_resource class: false
|
||||
# TODO: Refactor this
|
||||
module Admin
|
||||
class ZonefilesController < BaseController
|
||||
authorize_resource class: false
|
||||
# TODO: Refactor this
|
||||
|
||||
def create
|
||||
if DNS::Zone.origins.include?(params[:origin])
|
||||
def create
|
||||
if DNS::Zone.origins.include?(params[:origin])
|
||||
|
||||
@zonefile = ActiveRecord::Base.connection.execute(
|
||||
"select generate_zonefile('#{params[:origin]}')"
|
||||
)[0]['generate_zonefile']
|
||||
@zonefile = ActiveRecord::Base.connection.execute(
|
||||
"select generate_zonefile('#{params[:origin]}')"
|
||||
)[0]['generate_zonefile']
|
||||
|
||||
send_data @zonefile, filename: "#{params[:origin]}.txt"
|
||||
else
|
||||
flash[:alert] = 'Origin not supported'
|
||||
redirect_to :back
|
||||
send_data @zonefile, filename: "#{params[:origin]}.txt"
|
||||
else
|
||||
flash[:alert] = 'Origin not supported'
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
class AdminController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
helper_method :head_title_sufix
|
||||
def head_title_sufix
|
||||
t(:admin_head_title_sufix)
|
||||
end
|
||||
end
|
|
@ -1,16 +1,17 @@
|
|||
en:
|
||||
admin:
|
||||
menu:
|
||||
users: Users
|
||||
api_users: API users
|
||||
admin_users: Admin users
|
||||
prices: Prices
|
||||
archive: Archive
|
||||
domain_history: Domain history
|
||||
contact_history: Contact history
|
||||
zones: Zones
|
||||
blocked_domains: Blocked domains
|
||||
reserved_domains: Reserved domains
|
||||
epp_log: EPP log
|
||||
repp_log: REPP log
|
||||
que: Que
|
||||
base:
|
||||
menu:
|
||||
users: Users
|
||||
api_users: API users
|
||||
admin_users: Admin users
|
||||
prices: Prices
|
||||
archive: Archive
|
||||
domain_history: Domain history
|
||||
contact_history: Contact history
|
||||
zones: Zones
|
||||
blocked_domains: Blocked domains
|
||||
reserved_domains: Reserved domains
|
||||
epp_log: EPP log
|
||||
repp_log: REPP log
|
||||
que: Que
|
||||
|
|
|
@ -52,11 +52,6 @@
|
|||
<ellipse fill="none" stroke="black" cx="532" cy="-462" rx="87.9851" ry="18"/>
|
||||
<text text-anchor="middle" x="532" y="-458.3" font-family="Times,serif" font-size="14.00">Epp::ErrorsController</text>
|
||||
</g>
|
||||
<!-- AdminController -->
|
||||
<g id="node9" class="node"><title>AdminController</title>
|
||||
<ellipse fill="none" stroke="black" cx="-361" cy="66" rx="71.4873" ry="18"/>
|
||||
<text text-anchor="middle" x="-361" y="69.7" font-family="Times,serif" font-size="14.00">AdminController</text>
|
||||
</g>
|
||||
<!-- RegistrarController -->
|
||||
<g id="node10" class="node"><title>RegistrarController</title>
|
||||
<ellipse fill="none" stroke="black" cx="-173" cy="-462" rx="79.0865" ry="18"/>
|
||||
|
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
@ -131,16 +131,6 @@
|
|||
<polyline fill="none" stroke="black" points="740.5,56 875.5,56 "/>
|
||||
<text text-anchor="start" x="748.5" y="71.2" font-family="Times,serif" font-size="14.00">_layout</text>
|
||||
</g>
|
||||
<!-- AdminController -->
|
||||
<g id="node9" class="node"><title>AdminController</title>
|
||||
<path fill="none" stroke="black" d="M152,239.5C152,239.5 238,239.5 238,239.5 244,239.5 250,233.5 250,227.5 250,227.5 250,158.5 250,158.5 250,152.5 244,146.5 238,146.5 238,146.5 152,146.5 152,146.5 146,146.5 140,152.5 140,158.5 140,158.5 140,227.5 140,227.5 140,233.5 146,239.5 152,239.5"/>
|
||||
<text text-anchor="middle" x="195" y="161.7" font-family="Times,serif" font-size="14.00">AdminController</text>
|
||||
<polyline fill="none" stroke="black" points="140,169.5 250,169.5 "/>
|
||||
<text text-anchor="start" x="148" y="184.7" font-family="Times,serif" font-size="14.00">head_title_sufix</text>
|
||||
<polyline fill="none" stroke="black" points="140,192.5 250,192.5 "/>
|
||||
<polyline fill="none" stroke="black" points="140,216.5 250,216.5 "/>
|
||||
<text text-anchor="start" x="148" y="231.7" font-family="Times,serif" font-size="14.00">_layout</text>
|
||||
</g>
|
||||
<!-- RegistrarController -->
|
||||
<g id="node10" class="node"><title>RegistrarController</title>
|
||||
<path fill="none" stroke="black" d="M-708,539.5C-708,539.5 -610,539.5 -610,539.5 -604,539.5 -598,533.5 -598,527.5 -598,527.5 -598,428.5 -598,428.5 -598,422.5 -604,416.5 -610,416.5 -610,416.5 -708,416.5 -708,416.5 -714,416.5 -720,422.5 -720,428.5 -720,428.5 -720,527.5 -720,527.5 -720,533.5 -714,539.5 -708,539.5"/>
|
||||
|
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 68 KiB |
|
@ -17,7 +17,7 @@ RSpec.feature 'New price in admin area', settings: false do
|
|||
end
|
||||
|
||||
def open_list
|
||||
click_link_or_button t('admin.menu.prices')
|
||||
click_link_or_button t('admin.base.menu.prices')
|
||||
end
|
||||
|
||||
def open_form
|
||||
|
|
|
@ -16,7 +16,7 @@ RSpec.feature 'Editing zone in admin area', settings: false do
|
|||
end
|
||||
|
||||
def open_list
|
||||
click_link_or_button t('admin.menu.zones')
|
||||
click_link_or_button t('admin.base.menu.zones')
|
||||
end
|
||||
|
||||
def open_form
|
||||
|
|
|
@ -15,7 +15,7 @@ RSpec.feature 'New zone in admin area', settings: false do
|
|||
end
|
||||
|
||||
def open_list
|
||||
click_link_or_button t('admin.menu.zones')
|
||||
click_link_or_button t('admin.base.menu.zones')
|
||||
end
|
||||
|
||||
def open_form
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue