Refactor zones

- Rename "zonefile_setting" to "zone"
- Remove version

#475
This commit is contained in:
Artur Beljajev 2017-04-20 17:20:36 +03:00
parent f1d7e53734
commit bff7437277
51 changed files with 425 additions and 389 deletions

View file

@ -0,0 +1,64 @@
module Admin
module DNS
class ZonesController < AdminController
#load_and_authorize_resource(class: DNS::Zone)
skip_authorization_check
before_action :load_zone, only: %i[edit update destroy]
def index
@zones = ::DNS::Zone.all
end
def new
@zone = ::DNS::Zone.new
end
def create
@zone = ::DNS::Zone.new(zone_params)
if @zone.save
flash[:notice] = t('.created')
redirect_to_index
else
render :new
end
end
def edit
@zone = ::DNS::Zone.find(params[:id])
end
def update
if @zone.update(zone_params)
flash[:notice] = t('.updated')
redirect_to_index
else
render :edit
end
end
def destroy
@zone.destroy!
flash[:notice] = t('.destroyed')
redirect_to_index
end
private
def load_zone
@zone = ::DNS::Zone.find(params[:id])
end
def zone_params
params.require(:zone).permit(
:origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email,
:master_nameserver, :ns_records, :a_records, :a4_records
)
end
def redirect_to_index
redirect_to admin_zones_url
end
end
end
end

View file

@ -1,60 +0,0 @@
class Admin::ZonefileSettingsController < AdminController
load_and_authorize_resource
before_action :set_zonefile_setting, only: [:update, :edit]
def index
@zonefile_settings = ZonefileSetting.all
end
def new
@zonefile_setting = ZonefileSetting.new
end
def create
@zonefile_setting = ZonefileSetting.new(zonefile_setting_params)
if @zonefile_setting.save
flash[:notice] = I18n.t('record_created')
redirect_to admin_zonefile_settings_path
else
flash.now[:alert] = I18n.t('failed_to_create_record')
render 'new'
end
end
def edit
@zonefile_setting = ZonefileSetting.find(params[:id])
end
def update
if @zonefile_setting.update(zonefile_setting_params)
flash[:notice] = I18n.t('record_updated')
redirect_to admin_zonefile_settings_path
else
flash.now[:alert] = I18n.t('failed_to_update_record')
render 'edit'
end
end
def destroy
if @zonefile_setting.destroy
flash[:notice] = I18n.t('record_deleted')
redirect_to admin_zonefile_settings_path
else
flash.now[:alert] = I18n.t('failed_to_delete_record')
render 'edit'
end
end
private
def set_zonefile_setting
@zonefile_setting = ZonefileSetting.find(params[:id])
end
def zonefile_setting_params
params.require(:zonefile_setting).permit(
:origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email,
:master_nameserver, :ns_records, :a_records, :a4_records
)
end
end

View file

@ -3,7 +3,7 @@ class Admin::ZonefilesController < ApplicationController
# TODO: Refactor this
def create
if ZonefileSetting.origins.include?(params[:origin])
if DNS::Zone.origins.include?(params[:origin])
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('#{params[:origin]}')"