mirror of
https://github.com/internetee/registry.git
synced 2025-07-13 14:35:05 +02:00
Merge branch '111396946-blocked_and_reserved_view' into staging
This commit is contained in:
commit
3178c13fd4
14 changed files with 208 additions and 54 deletions
|
@ -2,46 +2,54 @@ class Admin::BlockedDomainsController < AdminController
|
|||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
bd = BlockedDomain.pluck(:name)
|
||||
if bd
|
||||
@blocked_domains = bd.to_yaml.gsub("---\n", '').gsub("-", '').gsub(" ", '')
|
||||
end
|
||||
|
||||
params[:q] ||= {}
|
||||
domains = BlockedDomain.all
|
||||
@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
|
||||
@blocked_domains = params[:blocked_domains]
|
||||
|
||||
begin
|
||||
params[:blocked_domains] = "---\n" if params[:blocked_domains].blank?
|
||||
names = YAML.load(params[:blocked_domains])
|
||||
fail if names == false
|
||||
rescue
|
||||
flash.now[:alert] = I18n.t('invalid_yaml')
|
||||
logger.warn 'Invalid YAML'
|
||||
render :index and return
|
||||
end
|
||||
@domain = BlockedDomain.new(blocked_domain_params)
|
||||
|
||||
names = names.split(' ')
|
||||
result = true
|
||||
BlockedDomain.transaction do
|
||||
existing = BlockedDomain.any_of_domains(names).pluck(:id)
|
||||
BlockedDomain.where.not(id: existing).destroy_all
|
||||
|
||||
names.each do |name|
|
||||
rec = BlockedDomain.find_or_initialize_by(name: name)
|
||||
unless rec.save
|
||||
result = false
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if result
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to :back
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('domain_added')
|
||||
redirect_to admin_blocked_domains_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render :index
|
||||
flash.now[:alert] = I18n.t('failed_to_add_domain')
|
||||
render 'new'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def delete
|
||||
|
||||
if BlockedDomain.find(params[:id]).destroy
|
||||
flash[:notice] = I18n.t('domain_deleted')
|
||||
redirect_to admin_blocked_domains_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_domain')
|
||||
redirect_to admin_blocked_domains_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def blocked_domain_params
|
||||
params.require(:blocked_domain).permit(:name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_domain
|
||||
@domain = BlockedDomain.find(params[:id])
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
class Admin::ReservedDomainsController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
|
||||
|
@ -16,10 +17,52 @@ class Admin::ReservedDomainsController < AdminController
|
|||
end
|
||||
|
||||
def edit
|
||||
authorize! :update, ReservedDomain
|
||||
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
|
||||
authorize! :delete, ReservedDomain
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue