mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 01:35:10 +02:00
Merge branch 'registry-475-refactor-zones' into registry-475
# Conflicts: # db/schema-read-only.rb # db/structure.sql
This commit is contained in:
commit
dbca4d010a
12 changed files with 165 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
|||
module Admin
|
||||
module DNS
|
||||
class ZonesController < AdminController
|
||||
load_and_authorize_resource(class: DNS::Zone)
|
||||
authorize_resource(class: 'DNS::Zone')
|
||||
before_action :load_zone, only: %i[edit update destroy]
|
||||
|
||||
def index
|
||||
|
@ -49,10 +49,21 @@ module Admin
|
|||
end
|
||||
|
||||
def zone_params
|
||||
params.require(:zone).permit(
|
||||
:origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email,
|
||||
:master_nameserver, :ns_records, :a_records, :a4_records
|
||||
)
|
||||
allowed_params = %i[
|
||||
origin
|
||||
ttl
|
||||
refresh
|
||||
retry
|
||||
expire
|
||||
minimum_ttl
|
||||
email
|
||||
master_nameserver
|
||||
ns_records
|
||||
a_records
|
||||
a4_records
|
||||
]
|
||||
|
||||
params.require(:zone).permit(*allowed_params)
|
||||
end
|
||||
|
||||
def redirect_to_index
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
module DNS
|
||||
class Zone < ActiveRecord::Base
|
||||
self.auto_html5_validation = false
|
||||
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: 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
|
||||
before_destroy do
|
||||
!used?
|
||||
end
|
||||
|
||||
def self.generate_zonefiles
|
||||
|
@ -37,6 +34,10 @@ module DNS
|
|||
pluck(:origin)
|
||||
end
|
||||
|
||||
def used?
|
||||
Domain.uses_zone?(self)
|
||||
end
|
||||
|
||||
def to_s
|
||||
origin
|
||||
end
|
||||
|
|
|
@ -724,5 +724,9 @@ class Domain < ActiveRecord::Base
|
|||
def self.delete_candidates
|
||||
where("#{attribute_alias(:delete_time)} < ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def self.uses_zone?(zone)
|
||||
exists?(["name ILIKE ?", "%.#{zone.origin}"])
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
.col-md-4.control-label
|
||||
= f.label :origin
|
||||
.col-md-8
|
||||
- if zone.persisted?
|
||||
= f.text_field :origin, class: 'form-control', disabled: true
|
||||
- else
|
||||
- if f.object.new_record?
|
||||
= f.text_field :origin, class: 'form-control', required: true
|
||||
- else
|
||||
= f.text_field :origin, class: 'form-control', disabled: true
|
||||
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
|
@ -47,7 +47,7 @@
|
|||
.col-md-4.control-label
|
||||
= f.label :email
|
||||
.col-md-8
|
||||
= f.email_field :email, class: 'form-control', required: true
|
||||
= f.text_field :email, class: 'form-control', required: true
|
||||
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
|
@ -69,7 +69,7 @@
|
|||
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
= f.label :a4_records, t(:a4_records)
|
||||
= f.label :a4_records
|
||||
.col-md-8
|
||||
= f.text_area :a4_records, class: 'form-control', rows: 8
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue