rubocop update, now it's green

This commit is contained in:
Priit Tamboom 2014-10-10 16:11:28 +03:00
parent 2d6ed7fa45
commit 8d189023c7
29 changed files with 190 additions and 54 deletions

View file

@ -53,6 +53,7 @@ class Admin::UsersController < AdminController
end
def user_params
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id, :admin, :registrar_typeahead, :country_id)
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id,
:admin, :registrar_typeahead, :country_id)
end
end

View file

@ -12,10 +12,12 @@ class Client::ContactsController < ClientController
end
def show
# rubocop: disable Style/GuardClause
if @contact.registrar != current_registrar
flash[:alert] = I18n.t('shared.authentication_error')
redirect_to client_contacts_path
end
# rubocop: enable Style/GuardClause
end
def create

View file

@ -12,6 +12,8 @@ class Client::DomainTransfersController < ClientController
@domain_transfer = DomainTransfer.new
end
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def create
@domain_transfer = @domain.pending_transfer
@ -36,6 +38,8 @@ class Client::DomainTransfersController < ClientController
redirect_to [:client, @domain_transfer]
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
def approve
if can? :approve_as_client, @domain_transfer
@ -63,6 +67,8 @@ class Client::DomainTransfersController < ClientController
}
end
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def set_domain
@domain_transfer = DomainTransfer.new
@domain = Domain.find_by(name: params[:domain_name])
@ -81,4 +87,6 @@ class Client::DomainTransfersController < ClientController
render 'new'
end
end
# rubocop: enbale Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
end

View file

@ -14,7 +14,9 @@ module Epp::Common
end
def proxy
@svTRID = "ccReg-#{'%010d' % rand(10**10)}"
# rubocop: disable Style/VariableName
@svTRID = "ccReg-#{format('%010d', rand(10**10))}"
# rubocop: enable Style/VariableName
send(params[:command])
end
@ -46,7 +48,10 @@ module Epp::Common
end
# for debugging
@errors << { code: '1', msg: 'handle_errors was executed when there were actually no errors' } if @errors.blank?
@errors << {
code: '1',
msg: 'handle_errors was executed when there were actually no errors'
} if @errors.blank?
@errors.uniq!
@ -60,7 +65,10 @@ module Epp::Common
def xml_attrs_present?(ph, attributes)
attributes.each do |x|
epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: x.last) } unless has_attribute(ph, x)
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)
} unless has_attribute(ph, x)
end
epp_errors.empty?
end
@ -68,24 +76,27 @@ module Epp::Common
def xml_attrs_array_present?(array_ph, attributes)
[array_ph].flatten.each do |ph|
attributes.each do |x|
unless has_attribute(ph, x)
epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: x.last) }
end
next if has_attribute(ph, x)
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)
}
end
end
epp_errors.empty?
end
# rubocop: disable Style/PredicateName
def has_attribute(ph, path)
path.reduce(ph) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
# rubocop: enable Style/PredicateName
def validate_request
validation_method = "validate_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}_#{params[:command]}_request"
if respond_to?(validation_method, true)
handle_errors and return unless send(validation_method)
end
return unless respond_to?(validation_method, true)
handle_errors and return unless send(validation_method)
end
end

View file

@ -20,6 +20,7 @@ module Epp::ContactsHelper
end
end
# rubocop:disable Metrics/CyclomaticComplexity
def delete_contact
@contact = find_contact
handle_errors(@contact) and return unless owner?
@ -28,6 +29,7 @@ module Epp::ContactsHelper
render '/epp/contacts/delete'
end
# rubocop:enable Metrics/CyclomaticComplexity
def check_contact
ph = params_hash['epp']['command']['check']['check']

View file

@ -43,6 +43,7 @@ module Epp::DomainsHelper
render '/epp/domains/info'
end
# rubocop:disable Metrics/CyclomaticComplexity
def update_domain
Epp::EppDomain.transaction do
@domain = find_domain
@ -66,6 +67,7 @@ module Epp::DomainsHelper
render '/epp/domains/success'
end
end
# rubocop:enable Metrics/CyclomaticComplexity
def transfer_domain
@domain = find_domain(secure: false)
@ -76,6 +78,7 @@ module Epp::DomainsHelper
render '/epp/domains/transfer'
end
# rubocop:disable Metrics/CyclomaticComplexity
def delete_domain
@domain = find_domain
@ -85,6 +88,7 @@ module Epp::DomainsHelper
render '/epp/domains/success'
end
# rubocop:enbale Metrics/CyclomaticComplexity
### HELPER METHODS ###
@ -156,12 +160,20 @@ module Epp::DomainsHelper
domain = Epp::EppDomain.find_by(name: @ph[:name])
unless domain
epp_errors << { code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: { obj: 'name', val: @ph[:name] } }
epp_errors << {
code: '2303',
msg: I18n.t('errors.messages.epp_domain_not_found'),
value: { obj: 'name', val: @ph[:name] }
}
return nil
end
if domain.registrar != current_epp_user.registrar && secure[:secure] == true
epp_errors << { code: '2302', msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'), value: { obj: 'name', val: @ph[:name] } }
epp_errors << {
code: '2302',
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),
value: { obj: 'name', val: @ph[:name] }
}
return nil
end

View file

@ -1,6 +1,8 @@
class Ability
include CanCan::Ability
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/CyclomaticComplexity
def initialize(user)
alias_action :create, :read, :update, :destroy, to: :crud
@ -66,4 +68,6 @@ class Ability
# See the wiki for details:
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
end
# rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/CyclomaticComplexity
end

View file

@ -17,12 +17,20 @@ class Address < ActiveRecord::Base
# errors, used = [], []
# parsed_frame.css('postalInfo').each do |pi|
# attr = pi.attributes['type'].try(:value)
# errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type') } and next unless attr
# errors << {
# code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')
# } and next unless attr
# unless TYPES.include?(attr)
# errors << { code: 2005, msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr } }
# errors << {
# code: 2005,
# msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }
# }
# next
# end
# errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr)
# errors << {
# code: 2005,
# msg: I18n.t('errors.messages.repeating_postal_info')
# } and next if used.include?(attr)
# used << attr
# end; errors
# end

View file

@ -33,7 +33,7 @@ module EppErrors
def collect_child_errors(key)
macro = self.class.reflect_on_association(key).macro
multi = [:has_and_belongs_to_many, :has_many]
single = [:belongs_to, :has_one]
# single = [:belongs_to, :has_one]
epp_errors = []
send(key).each do |x|

View file

@ -13,7 +13,7 @@ class Contact < ActiveRecord::Base
has_many :domain_contacts
has_many :domains, through: :domain_contacts
# TODO remove the x_by
# TODO: remove the x_by
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
belongs_to :registrar
@ -160,6 +160,4 @@ class Contact < ActiveRecord::Base
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
end
end
private
end

View file

@ -1,6 +1,6 @@
class Domain < ActiveRecord::Base
# TODO whois requests ip whitelist for full info for own domains and partial info for other domains
# TODO most inputs should be trimmed before validatation, probably some global logic?
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
# TODO: most inputs should be trimmed before validatation, probably some global logic?
paginates_per 10 # just for showoff
belongs_to :registrar
@ -9,13 +9,13 @@ class Domain < ActiveRecord::Base
has_many :domain_contacts, dependent: :delete_all
accepts_nested_attributes_for :domain_contacts, allow_destroy: true
has_many :tech_contacts, -> do
where(domain_contacts: { contact_type: DomainContact::TECH })
end, through: :domain_contacts, source: :contact
has_many :tech_contacts,
-> { where(domain_contacts: { contact_type: DomainContact::TECH }) },
through: :domain_contacts, source: :contact
has_many :admin_contacts, -> do
where(domain_contacts: { contact_type: DomainContact::ADMIN })
end, through: :domain_contacts, source: :contact
has_many :admin_contacts,
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
through: :domain_contacts, source: :contact
has_many :nameservers, dependent: :delete_all
accepts_nested_attributes_for :nameservers, allow_destroy: true,
@ -64,9 +64,9 @@ class Domain < ActiveRecord::Base
def name=(value)
value.strip!
write_attribute(:name, SimpleIDN.to_unicode(value))
write_attribute(:name_puny, SimpleIDN.to_ascii(value))
write_attribute(:name_dirty, value)
self[:name] = SimpleIDN.to_unicode(value)
self[:name_puny] = SimpleIDN.to_ascii(value)
self[:name_dirty] = value
end
def owner_contact_typeahead
@ -214,11 +214,13 @@ class Domain < ActiveRecord::Base
name
end
# rubocop:disable Lint/Loop
def generate_auth_info
begin
self.auth_info = SecureRandom.hex
end while self.class.exists?(auth_info: auth_info)
end
# rubocop:enable Lint/Loop
def attach_default_contacts
tech_contacts << owner_contact if tech_contacts_count.zero?

View file

