111396946-methods

This commit is contained in:
Stas 2016-01-20 15:44:55 +02:00
parent b111285334
commit 793bc359ea
2 changed files with 5 additions and 63 deletions

View file

@ -16,66 +16,10 @@ class Admin::ReservedDomainsController < AdminController
end
def edit
authorize! :update, Depp::Domain
@data = @domain.info(params[:domain_name])
@domain_params = Depp::Domain.construct_params_from_server_data(@data)
end
def update
authorize! :update, Depp::Domain
@domain_params = params[:domain]
@data = @domain.update(@domain_params)
if response_ok?
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
else
params[:domain_name] = @domain_params[:name]
render 'new'
end
authorize! :update, ReservedDomain
end
def delete
authorize! :delete, Depp::Domain
end
def create
@reserved_domains = params[:reserved_domains]
begin
params[:reserved_domains] = "---\n" if params[:reserved_domains].blank?
names = YAML.load(params[:reserved_domains])
fail if names == false
rescue
flash.now[:alert] = I18n.t('invalid_yaml')
logger.warn 'Invalid YAML'
render :index and return
end
result = true
ReservedDomain.transaction do
# removing old ones
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
ReservedDomain.where.not(id: existing).destroy_all
#updating and adding
names.each do |name, psw|
rec = ReservedDomain.find_or_initialize_by(name: name)
rec.password = psw
unless rec.save
result = false
raise ActiveRecord::Rollback
end
end
end
if result
flash[:notice] = I18n.t('record_updated')
redirect_to :back
else
flash.now[:alert] = I18n.t('failed_to_update_record')
render :index
end
authorize! :delete, ReservedDomain
end
end

View file

@ -55,12 +55,10 @@
%td= l(x.created_at, format: :short)
%td= l(x.updated_at, format: :short)
%td
= link_to(t(:edit), edit_admin_reserved_domains_path(name: x.name),
= link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id),
class: 'btn btn-primary btn-xs')
= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id),
class: 'btn btn-primary btn-xs')
= link_to(t(:renew), renew_admin_reserved_domains_path(name: x.name),
class: 'btn btn-default btn-xs')
= link_to(t(:delete), delete_admin_reserved_domains_path(name: x.name),
class: 'btn btn-default btn-xs')
.row
.col-md-6
= paginate @domains