Create blocked domains #2564

This commit is contained in:
Martin Lensment 2015-07-01 12:45:58 +03:00
parent cd277c25ed
commit d93d43e75c
13 changed files with 254 additions and 80 deletions

View file

@ -0,0 +1,22 @@
class Admin::BlockedDomainsController < AdminController
load_and_authorize_resource
def index
bd = BlockedDomain.first_or_initialize
@blocked_domains = bd.names.join("\n")
end
def create
names = params[:blocked_domains].split("\r\n").map(&:strip)
bd = BlockedDomain.first_or_create
if bd.update(names: names)
flash[:notice] = I18n.t('record_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_record')
end
redirect_to :back
end
end

View file

@ -106,6 +106,7 @@ class Ability
def admin
customer_service
can :manage, Setting
can :manage, BlockedDomain
can :manage, ZonefileSetting
can :manage, DomainVersion
can :manage, Pricelist

View file

@ -0,0 +1,5 @@
class BlockedDomain < ActiveRecord::Base
include Versions
after_initialize -> { self.names = [] if names.nil? }
end

View file

@ -62,7 +62,8 @@ class Epp::Domain < Domain
],
'2302' => [ # Object exists
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }]
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :blocked, { value: { obj: 'name', val: name_dirty } }]
],
'2304' => [ # Object status prohibits operation
[:base, :domain_status_prohibits_operation]

View file

@ -0,0 +1,4 @@
class BlockedDomainVersion < PaperTrail::Version
self.table_name = :log_blocked_domains
self.sequence_name = :log_blocked_domains_id_seq
end

View file

@ -1,11 +1,17 @@
class DomainNameValidator < ActiveModel::EachValidator
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def validate_each(record, attribute, value)
if !self.class.validate_format(value)
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_blocked(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :blocked)))
elsif !self.class.validate_reservation(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :reserved)))
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
class << self
def validate_format(value)
@ -31,6 +37,11 @@ class DomainNameValidator < ActiveModel::EachValidator
# rubocop: enable Style/DoubleNegation
end
def validate_blocked(value)
return true unless value
BlockedDomain.where("names @> ?::varchar[]", "{#{value}}").count == 0
end
def validate_reservation(value)
return true unless value
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)

View file

@ -0,0 +1,10 @@
= render 'shared/title', name: t(:blocked_domains)
= form_tag([:admin, :blocked_domains]) do |f|
.row
.col-md-12
= text_area_tag :blocked_domains, @blocked_domains, class: 'form-control', rows: 30
%hr
.row
.col-md-12.text-right
%button.btn.btn-warning=t(:save)

View file

@ -59,9 +59,7 @@
%li.dropdown-header= t(:system)
%li= link_to t(:settings), admin_settings_path
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li.dropdown-header= t(:system)
%li= link_to t(:settings), admin_settings_path
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li= link_to t(:blocked_domains), admin_blocked_domains_path
-# %li= link_to t(:domains_history), admin_domain_versions_path
%li= link_to t(:epp_logs), admin_epp_logs_path
%li= link_to t(:repp_logs), admin_repp_logs_path