@ -29,9 +29,26 @@ class DomainStatus < ActiveRecord::Base
DELETE_CANDIDATE = 'deleteCandidate'
EXPIRED = 'expired'
STATUSES = [CLIENT_DELETE_PROHIBITED, SERVER_DELETE_PROHIBITED, CLIENT_HOLD, SERVER_HOLD, CLIENT_RENEW_PROHIBITED, SERVER_RENEW_PROHIBITED, CLIENT_TRANSFER_PROHIBITED, SERVER_TRANSFER_PROHIBITED, CLIENT_UPDATE_PROHIBITED, SERVER_UPDATE_PROHIBITED, INACTIVE, OK, PENDING_CREATE, PENDING_DELETE, PENDING_RENEW, PENDING_TRANSFER, PENDING_UPDATE, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED, SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED, FORCE_DELETE, DELETE_CANDIDATE, EXPIRED]
CLIENT_STATUSES = [CLIENT_DELETE_PROHIBITED, CLIENT_HOLD, CLIENT_RENEW_PROHIBITED, CLIENT_TRANSFER_PROHIBITED, CLIENT_UPDATE_PROHIBITED]
SERVER_STATUSES = [SERVER_DELETE_PROHIBITED, SERVER_HOLD, SERVER_RENEW_PROHIBITED, SERVER_TRANSFER_PROHIBITED, SERVER_UPDATE_PROHIBITED, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED, SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED]
STATUSES = [
CLIENT_DELETE_PROHIBITED, SERVER_DELETE_PROHIBITED, CLIENT_HOLD, SERVER_HOLD,
CLIENT_RENEW_PROHIBITED, SERVER_RENEW_PROHIBITED, CLIENT_TRANSFER_PROHIBITED,
SERVER_TRANSFER_PROHIBITED, CLIENT_UPDATE_PROHIBITED, SERVER_UPDATE_PROHIBITED,
INACTIVE, OK, PENDING_CREATE, PENDING_DELETE, PENDING_RENEW, PENDING_TRANSFER,
PENDING_UPDATE, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED,
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED, FORCE_DELETE,
DELETE_CANDIDATE, EXPIRED
]
CLIENT_STATUSES = [
CLIENT_DELETE_PROHIBITED, CLIENT_HOLD, CLIENT_RENEW_PROHIBITED, CLIENT_TRANSFER_PROHIBITED,
CLIENT_UPDATE_PROHIBITED
]
SERVER_STATUSES = [
SERVER_DELETE_PROHIBITED, SERVER_HOLD, SERVER_RENEW_PROHIBITED, SERVER_TRANSFER_PROHIBITED,
SERVER_UPDATE_PROHIBITED, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED,
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED
]
# archiving
has_paper_trail class_name: 'DomainStatusVersion'

View file

@ -1,3 +1,4 @@
# rubocop: disable Metrics/ClassLength
class Epp::EppDomain < Domain
include EppErrors
@ -211,6 +212,9 @@ class Epp::EppDomain < Domain
### TRANSFER ###
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/CyclomaticComplexity
def transfer(params)
return false unless authenticate(params[:pw])
@ -249,6 +253,9 @@ class Epp::EppDomain < Domain
save
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/CyclomaticComplexity
def approve_pending_transfer(current_user)
pt = pending_transfer
@ -397,3 +404,4 @@ class Epp::EppDomain < Domain
end
end
end
# rubocop: enable Metrics/ClassLength

View file

@ -2,7 +2,7 @@ class EppSession < ActiveRecord::Base
before_save :marshal_data!
def data
@data ||= self.class.unmarshal(read_attribute(:data)) || {}
@data ||= self.class.unmarshal(self[:data]) || {}
end
def [](key)

View file

@ -1,5 +1,6 @@
# rubocop: disable Metrics/ClassLength
class EppUser < ActiveRecord::Base
# TODO should have max request limit per day
# TODO: should have max request limit per day
belongs_to :registrar
has_many :contacts
@ -16,3 +17,4 @@ class EppUser < ActiveRecord::Base
username
end
end
# rubocop: enable Metrics/ClassLength

View file

@ -4,9 +4,11 @@ class Nameserver < ActiveRecord::Base
belongs_to :registrar
belongs_to :domain
# 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 :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 :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
# rubocop: enable Metrics/LineLength
# archiving
has_paper_trail class_name: 'NameserverVersion'

View file

@ -1,3 +1,5 @@
class Right < ActiveRecord::Base
# rubocop: disable Rails/HasAndBelongsToMany
has_and_belongs_to_many :roles
# rubocop: enable Rails/HasAndBelongsToMany
end

View file

@ -1,4 +1,6 @@
class Role < ActiveRecord::Base
has_many :users
# rubocop: disable Rails/HasAndBelongsToMany
has_and_belongs_to_many :rights
# rubocop: enbale Rails/HasAndBelongsToMany
end

View file

@ -2,9 +2,9 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :trackable, :timeoutable
# TODO Foreign user will get email with activation link,email,temp-password.
# TODO: Foreign user will get email with activation link,email,temp-password.
# After activisation, system should require to change temp password.
# TODO Estonian id validation
# TODO: Estonian id validation
belongs_to :role
belongs_to :registrar

View file

@ -28,10 +28,14 @@ class DomainNameValidator < ActiveModel::EachValidator
value = SimpleIDN.to_unicode(value).mb_chars.downcase.strip
end
# rubocop: disable Metrics/LineLength
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
regexp = /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
# rubocop: enable Metrics/LineLength
# rubocop: disable Style/DoubleNegation
!!(value =~ regexp)
# rubocop: enable Style/DoubleNegation
end
def validate_reservation(value)