mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Refactored contact with ability
This commit is contained in:
parent
62f8061e10
commit
96d1c60dd8
33 changed files with 763 additions and 1045 deletions
|
@ -1,4 +1,3 @@
|
|||
class AdminController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
check_authorization
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
check_authorization
|
||||
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
@ -9,8 +11,22 @@ class ApplicationController < ActionController::Base
|
|||
params[resource] &&= send(method) if respond_to?(method, true)
|
||||
end
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
redirect_to admin_dashboard_path, alert: exception.message
|
||||
end
|
||||
|
||||
def current_ability
|
||||
if defined?(current_api_user) && current_api_user.present?
|
||||
current_api_user.ability
|
||||
else
|
||||
current_user.ability
|
||||
end
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(_resource)
|
||||
return session[:user_return_to].to_s if session[:user_return_to] && session[:user_return_to] != login_path
|
||||
if session[:user_return_to] && session[:user_return_to] != login_path
|
||||
return session[:user_return_to].to_s
|
||||
end
|
||||
admin_dashboard_path
|
||||
end
|
||||
|
||||
|
@ -34,9 +50,3 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
redirect_to admin_dashboard_path, alert: exception.message
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,183 +1,114 @@
|
|||
class Epp::ContactsController < EppController
|
||||
before_action :find_contact, only: [:info, :update, :delete]
|
||||
before_action :find_password, only: [:info, :update, :delete]
|
||||
|
||||
def info
|
||||
handle_errors(@contact) and return unless @contact && rights?
|
||||
# handle_errors(@contact) and return unless rights?
|
||||
@disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.try(:as_hash) || {})
|
||||
@disclosure_policy = @contact.disclosure.try(:attributes_with_flag)
|
||||
@owner = owner?(false)
|
||||
# need to reload contact eagerly
|
||||
@contact = find_contact if @owner # for clarity, could just be true
|
||||
authorize! :info, @contact, @password
|
||||
render_epp_response 'epp/contacts/info'
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(contact_and_address_attributes)
|
||||
@contact.registrar = current_user.registrar
|
||||
render_epp_response '/epp/contacts/create' and return if @contact.save
|
||||
handle_errors(@contact)
|
||||
end
|
||||
|
||||
def update
|
||||
# FIXME: Update returns 2303 update multiple times
|
||||
code = params_hash['epp']['command']['update']['update'][:id]
|
||||
|
||||
@contact = Contact.where(code: code).first
|
||||
# if update_rights? && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
if owner? && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
render_epp_response 'epp/contacts/update'
|
||||
else
|
||||
contact_exists?(code)
|
||||
handle_errors(@contact) and return
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def delete
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless rights? # owner?
|
||||
handle_errors(@contact) and return unless @contact
|
||||
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
||||
|
||||
render_epp_response '/epp/contacts/delete'
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
def check
|
||||
ph = params_hash['epp']['command']['check']['check']
|
||||
@contacts = Contact.check_availability(ph[:id])
|
||||
authorize! :check, Epp::Contact
|
||||
|
||||
ids = params[:parsed_frame].css('id').map(&:text)
|
||||
@results = Contact.check_availability(ids)
|
||||
render_epp_response '/epp/contacts/check'
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, Epp::Contact
|
||||
|
||||
@contact = Epp::Contact.new(params[:parsed_frame])
|
||||
@contact.registrar = current_user.registrar
|
||||
|
||||
if @contact.save
|
||||
render_epp_response '/epp/contacts/create'
|
||||
else
|
||||
handle_errors(@contact)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :update, @contact, @password
|
||||
|
||||
if @contact.update_attributes(params[:parsed_frame])
|
||||
render_epp_response 'epp/contacts/update'
|
||||
else
|
||||
handle_errors(@contact)
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
authorize! :delete, @contact, @password
|
||||
|
||||
if @contact.destroy_and_clean
|
||||
render_epp_response '/epp/contacts/delete'
|
||||
else
|
||||
handle_errors(@contact)
|
||||
end
|
||||
end
|
||||
|
||||
def renew
|
||||
authorize! :renew, Epp::Contact
|
||||
epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') }
|
||||
handle_errors
|
||||
end
|
||||
|
||||
## HELPER METHODS
|
||||
|
||||
private
|
||||
|
||||
## CREATE
|
||||
def validate_create
|
||||
@prefix = 'create > create >'
|
||||
requires 'postalInfo > name', 'postalInfo > addr > city',
|
||||
'postalInfo > addr > cc', 'ident', 'voice', 'email'
|
||||
def find_password
|
||||
@password = params[:parsed_frame].css('authInfo pw').text
|
||||
end
|
||||
|
||||
def find_contact
|
||||
code = params[:parsed_frame].css('id').text.strip.downcase
|
||||
@contact = Epp::Contact.find_by(code: code)
|
||||
|
||||
if @contact.blank?
|
||||
epp_errors << {
|
||||
code: '2303',
|
||||
msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||
value: { obj: 'id', val: code }
|
||||
}
|
||||
fail CanCan::AccessDenied
|
||||
end
|
||||
@contact
|
||||
end
|
||||
|
||||
#
|
||||
# Validations
|
||||
#
|
||||
def validate_info
|
||||
@prefix = 'info > info >'
|
||||
requires 'id'
|
||||
end
|
||||
|
||||
def validate_check
|
||||
@prefix = 'check > check >'
|
||||
requires 'id'
|
||||
end
|
||||
|
||||
def validate_create
|
||||
@prefix = 'create > create >'
|
||||
requires(
|
||||
'postalInfo > name', 'postalInfo > addr > city',
|
||||
'postalInfo > addr > cc', 'ident', 'voice', 'email'
|
||||
)
|
||||
end
|
||||
|
||||
## UPDATE
|
||||
def validate_update
|
||||
@prefix = 'update > update >'
|
||||
requires 'id'
|
||||
|
||||
if element_count('chg') == 0 && element_count('rem') == 0 && element_count('add') == 0
|
||||
epp_errors << {
|
||||
code: '2003',
|
||||
msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg')
|
||||
}
|
||||
end
|
||||
requires 'id', 'authInfo > pw'
|
||||
end
|
||||
|
||||
def contact_exists?(code)
|
||||
return true if @contact.is_a?(Contact)
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||
value: { obj: 'id', val: code } }
|
||||
end
|
||||
|
||||
## DELETE
|
||||
def validate_delete
|
||||
@ph = params_hash['epp']['command']['delete']['delete']
|
||||
xml_attrs_present?(@ph, [['id']])
|
||||
end
|
||||
|
||||
## check
|
||||
def validate_check
|
||||
@ph = params_hash['epp']['command']['check']['check']
|
||||
xml_attrs_present?(@ph, [['id']])
|
||||
end
|
||||
|
||||
## info
|
||||
def validate_info # and process
|
||||
@ph = params_hash['epp']['command']['info']['info']
|
||||
return false unless xml_attrs_present?(@ph, [['id']])
|
||||
@contact = find_contact
|
||||
return false unless @contact
|
||||
return true if current_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
|
||||
false
|
||||
end
|
||||
|
||||
## SHARED
|
||||
|
||||
def find_contact
|
||||
contact_code = params[:parsed_frame].css('id').text.strip.downcase
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
|
||||
if contact.blank?
|
||||
epp_errors << { code: '2303',
|
||||
msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||
value: { obj: 'id', val: contact_code } }
|
||||
end
|
||||
contact
|
||||
end
|
||||
|
||||
def owner?(with_errors = true)
|
||||
return false unless find_contact
|
||||
return true if @contact.registrar == current_user.registrar
|
||||
return false unless with_errors
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
||||
false
|
||||
end
|
||||
|
||||
def rights?
|
||||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
|
||||
return true if current_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if pw && @contact.auth_info_matches(pw) # @contact.try(:auth_info_matches, pw)
|
||||
|
||||
epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }
|
||||
false
|
||||
end
|
||||
|
||||
def update_rights?
|
||||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
return true if pw && @contact.auth_info_matches(pw)
|
||||
epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }
|
||||
false
|
||||
end
|
||||
|
||||
def contact_and_address_attributes(type = :create)
|
||||
case type
|
||||
when :update
|
||||
# TODO: support for rem/add
|
||||
contact_hash = merge_attribute_hash(@ph[:chg], type).delete_if { |_k, v| v.empty? }
|
||||
else
|
||||
contact_hash = merge_attribute_hash(@ph, type)
|
||||
end
|
||||
contact_hash[:ident_type] = ident_type unless ident_type.nil?
|
||||
contact_hash
|
||||
end
|
||||
|
||||
def merge_attribute_hash(prms, type)
|
||||
contact_hash = Contact.extract_attributes(prms, type)
|
||||
contact_hash = contact_hash.merge(
|
||||
Address.extract_attributes((prms.try(:[], :postalInfo) || []))
|
||||
)
|
||||
contact_hash[:disclosure_attributes] =
|
||||
ContactDisclosure.extract_attributes(params[:parsed_frame])
|
||||
|
||||
contact_hash
|
||||
end
|
||||
|
||||
def ident_type
|
||||
result = params[:parsed_frame].css('ident').first.try(:attributes).try(:[], 'type').try(:value)
|
||||
return nil unless result
|
||||
|
||||
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
|
||||
nil
|
||||
end
|
||||
|
||||
def validate_params
|
||||
return true if @ph
|
||||
epp_errors << { code: '2001', msg: t(:'errors.messages.epp_command_syntax_error') }
|
||||
false
|
||||
@prefix = 'delete > delete >'
|
||||
requires 'id', 'authInfo > pw'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Epp::DomainsController < EppController
|
||||
skip_authorization_check # TODO: remove it
|
||||
|
||||
def create
|
||||
@domain = Epp::EppDomain.new(domain_create_params)
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Epp::ErrorsController < EppController
|
||||
skip_authorization_check # TODO: remove it
|
||||
|
||||
def error
|
||||
epp_errors << { code: params[:code], msg: params[:msg] }
|
||||
render_epp_response '/epp/error'
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Epp::KeyrelaysController < EppController
|
||||
skip_authorization_check # TODO: remove it
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def keyrelay
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Epp::PollsController < EppController
|
||||
skip_authorization_check # TODO: remove it
|
||||
|
||||
def poll
|
||||
req_poll if params[:parsed_frame].css('poll').first['op'] == 'req'
|
||||
ack_poll if params[:parsed_frame].css('poll').first['op'] == 'ack'
|
||||
|
@ -38,6 +40,6 @@ class Epp::PollsController < EppController
|
|||
private
|
||||
|
||||
def validate_poll
|
||||
requires_attribute 'poll', 'op', values: %(ack req)
|
||||
requires_attribute 'poll', 'op', values: %(ack req), allow_blank: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Epp::SessionsController < EppController
|
||||
skip_authorization_check only: [:hello, :login, :logout]
|
||||
|
||||
def hello
|
||||
render_epp_response('greeting')
|
||||
end
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
class EppController < ApplicationController
|
||||
layout false
|
||||
protect_from_forgery with: :null_session
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
before_action :generate_svtrid
|
||||
before_action :validate_request
|
||||
layout false
|
||||
helper_method :current_user
|
||||
|
||||
rescue_from CanCan::AccessDenied do |_exception|
|
||||
@errors ||= []
|
||||
if @errors.blank?
|
||||
@errors = [{
|
||||
msg: t('errors.messages.epp_authorization_error'),
|
||||
code: '2201'
|
||||
}]
|
||||
end
|
||||
render_epp_response '/epp/error'
|
||||
end
|
||||
|
||||
def generate_svtrid
|
||||
# rubocop: disable Style/VariableName
|
||||
@svTRID = "ccReg-#{format('%010d', rand(10**10))}"
|
||||
|
@ -112,7 +125,7 @@ class EppController < ApplicationController
|
|||
# requires_attribute 'transfer', 'op', values: %(approve, query, reject)
|
||||
|
||||
def requires_attribute(element_selector, attribute_selector, options)
|
||||
element = requires(element_selector)
|
||||
element = requires(element_selector, allow_blank: options[:allow_blank])
|
||||
return unless element
|
||||
|
||||
attribute = element[attribute_selector]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class SessionsController < Devise::SessionsController
|
||||
skip_authorization_check only: [:login, :create]
|
||||
|
||||
def create
|
||||
# TODO: Create ID Card login here:
|
||||
# this is just testing config
|
||||
|
|
|
@ -2,16 +2,25 @@ class Ability
|
|||
include CanCan::Ability
|
||||
|
||||
def initialize(user)
|
||||
alias_action :create, :read, :update, :destroy, to: :crud
|
||||
alias_action :show, :create, :update, :destroy, to: :crud
|
||||
|
||||
@user = user || AdminUser.new
|
||||
@user.roles.each { |role| send(role) } if @user.roles
|
||||
|
||||
return if @user.roles || @user.roles.any?
|
||||
|
||||
can :show, :dashboard
|
||||
end
|
||||
|
||||
def epp
|
||||
# Epp::Contact
|
||||
can(:info, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || c.auth_info == pw }
|
||||
can(:check, Epp::Contact)
|
||||
can(:create, Epp::Contact)
|
||||
can(:update, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id && c.auth_info == pw }
|
||||
can(:delete, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id && c.auth_info == pw }
|
||||
can(:renew, Epp::Contact)
|
||||
can(:view_password, Epp::Contact) { |c| c.registrar_id == @user.registrar_id }
|
||||
end
|
||||
|
||||
def user
|
||||
can :show, :dashboard
|
||||
end
|
||||
|
|
|
@ -13,6 +13,11 @@ class ApiUser < User
|
|||
|
||||
attr_accessor :registrar_typeahead
|
||||
|
||||
def ability
|
||||
@ability ||= Ability.new(self)
|
||||
end
|
||||
delegate :can?, :cannot?, to: :ability
|
||||
|
||||
def registrar_typeahead
|
||||
@registrar_typeahead || registrar || nil
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module VersionSession
|
|||
before_save :add_session
|
||||
|
||||
def add_session
|
||||
self.session = PaperSession.session
|
||||
self.session = ::PaperSession.session
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,9 +28,9 @@ module Versions
|
|||
return nil if creator_str.blank?
|
||||
|
||||
if creator_str =~ /^\d-api-/
|
||||
ApiUser.find(creator_str)
|
||||
ApiUser.find_by(id: creator_str)
|
||||
else
|
||||
AdminUser.find(creator_str)
|
||||
AdminUser.find_by(id: creator_str)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,9 +38,9 @@ module Versions
|
|||
return nil if updator_str.blank?
|
||||
|
||||
if updator_str =~ /^\d-api-/
|
||||
ApiUser.find(updator_str)
|
||||
ApiUser.find_by(id: updator_str)
|
||||
else
|
||||
AdminUser.find(updator_str)
|
||||
AdminUser.find_by(id: updator_str)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
include Versions # version/contact_version.rb
|
||||
include EppErrors
|
||||
|
||||
has_one :address, dependent: :destroy
|
||||
has_one :disclosure, class_name: 'ContactDisclosure', dependent: :destroy
|
||||
|
@ -19,25 +18,20 @@ class Contact < ActiveRecord::Base
|
|||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||
validates :email, format: /@/
|
||||
validates :ident, format: /\d{4}-\d{2}-\d{2}/, if: proc { |c| c.ident_type == 'birthday' }
|
||||
|
||||
validate :ident_must_be_valid
|
||||
|
||||
validates :code, uniqueness: { message: :epp_id_taken }
|
||||
|
||||
delegate :city, to: :address # , prefix: true
|
||||
delegate :street, to: :address # , prefix: true
|
||||
delegate :zip, to: :address # , prefix: true
|
||||
delegate :street, to: :address
|
||||
delegate :city, to: :address
|
||||
delegate :zip, to: :address
|
||||
delegate :state, to: :address
|
||||
delegate :country_code, to: :address
|
||||
delegate :country, to: :address
|
||||
|
||||
# callbacks
|
||||
# TODO: remove old
|
||||
# after_commit :domains_snapshot
|
||||
# after_update :domains_snapshot
|
||||
# after_destroy :domains_snapshot
|
||||
before_create :generate_code
|
||||
before_create :generate_auth_info
|
||||
after_create :ensure_disclosure
|
||||
|
||||
# scopes
|
||||
scope :current_registrars, ->(id) { where(registrar_id: id) }
|
||||
|
||||
IDENT_TYPE_ICO = 'ico'
|
||||
|
@ -54,6 +48,32 @@ class Contact < ActiveRecord::Base
|
|||
CONTACT_TYPE_ADMIN = 'admin'
|
||||
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||
|
||||
class << self
|
||||
def search_by_query(query)
|
||||
res = search(code_cont: query).result
|
||||
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << { code: x, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << { code: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def ident_must_be_valid
|
||||
# TODO: Ident can also be passport number or company registry code.
|
||||
# so have to make changes to validations (and doc/schema) accordingly
|
||||
|
@ -66,15 +86,6 @@ class Contact < ActiveRecord::Base
|
|||
create_disclosure! unless disclosure
|
||||
end
|
||||
|
||||
# TODO: remove old
|
||||
# def domains_snapshot
|
||||
# (domains + domains_owned).uniq.each do |domain|
|
||||
# next unless domain.is_a?(Domain)
|
||||
# # next if domain.versions.last == domain.create_snapshot
|
||||
# domain.create_version # Method from paper_trail
|
||||
# end
|
||||
# end
|
||||
|
||||
def juridical?
|
||||
ident_type == IDENT_TYPE_ICO
|
||||
end
|
||||
|
@ -83,18 +94,6 @@ class Contact < ActiveRecord::Base
|
|||
ident_type != IDENT_TYPE_ICO
|
||||
end
|
||||
|
||||
def cr_id
|
||||
# created_by ? created_by.username : nil
|
||||
end
|
||||
|
||||
def up_id
|
||||
# updated_by ? updated_by.username : nil
|
||||
end
|
||||
|
||||
def auth_info_matches(pw)
|
||||
auth_info == pw
|
||||
end
|
||||
|
||||
# generate random id for contact
|
||||
def generate_code
|
||||
self.code = SecureRandom.hex(4)
|
||||
|
@ -114,6 +113,8 @@ class Contact < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
# TODO: refactor, it should not allow to destroy with normal destroy,
|
||||
# no need separate method
|
||||
# should use only in transaction
|
||||
def destroy_and_clean
|
||||
if relations_with_domain?
|
||||
|
@ -122,76 +123,4 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
destroy
|
||||
end
|
||||
|
||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||
{
|
||||
'2302' => [ # Object exists
|
||||
[:code, :epp_id_taken]
|
||||
],
|
||||
'2305' => [ # Association exists
|
||||
[:domains, :exist]
|
||||
],
|
||||
'2005' => [ # Value syntax error
|
||||
[:phone, :invalid],
|
||||
[:email, :invalid],
|
||||
[:ident, :invalid]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
# TODO: remove old
|
||||
# for archiving
|
||||
# def snapshot
|
||||
# {
|
||||
# name: name,
|
||||
# phone: phone,
|
||||
# code: code,
|
||||
# ident: ident,
|
||||
# email: email
|
||||
# }
|
||||
# end
|
||||
|
||||
class << self
|
||||
# non-EPP
|
||||
|
||||
# EPP
|
||||
def extract_attributes(ph, _type = :create)
|
||||
ph[:postalInfo] = ph[:postalInfo].first if ph[:postalInfo].is_a?(Array)
|
||||
contact_hash = {
|
||||
phone: ph[:voice],
|
||||
ident: ph[:ident],
|
||||
ident_type: ph[:ident_type],
|
||||
email: ph[:email],
|
||||
fax: ph[:fax],
|
||||
name: ph[:postalInfo].try(:[], :name),
|
||||
org_name: ph[:postalInfo].try(:[], :org)
|
||||
}
|
||||
# contact_hash[:auth_info] = ph[:authInfo][:pw] if type == :create
|
||||
contact_hash.delete_if { |_k, v| v.nil? }
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << { code: x, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << { code: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
def search_by_query(query)
|
||||
res = search(code_cont: query).result
|
||||
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
87
app/models/epp/contact.rb
Normal file
87
app/models/epp/contact.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
# rubocop: disable Metrics/ClassLength
|
||||
class Epp::Contact < Contact
|
||||
include EppErrors
|
||||
|
||||
# disable STI, there is type column present
|
||||
self.inheritance_column = :sti_disabled
|
||||
|
||||
class << self
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def attrs_from(frame)
|
||||
f = frame
|
||||
at = {}.with_indifferent_access
|
||||
at[:name] = f.css('postalInfo name').text if f.css('postalInfo name').present?
|
||||
at[:org_name] = f.css('postalInfo org').text if f.css('postalInfo org').present?
|
||||
at[:email] = f.css('email').text if f.css('email').present?
|
||||
at[:fax] = f.css('fax').text if f.css('fax').present?
|
||||
at[:phone] = f.css('voice').text if f.css('voice').present?
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
|
||||
if f.css('ident').present? && f.css('ident').attr('type').present?
|
||||
at[:ident] = f.css('ident').text
|
||||
at[:ident_type] = f.css('ident').attr('type').text
|
||||
end
|
||||
|
||||
at[:address_attributes] = {}
|
||||
sat = at[:address_attributes]
|
||||
sat[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present?
|
||||
sat[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present?
|
||||
sat[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
|
||||
sat[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
|
||||
sat[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
at.delete(:address_attributes) if at[:address_attributes].blank?
|
||||
at
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
def new(frame)
|
||||
return super if frame.blank?
|
||||
super(attrs_from(frame))
|
||||
end
|
||||
|
||||
def parse_legal_document_from_frame(parsed_frame)
|
||||
ld = parsed_frame.css('legalDocument').first
|
||||
return nil unless ld
|
||||
|
||||
{
|
||||
body: ld.text,
|
||||
type: ld['type']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||
{
|
||||
'2302' => [ # Object exists
|
||||
[:code, :epp_id_taken]
|
||||
],
|
||||
'2305' => [ # Association exists
|
||||
[:domains, :exist]
|
||||
],
|
||||
'2005' => [ # Value syntax error
|
||||
[:phone, :invalid],
|
||||
[:email, :invalid],
|
||||
[:ident, :invalid]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def update_attributes(frame)
|
||||
return super if frame.blank?
|
||||
at = {}.with_indifferent_access
|
||||
at.deep_merge!(self.class.attrs_from(frame.css('chg')))
|
||||
super(at)
|
||||
end
|
||||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
|
||||
legal_documents.build(
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
|
@ -22,20 +22,20 @@
|
|||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'name', t('name'))
|
||||
= sort_link(@q, 'name', t(:name))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'code', t('code'))
|
||||
= sort_link(@q, 'ident', t(:identity))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'ident', t('identity_code'))
|
||||
= sort_link(@q, 'email', t(:email))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'email', t('email'))
|
||||
= sort_link(@q, 'code', t(:code))
|
||||
%tbody
|
||||
- @contacts.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, admin_contact_path(x))
|
||||
%td= x.code
|
||||
%td= x.ident
|
||||
%td= x.email
|
||||
%td= x.code
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @contacts
|
||||
|
|
|
@ -4,25 +4,17 @@
|
|||
.panel-body
|
||||
- unless @contact.address.nil?
|
||||
%dl.dl-horizontal
|
||||
%dt= t('country')
|
||||
%dd= @contact.address.country
|
||||
%dt= t('street')
|
||||
%dd= @contact.street
|
||||
|
||||
%dt= t('city')
|
||||
%dd= @contact.address.city
|
||||
|
||||
%dt= t('street')
|
||||
%dd= @contact.address.street
|
||||
|
||||
- if @contact.address.street2
|
||||
%dt= t('street')
|
||||
%dd= @contact.address.street2
|
||||
|
||||
- if @contact.address.street3
|
||||
%dt= t('street')
|
||||
%dd= @contact.address.street3
|
||||
|
||||
|
||||
%dd= @contact.city
|
||||
|
||||
%dt= t('zip')
|
||||
%dd= @contact.address.zip
|
||||
%dd= @contact.zip
|
||||
|
||||
%dt= t('state')
|
||||
%dd= @contact.state
|
||||
|
||||
%dt= t('country')
|
||||
%dd= @contact.country
|
||||
|
|
|
@ -3,30 +3,28 @@
|
|||
%h3.panel-title= t('general')
|
||||
.panel-body
|
||||
%dl.dl-horizontal
|
||||
%dt= t('name')
|
||||
%dd= @contact.name
|
||||
%dt= t(:ident)
|
||||
%dd= @contact.ident + ' [' + @contact.ident_type + ']'
|
||||
|
||||
%dt= t('org_name')
|
||||
%dd= @contact.org_name
|
||||
%br
|
||||
|
||||
%dt= t('code')
|
||||
%dd= @contact.code
|
||||
|
||||
%dt= t('ident')
|
||||
%dd= @contact.ident
|
||||
|
||||
%dt= t('ident_type')
|
||||
%dd= @contact.ident_type
|
||||
|
||||
%dt= t('email')
|
||||
%dt= t(:email)
|
||||
%dd= @contact.email
|
||||
|
||||
%dt= t('phone')
|
||||
%dt= t(:phone)
|
||||
%dd= @contact.phone
|
||||
|
||||
%dt= t(:org_name)
|
||||
%dd= @contact.org_name
|
||||
|
||||
- if @contact.fax
|
||||
%dt= t('fax')
|
||||
%dt= t(:fax)
|
||||
%dd= @contact.fax
|
||||
|
||||
%br
|
||||
|
||||
%dt= t(:code)
|
||||
%dd= @contact.code
|
||||
|
||||
%dt= t('password')
|
||||
%dd= @contact.auth_info
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.row
|
||||
.col-sm-12
|
||||
%h2.text-center-xs
|
||||
= "#{t('contact_details')}"
|
||||
= @contact.name
|
||||
%hr
|
||||
.row
|
||||
.col-md-6= render 'admin/contacts/partials/general'
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
address = @contact.address
|
||||
xml.tag!('contact:postalInfo', type: 'int') do
|
||||
xml.tag!('contact:name', @contact.name) if @disclosure.try(:[], :name) || @owner
|
||||
xml.tag!('contact:org', @contact.org_name) if @disclosure.try(:[], :org_name) || @owner
|
||||
if @disclosure.try(:addr) || @owner
|
||||
xml.tag!('contact:name', @contact.name) #if @disclosure.try(:[], :name) || @owner
|
||||
xml.tag!('contact:org', @contact.org_name) #if @disclosure.try(:[], :org_name) || @owner
|
||||
# if @disclosure.try(:addr) || @owner
|
||||
xml.tag!('contact:addr') do
|
||||
xml.tag!('contact:street', address.street) if address
|
||||
xml.tag!('contact:cc', address.country_code) unless address.country_code.nil?
|
||||
xml.tag!('contact:city', address.city) if address
|
||||
xml.tag!('contact:street', @contact.street)
|
||||
xml.tag!('contact:city', @contact.city)
|
||||
xml.tag!('contact:pc', @contact.zip)
|
||||
xml.tag!('contact:sp', @contact.state)
|
||||
xml.tag!('contact:cc', @contact.country_code)
|
||||
end
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@ xml.epp_head do
|
|||
|
||||
xml.resData do
|
||||
xml.tag!('contact:chkData', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||
#xml.tag!('contact:id', @contact.code)
|
||||
@contacts.each do |contact|
|
||||
@results.each do |result|
|
||||
xml.tag!('contact:cd') do
|
||||
xml.tag! "contact:id", contact[:code], avail: contact[:avail]
|
||||
xml.tag!('contact:reason', contact[:reason]) unless contact[:avail] == 1
|
||||
xml.tag! "contact:id", result[:code], avail: result[:avail]
|
||||
xml.tag!('contact:reason', result[:reason]) unless result[:avail] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,9 +8,9 @@ xml.epp_head do
|
|||
xml.tag!('contact:chkData', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||
xml.tag!('contact:id', @contact.code)
|
||||
xml << render('/epp/contacts/postal_info')
|
||||
xml.tag!('contact:voice', @contact.phone) if @disclosure.try(:phone) || @owner
|
||||
xml.tag!('contact:fax', @contact.fax) if @disclosure.try(:fax) || @owner
|
||||
xml.tag!('contact:email', @contact.email) if @disclosure.try(:email) || @owner
|
||||
xml.tag!('contact:voice', @contact.phone) #if @disclosure.try(:phone) || @owner
|
||||
xml.tag!('contact:fax', @contact.fax) #if @disclosure.try(:fax) || @owner
|
||||
xml.tag!('contact:email', @contact.email) #if @disclosure.try(:email) || @owner
|
||||
xml.tag!('contact:clID', @contact.registrar.try(:name))
|
||||
xml.tag!('contact:crID', @contact.creator.try(:registrar))
|
||||
xml.tag!('contact:crDate', @contact.created_at)
|
||||
|
@ -19,17 +19,16 @@ xml.epp_head do
|
|||
xml.tag!('contact:upDate', @contact.updated_at)
|
||||
end
|
||||
xml.tag!('contact:ident', @contact.ident, type: @contact.ident_type)
|
||||
xml.tag!('contact:trDate', '123') if false
|
||||
if @owner
|
||||
# xml.tag!('contact:trDate', '123') if false
|
||||
if can? :view_password, @contact
|
||||
xml.tag!('contact:authInfo') do
|
||||
xml.tag!('contact:pw', @contact.auth_info) # Doc says we have to return this but is it necessary?
|
||||
xml.tag!('contact:pw', @contact.auth_info)
|
||||
end
|
||||
end
|
||||
# statuses
|
||||
@contact.statuses.each do |cs|
|
||||
xml.tag!('contact:status', s: cs.value)
|
||||
@contact.statuses.each do |status|
|
||||
xml.tag!('contact:status', s: status.value)
|
||||
end
|
||||
xml << render('/epp/contacts/disclosure_policy')
|
||||
# xml << render('/epp/contacts/disclosure_policy')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue