Add ability to delete records #2806

This commit is contained in:
Martin Lensment 2015-08-03 12:23:48 +03:00
parent 44b2d383b1
commit 72b322ae1f
4 changed files with 21 additions and 0 deletions

View file

@ -35,6 +35,16 @@ class Admin::ZonefileSettingsController < AdminController
end end
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 private
def set_zonefile_setting def set_zonefile_setting

View file

@ -4,6 +4,14 @@ class ZonefileSetting < ActiveRecord::Base
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true } validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
validates :origin, uniqueness: true validates :origin, uniqueness: true
before_destroy :check_for_dependencies
def check_for_dependencies
dc = Domain.where("name ILIKE ?", "%.#{origin}").count
return if dc == 0
errors.add(:base, I18n.t('there_are_count_domains_in_this_zone', count: dc))
false
end
def self.generate_zonefiles def self.generate_zonefiles
pluck(:origin).each do |origin| pluck(:origin).each do |origin|
generate_zonefile(origin) generate_zonefile(origin)

View file

@ -1,5 +1,7 @@
- content_for :actions do - content_for :actions do
= link_to(t(:back), admin_zonefile_settings_path, class: 'btn btn-default') = link_to(t(:back), admin_zonefile_settings_path, class: 'btn btn-default')
= link_to(t(:delete), admin_zonefile_setting_path(@zonefile_setting),
method: :delete, data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger')
= render 'shared/title', name: t(:edit_zone) = render 'shared/title', name: t(:edit_zone)
= render 'form' = render 'form'

View file

@ -898,3 +898,4 @@ en:
a4_records: 'AAAA records' a4_records: 'AAAA records'
new_zone: 'New zone' new_zone: 'New zone'
edit_zone: 'Edit zone' edit_zone: 'Edit zone'
there_are_count_domains_in_this_zone: 'There are %{count} domains in this zone'