Merge branch 'master' into 108869472-objects_archive

This commit is contained in:
Stas Paaslane 2016-08-04 19:22:08 +03:00
commit 305333d6c9
29 changed files with 202 additions and 142 deletions

View file

@ -35,7 +35,7 @@ module Repp
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.auth_info.eql? request.headers['Auth-Code']
contact_repp_json = proc{|contact|
contact.attributes.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
contact.as_json.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
}
@response = {

View file

@ -2,6 +2,9 @@ $(document).on 'page:change', ->
$('.selectize').selectize({
allowEmptyOption: true
})
$('.selectize_create').selectize({
allowEmptyOption: true, create: true
})
$('.js-datepicker').datepicker({
showAnim: "",

View file

@ -10,21 +10,13 @@ class Admin::ContactsController < AdminController
search_params[:registrant_domains_id_not_null] = 1
end
@q = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name').search(search_params)
@contacts = @q.result(distinct: :true).page(params[:page])
if params[:statuses_contains]
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name').where(
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name')
end
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name')
contacts = contacts.filter_by_states(params[:statuses_contains].join(',')) if params[:statuses_contains]
contacts = contacts.where("ident_country_code is null or ident_country_code=''") if params[:only_no_country_code].eql?('1')
normalize_search_parameters do
@q = contacts.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name').search(search_params)
@q = contacts.search(search_params)
@contacts = @q.result.uniq.page(params[:page])
end

View file

@ -51,6 +51,7 @@ class Admin::SettingsController < AdminController
:admin_contacts_max_count,
:tech_contacts_min_count,
:tech_contacts_max_count,
:orphans_contacts_in_months,
:ds_digest_type,
:dnskeys_min_count,
:dnskeys_max_count,

View file

@ -56,4 +56,8 @@ class Epp::KeyrelaysController < EppController
# domain
end
def resource
@domain
end
end

View file

@ -54,4 +54,8 @@ class Epp::PollsController < EppController
def validate_poll
requires_attribute 'poll', 'op', values: %(ack req), allow_blank: true
end
def resource
@message
end
end

View file

@ -137,4 +137,9 @@ class Epp::SessionsController < EppController
pw = params[:parsed_frame].css('pw').first.text
{ username: user, password: pw }
end
private
def resource
@api_user
end
end

View file

@ -6,8 +6,15 @@ class EppController < ApplicationController
before_action :generate_svtrid
before_action :latin_only
before_action :validate_against_schema
before_action :validate_request
before_action :update_epp_session
around_action :catch_epp_errors
helper_method :current_user
helper_method :resource
def validate_against_schema
return if ['hello', 'error', 'keyrelay'].include?(params[:action])
schema.validate(params[:nokogiri_frame]).each do |error|
@ -20,10 +27,7 @@ class EppController < ApplicationController
handle_errors and return if epp_errors.any?
end
before_action :validate_request
before_action :update_epp_session
around_action :catch_epp_errors
def catch_epp_errors
err = catch(:epp_error) do
yield
@ -34,7 +38,6 @@ class EppController < ApplicationController
handle_errors
end
helper_method :current_user
rescue_from StandardError do |e|
@errors ||= []
@ -367,7 +370,7 @@ class EppController < ApplicationController
request: trimmed_request,
request_command: request_command,
request_successful: epp_errors.empty?,
request_object: params[:epp_object_type],
request_object: resource ? "#{params[:epp_object_type]}: #{resource.class} - #{resource.id} - #{resource.name}" : params[:epp_object_type],
response: @response,
api_user_name: @api_user.try(:username) || current_user.try(:username) || 'api-public',
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
@ -383,4 +386,9 @@ class EppController < ApplicationController
return if current_user.blank?
counter_update(current_user.registrar_code, ENV['iptables_server_ip'])
end
def resource
name = self.class.to_s.sub("Epp::","").sub("Controller","").underscore.singularize
instance_variable_get("@#{name}")
end
end

View file

@ -42,13 +42,8 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
@contacts = Contact.find_by(name: params[:q][:name_matches])
end
if params[:statuses_contains]
contacts = current_user.registrar.contacts.includes(:registrar).where(
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
contacts = current_user.registrar.contacts.includes(:registrar)
end
contacts = current_user.registrar.contacts.includes(:registrar)
contacts = contacts.filter_by_states(params[:statuses_contains]) if params[:statuses_contains]
normalize_search_parameters do
@q = contacts.search(params[:q])

View file

@ -62,6 +62,10 @@ class ApiUser < User
username
end
def name
username
end
def queued_messages
registrar.messages.queued
end

View file

@ -36,12 +36,10 @@ class Contact < ActiveRecord::Base
validate :val_ident_type
validate :val_ident_valid_format?
validate :uniq_statuses?
validate :validate_html
validate :val_country_code
after_initialize do
self.statuses = [] if statuses.nil?
self.status_notes = {} if status_notes.nil?
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
end
@ -64,16 +62,6 @@ class Contact < ActiveRecord::Base
end
end
before_save :manage_statuses
def manage_statuses
if domain_transfer # very ugly but need better workflow
self.statuses = statuses | [OK, LINKED]
return
end
manage_linked
manage_ok
end
after_save :update_related_whois_records
@ -176,7 +164,7 @@ class Contact < ActiveRecord::Base
end
def find_orphans
Contact.where('
where('
NOT EXISTS(
select 1 from domains d where d.registrant_id = contacts.id
) AND NOT EXISTS(
@ -185,20 +173,49 @@ class Contact < ActiveRecord::Base
')
end
def find_linked
where('
EXISTS(
select 1 from domains d where d.registrant_id = contacts.id
) OR EXISTS(
select 1 from domain_contacts dc where dc.contact_id = contacts.id
)
')
end
def filter_by_states in_states
states = Array(in_states).dup
scope = all
# all contacts has state ok, so no need to filter by it
scope = scope.where("NOT contacts.statuses && ?::varchar[]", "{#{(STATUSES - [OK, LINKED]).join(',')}}") if states.delete(OK)
scope = scope.find_linked if states.delete(LINKED)
scope = scope.where("contacts.statuses @> ?::varchar[]", "{#{states.join(',')}}") if states.any?
scope
end
# To leave only new ones we need to check
# if contact was at any time used in domain.
# This can be checked by domain history.
# This can be checked by saved relations in children attribute
def destroy_orphans
STDOUT << "#{Time.zone.now.utc} - Destroying orphaned contacts\n" unless Rails.env.test?
orphans = find_orphans
unless Rails.env.test?
orphans.each do |m|
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{m.id} (#{m.name})\n"
counter = Counter.new
find_orphans.find_each do |contact|
ver_scope = []
%w(admin_contacts tech_contacts registrant).each do |type|
ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb"
end
next if DomainVersion.where("created_at > ?", Time.now - Setting.orphans_contacts_in_months.to_i.months).where(ver_scope.join(" OR ")).any?
next if contact.domains_present?
contact.destroy
counter.next
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n"
end
count = orphans.destroy_all.count
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n" unless Rails.env.test?
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{counter} orphaned contacts\n" unless Rails.env.test?
end
def privs
@ -239,6 +256,23 @@ class Contact < ActiveRecord::Base
"EIS-#{id}"
end
# kind of decorator in order to always return statuses
# if we use separate decorator, then we should add it
# to too many places
def statuses
calculated = Array(read_attribute(:statuses))
calculated.delete(Contact::OK)
calculated.delete(Contact::LINKED)
calculated << Contact::OK if calculated.empty?# && valid?
calculated << Contact::LINKED if domains_present?
calculated.uniq
end
def statuses= arr
write_attribute(:statuses, Array(arr).uniq)
end
def to_s
name || '[no name]'
end
@ -278,11 +312,6 @@ class Contact < ActiveRecord::Base
end
end
def uniq_statuses?
return true unless statuses.detect { |s| statuses.count(s) > 1 }
errors.add(:statuses, :not_uniq)
false
end
def org?
ident_type == ORG
@ -412,13 +441,6 @@ class Contact < ActiveRecord::Base
domain_contacts.present? || registrant_domains.present?
end
def manage_linked
if domains_present?
set_linked
else
unset_linked
end
end
def search_name
"#{code} #{name}"
@ -497,43 +519,6 @@ class Contact < ActiveRecord::Base
end
end
def set_linked
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
end
def unset_linked
statuses.delete_if { |s| s == LINKED }
end
# rubocop:disable Metrics/CyclomaticComplexity
def manage_ok
return unset_ok unless valid?
case statuses.size
when 0
set_ok
when 1
set_ok if statuses == [LINKED]
when 2
return if statuses.sort == [LINKED, OK]
unset_ok
else
unset_ok
end
end
# rubocop:enable Metrics/CyclomaticComplexity
def unset_ok
statuses.delete_if { |s| s == OK }
end
def set_ok
statuses << OK if statuses.detect { |s| s == OK }.blank?
end
def linked?
statuses.include?(LINKED)
end
def update_prohibited?
(statuses & [
@ -562,6 +547,9 @@ class Contact < ActiveRecord::Base
end
def update_related_whois_records
# not doing anything if no real changes
return if changes.slice(*(self.class.column_names - ["updated_at", "created_at", "statuses", "status_notes"])).empty?
names = related_domain_descriptions.keys
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
end

View file

@ -478,7 +478,8 @@ class Domain < ActiveRecord::Base
def validate_nameserver_ips
nameservers.to_a.reject(&:marked_for_destruction?).each do |ns|
next unless ns.hostname.end_with?(".#{name}")
next if ns.ipv4.present?
next if ns.ipv4.present? || ns.ipv6.present?
errors.add(:nameservers, :invalid) if errors[:nameservers].blank?
ns.errors.add(:ipv4, :blank)
end

View file

@ -39,29 +39,12 @@ class Epp::Domain < Domain
before_save :link_contacts
def link_contacts
# Based on bullet report
if new_record?
# new record does not have correct instance contacts entries thanks to epp
unlinked_contacts = [registrant]
unlinked_contacts << admin_domain_contacts.map(&:contact)
unlinked_contacts << tech_domain_contacts.map(&:contact)
unlinked_contacts.flatten!
else
unlinked_contacts = contacts.select { |c| !c.linked? } # speed up a bit
end
unlinked_contacts.each do |uc|
uc.domains_present = true # no need to fetch domains again
uc.save(validate: false)
end
#TODO: cleanup cache if we think to cache dynamic statuses
end
after_destroy :unlink_contacts
def unlink_contacts
contacts.each do |c|
c.domains_present = false
c.save(validate: false)
end
#TODO: cleanup cache if we think to cache dynamic statuses
end
class << self

View file

@ -12,4 +12,8 @@ class Message < ActiveRecord::Base
self.queued = false
save
end
def name
"-"
end
end

View file

@ -32,7 +32,7 @@ class Nameserver < ActiveRecord::Base
[:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }],
[:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }]
],
'2306' => [
'2003' => [
[:ipv4, :blank]
]
}

View file

@ -5,6 +5,7 @@
- if domain.present?
- if version # normal history
- epp_req = ApiLog::EppLog.find_by(uuid: version.uuid).try(:request) if version.uuid
- children = HashWithIndifferentAccess.new(version.children)
- nameservers = Nameserver.all_versions_for(children[:nameservers], version.created_at)
- dnskeys = Dnskey.all_versions_for(children[:dnskeys], version.created_at)
@ -13,7 +14,9 @@
- registrant = Contact.all_versions_for(children[:registrant], version.created_at)
- event = version.event
- creator = plain_username(version.terminator)
- whodunnit = version.try(:whodunnit)
- else # pending history
- epp_req = false
- nameservers = domain.nameservers
- dnskeys = domain.dnskeys
- tech_contacts = domain.tech_contacts
@ -25,7 +28,8 @@
- registrant.version_loader = ver
- registrant = [registrant]
- creator = pending_user.try(:username)
- event = 'pending'
- event = 'pending'
- whodunnit = false
%td
%p.nowrap
@ -34,9 +38,15 @@
%br= link_to t(:edit_statuses), edit_admin_domain_path(params[:domain_id])
%p.text-right
= event
- if (event == 'update' || event == 'create') && epp_req
= link_to event, '#', class: 'js-event'
- else
= event
%br
= creator
- if whodunnit
= whodunnit
- else
= creator
- if version
%p.text-right
= link_to "Pure history", admin_domain_version_path(version)
@ -54,7 +64,7 @@
%br
- if domain.pending_json.present?
%p
= link_to t(:pending_epp), '#', class: 'js-pending-toggle'
= link_to t(:pending_epp), '#', class: 'js-pending'
%td{class: changing_css_class(version, "period", "period_unit", "valid_from", "valid_to")}
%p
@ -120,9 +130,15 @@
= link_to admin_registrar_path(domain.registrar), target: "registrar_#{domain.registrar.id}" do
= domain.registrar.name
- if (event == 'create' || event == 'update') && epp_req
%tr.js-event{ style: 'display: none;' }
%td{colspan: 9}
%pre
= Nokogiri::XML(epp_req)
- if domain.pending_json.present?
%tr.js-pending{ style: 'display: none;' }
%td{colspan: 8}
%td{colspan: 9}
= preserve do
%pre
- formatted_req = Nokogiri::XML(domain.pending_json['frame'])

View file

@ -37,9 +37,9 @@
domain: version.reify, version: version.previous
:coffee
$(document).on 'click', '.js-pending-toggle', (e) ->
$(document).on 'click', '.js-pending, .js-event', (e) ->
e.preventDefault()
$(document).on 'mousedown', '.js-pending-toggle', (e) ->
$(document).on 'mousedown', '.js-pending, .js-event', (e) ->
target = $(e.target)
target.parents('tr').next('tr.js-pending').toggle()
target.parents('tr').nextUntil('tr.small' ,'tr.' + this.className).toggle()

View file

@ -11,8 +11,10 @@
= f.select :request_command_eq, [[t(:choose),''], 'hello', 'login', 'logout', 'info', 'create', 'update', 'delete', 'check', 'renew', 'transfer', 'poll', 'keyrelay'], {}, class: 'form-control selectize', placeholder: t(:choose)
.col-md-3
.form-group
- opts = [[t(:choose),''], 'contact', 'domain', 'poll', 'keyrelay']
- opts += [params[:q][:request_object_cont]] if params[:q].present? && params[:q][:request_object_cont].present?
= f.label :request_object
= f.select :request_object_eq, [[t(:choose),''], 'contact', 'domain', 'poll', 'keyrelay'], {}, class: 'form-control selectize', placeholder: t(:choose)
= f.select :request_object_cont, opts, {}, class: 'form-control selectize_create', placeholder: t(:choose)
.col-md-3
.form-group
= f.label :request_successful

View file

@ -15,6 +15,7 @@
= render 'setting_row', var: :admin_contacts_max_count
= render 'setting_row', var: :tech_contacts_min_count
= render 'setting_row', var: :tech_contacts_max_count
= render 'setting_row', var: :orphans_contacts_in_months
= render 'setting_row', var: :ds_data_allowed
= render 'setting_row', var: :key_data_allowed
= render 'setting_row', var: :dnskeys_min_count

View file

@ -30,6 +30,8 @@ Hi,
<br><br>
Registrant change process for the domain <%= @params[:name] %> has been started.
<br><br>
Please verify the details of the following change request. In case of problems contact your registrar <%= @params[:registrar_name] %>
<br><br>
New registrant:<br>
Name: <%= @params[:registrant_name] %><br>
<% if @params[:registrant_priv] %>
@ -41,7 +43,11 @@ Street: <%= @params[:registrant_street] %><br>
City: <%= @params[:registrant_city] %><br>
Country: <%= @params[:registrant_country] %>
<br><br>
Please contact to your registrar <%= @params[:registrar_name] %> if you have any questions.
The registrant change procedure will be completed only after the current registrant <%= @params[:old_registrant_name] %> has approved it.
<br><br>
Change request will be cancelled in case <%= @params[:old_registrant_name] %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours.
<br><br>
Please contact registrar <%= @params[:registrar_name] %> in case of questions. You can find the registrar's contacts at http://internet.ee/registrars.
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -30,6 +30,8 @@ Hi,
Registrant change process for the domain <%= @params[:name] %> has been started.
Please verify the details of the following change request. In case of problems contact your registrar <%= @params[:registrar_name] %>
New registrant:
Name: <%= @params[:registrant_name] %>
<% if @params[:registrant_priv] %>
@ -41,7 +43,11 @@ Street: <%= @params[:registrant_street] %>
City: <%= @params[:registrant_city] %>
Country: <%= @params[:registrant_country] %>
Please contact to your registrar <%= @params[:registrar_name] %> if you have any questions.
The registrant change procedure will be completed only after the current registrant <%= @params[:old_registrant_name] %> has approved it.
Change request will be cancelled in case <%= @params[:old_registrant_name] %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours.
Please contact registrar <%= @params[:registrar_name] %> in case of questions. You can find the registrar's contacts at http://internet.ee/registrars.
Best Regards,
Estonian Internet Foundation