mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Nameserver hostname replacing
This commit is contained in:
parent
23098add74
commit
1f2ba55acb
7 changed files with 135 additions and 0 deletions
38
app/controllers/registrar/nameservers_controller.rb
Normal file
38
app/controllers/registrar/nameservers_controller.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
class Registrar::NameserversController < RegistrarController
|
||||||
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
def index
|
||||||
|
nameservers = current_user.registrar.nameservers
|
||||||
|
@q = nameservers.search(params[:q])
|
||||||
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||||
|
@nameservers = @q.result.page(params[:page])
|
||||||
|
|
||||||
|
return unless can_replace_hostnames?
|
||||||
|
|
||||||
|
res = Nameserver.replace_hostname_ends(
|
||||||
|
current_user.registrar.domains.includes(
|
||||||
|
:registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses,
|
||||||
|
:versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys
|
||||||
|
),
|
||||||
|
params[:q][:hostname_end],
|
||||||
|
params[:hostname_end_replacement]
|
||||||
|
)
|
||||||
|
|
||||||
|
if res
|
||||||
|
flash.now[:notice] = t('all_hostnames_replaced')
|
||||||
|
else
|
||||||
|
flash.now[:warning] = t('hostnames_partially_replaced')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def can_replace_hostnames?
|
||||||
|
if params[:replace] && params[:q]
|
||||||
|
flash.now[:alert] = t('hostname_end_replacement_is_required') unless params[:hostname_end_replacement].present?
|
||||||
|
flash.now[:alert] = t('hostname_end_is_required') unless params[:q][:hostname_end].present?
|
||||||
|
return true if flash[:alert].blank?
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
|
@ -48,6 +48,7 @@ class Ability
|
||||||
def registrar
|
def registrar
|
||||||
can :manage, Invoice
|
can :manage, Invoice
|
||||||
can :read, AccountActivity
|
can :read, AccountActivity
|
||||||
|
can :manage, Nameserver
|
||||||
can :view, :registrar_dashboard
|
can :view, :registrar_dashboard
|
||||||
can :delete, :registrar_poll
|
can :delete, :registrar_poll
|
||||||
can :manage, :registrar_xml_console
|
can :manage, :registrar_xml_console
|
||||||
|
|
|
@ -5,6 +5,8 @@ class Nameserver < ActiveRecord::Base
|
||||||
# belongs_to :registrar
|
# belongs_to :registrar
|
||||||
belongs_to :domain
|
belongs_to :domain
|
||||||
|
|
||||||
|
# scope :owned_by_registrar, -> (registrar) { joins(:domain).where('domains.registrar_id = ?', registrar.id) }
|
||||||
|
|
||||||
# rubocop: disable Metrics/LineLength
|
# rubocop: disable Metrics/LineLength
|
||||||
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
||||||
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
||||||
|
@ -40,4 +42,27 @@ class Nameserver < ActiveRecord::Base
|
||||||
def to_s
|
def to_s
|
||||||
hostname
|
hostname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def replace_hostname_ends(domains, old_end, new_end)
|
||||||
|
res = true
|
||||||
|
domains.each do |d|
|
||||||
|
nameservers = d.nameservers.where('hostname LIKE ?', "%#{old_end}")
|
||||||
|
next unless nameservers
|
||||||
|
|
||||||
|
ns_attrs = { nameservers_attributes: [] }
|
||||||
|
|
||||||
|
nameservers.each do |ns|
|
||||||
|
hn = ns.hostname.chomp(old_end)
|
||||||
|
ns_attrs[:nameservers_attributes] << {
|
||||||
|
id: ns.id,
|
||||||
|
hostname: "#{hn}#{new_end}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
res = false unless d.update(ns_attrs)
|
||||||
|
end
|
||||||
|
res
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ class Registrar < ActiveRecord::Base
|
||||||
has_many :messages
|
has_many :messages
|
||||||
has_many :invoices, foreign_key: 'buyer_id'
|
has_many :invoices, foreign_key: 'buyer_id'
|
||||||
has_many :accounts
|
has_many :accounts
|
||||||
|
has_many :nameservers, through: :domains
|
||||||
|
|
||||||
belongs_to :country_deprecated, foreign_key: :country_id
|
belongs_to :country_deprecated, foreign_key: :country_id
|
||||||
|
|
||||||
|
|
57
app/views/registrar/nameservers/index.haml
Normal file
57
app/views/registrar/nameservers/index.haml
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/ - content_for :actions do
|
||||||
|
/ = link_to(t(:add_deposit), new_registrar_deposit_path, class: 'btn btn-primary')
|
||||||
|
/ = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
|
||||||
|
= render 'shared/title', name: t(:nameservers)
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
= search_form_for @q, url: [:registrar, :nameservers], html: { style: 'margin-bottom: 0;' } do |f|
|
||||||
|
.row
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= f.label t(:hostname_end)
|
||||||
|
= f.search_field :hostname_end, class: 'form-control', placeholder: t(:hostname_end), autocomplete: 'off'
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag t(:hostname_end_replacement)
|
||||||
|
= text_field_tag :hostname_end_replacement, params[:hostname_end_replacement], class: 'form-control', placeholder: t(:hostname_end_replacement), autocomplete: 'off'
|
||||||
|
.col-md-4{style: 'padding-top: 25px;'}
|
||||||
|
%button.btn.btn-default
|
||||||
|
|
||||||
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
||||||
|
%button.btn.btn-default{name: 'replace'}
|
||||||
|
= t(:replace)
|
||||||
|
%button.btn.btn-default.js-reset-form
|
||||||
|
= t(:clear_fields)
|
||||||
|
%hr
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
.table-responsive
|
||||||
|
%table.table.table-hover.table-condensed
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th{class: 'col-xs-4'}= t(:hostname)
|
||||||
|
%th{class: 'col-xs-4'}= t(:ipv4)
|
||||||
|
%th{class: 'col-xs-4'}= t(:ipv6)
|
||||||
|
%tbody
|
||||||
|
- @nameservers.each do |x|
|
||||||
|
%tr
|
||||||
|
- if params[:q] && params[:q][:hostname_end]
|
||||||
|
- hn = x.hostname.chomp(params[:q][:hostname_end])
|
||||||
|
%td
|
||||||
|
= precede hn do
|
||||||
|
%strong= params[:q][:hostname_end]
|
||||||
|
- else
|
||||||
|
%td= x.hostname
|
||||||
|
%td= x.ipv4
|
||||||
|
%td= x.ipv4
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
/ = paginate @nameservers
|
||||||
|
|
||||||
|
:coffee
|
||||||
|
$(".js-reset-form").on "click", (e) ->
|
||||||
|
e.preventDefault();
|
||||||
|
window.location = "#{registrar_nameservers_path}"
|
||||||
|
|
|
@ -746,3 +746,10 @@ en:
|
||||||
due_date_before: 'Due date before'
|
due_date_before: 'Due date before'
|
||||||
minimum_total: 'Minimum total'
|
minimum_total: 'Minimum total'
|
||||||
maximum_total: 'Maximum total'
|
maximum_total: 'Maximum total'
|
||||||
|
hostname_end: 'Hostname end'
|
||||||
|
hostname_end_replacement: 'Hostname end replacement'
|
||||||
|
hostname_end_is_required: 'Hostname end is required'
|
||||||
|
hostname_end_replacement_is_required: 'Hostname end replacement is required'
|
||||||
|
hostnames_replaced: 'Hostnames replaced'
|
||||||
|
all_hostnames_replaced: 'All hostnames replaced'
|
||||||
|
hostnames_partially_replaced: 'Hostnames partially replaced'
|
||||||
|
|
|
@ -55,6 +55,12 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :nameservers do
|
||||||
|
collection do
|
||||||
|
get 'replace_hostnames'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :contacts do
|
resources :contacts do
|
||||||
member do
|
member do
|
||||||
get 'delete'
|
get 'delete'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue