mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 22:46:22 +02:00
Merge branch 'master' into 2236-removing-old-validation-events
This commit is contained in:
commit
bbc1380e46
169 changed files with 2190 additions and 1340 deletions
|
@ -12,7 +12,7 @@ class Ability
|
|||
@user.roles&.each { |role| send(role) }
|
||||
when 'ApiUser'
|
||||
@user.roles&.each { |role| send(role) }
|
||||
when 'RegistrantUser'
|
||||
when 'RegistrantUser'
|
||||
static_registrant
|
||||
end
|
||||
|
||||
|
@ -95,6 +95,7 @@ class Ability
|
|||
can :manage, User
|
||||
can :manage, ApiUser
|
||||
can :manage, AdminUser
|
||||
can :manage, Auction
|
||||
can :manage, Certificate
|
||||
can :manage, LegalDocument
|
||||
can :manage, BankStatement
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class Account < ApplicationRecord
|
||||
extend ToCsv
|
||||
include Versions
|
||||
|
||||
belongs_to :registrar, required: true
|
||||
|
@ -12,4 +11,12 @@ class Account < ApplicationRecord
|
|||
def activities
|
||||
account_activities
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[id, balance, currency, registrar]
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Id', 'Balance', 'Currency', 'Registrar']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ class AccountActivity < ApplicationRecord
|
|||
UPDATE_CREDIT = 'update_credit'.freeze
|
||||
|
||||
after_create :update_balance
|
||||
|
||||
def update_balance
|
||||
account.balance += sum
|
||||
account.save
|
||||
|
@ -19,23 +20,17 @@ class AccountActivity < ApplicationRecord
|
|||
save
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[account.registrar.try(:code), description, I18n.t(activity_type), I18n.l(created_at), sum]
|
||||
end
|
||||
|
||||
class << self
|
||||
def types_for_select
|
||||
[CREATE, RENEW, ADD_CREDIT, UPDATE_CREDIT].map { |x| [I18n.t(x), x] }
|
||||
end
|
||||
|
||||
def to_csv
|
||||
attributes = %w(description activity_type created_at sum)
|
||||
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << %w(registrar description activity_type receipt_date sum)
|
||||
|
||||
all.each do |x|
|
||||
attrs = [x.account.registrar.try(:code)]
|
||||
attrs += attributes.map { |attr| x.send(attr) }
|
||||
csv << attrs
|
||||
end
|
||||
end
|
||||
def csv_header
|
||||
['Registrar', 'Description', 'Activity Type', 'Receipt Date', 'Sum']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,18 +2,40 @@ class Action < ApplicationRecord
|
|||
has_paper_trail versions: { class_name: 'Version::ActionVersion' }
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :contact
|
||||
belongs_to :contact, optional: true
|
||||
has_many :subactions, class_name: 'Action',
|
||||
foreign_key: 'bulk_action_id',
|
||||
inverse_of: :bulk_action,
|
||||
dependent: :destroy
|
||||
belongs_to :bulk_action, class_name: 'Action', optional: true
|
||||
|
||||
validates :operation, inclusion: { in: proc { |action| action.class.valid_operations } }
|
||||
|
||||
class << self
|
||||
def valid_operations
|
||||
%w[update]
|
||||
%w[update bulk_update]
|
||||
end
|
||||
end
|
||||
|
||||
def notification_key
|
||||
raise 'Action object is missing' unless contact
|
||||
raise 'Action object is missing' unless bulk_action? || contact
|
||||
|
||||
"contact_#{operation}".to_sym
|
||||
end
|
||||
|
||||
def bulk_action?
|
||||
!!subactions.exists?
|
||||
end
|
||||
|
||||
def to_non_available_contact_codes
|
||||
return [] unless bulk_action?
|
||||
|
||||
subactions.map do |a|
|
||||
{
|
||||
code: a.contact.code,
|
||||
avail: 0,
|
||||
reason: 'in use',
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
module ApiLog
|
||||
class EppLog < Db
|
||||
extend ToCsv
|
||||
end
|
||||
class EppLog < Db; end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
module ApiLog
|
||||
class ReppLog < Db
|
||||
extend ToCsv
|
||||
end
|
||||
class ReppLog < Db; end
|
||||
end
|
||||
|
|
|
@ -9,11 +9,30 @@ class Auction < ApplicationRecord
|
|||
domain_not_registered: 'domain_not_registered',
|
||||
}
|
||||
|
||||
enum platform: %i[auto manual]
|
||||
|
||||
PENDING_STATUSES = [statuses[:started],
|
||||
statuses[:awaiting_payment],
|
||||
statuses[:payment_received]].freeze
|
||||
|
||||
private_constant :PENDING_STATUSES
|
||||
|
||||
scope :with_status, ->(status) {
|
||||
where(status: status) if status.present?
|
||||
}
|
||||
|
||||
scope :with_start_created_at_date, ->(start_created_at) {
|
||||
where('created_at >= ?', start_created_at) if start_created_at.present?
|
||||
}
|
||||
|
||||
scope :with_end_created_at_date, ->(end_created_at) {
|
||||
where('created_at <= ?', end_created_at) if end_created_at.present?
|
||||
}
|
||||
|
||||
scope :with_domain_name, ->(domain_name) {
|
||||
where('domain ilike ?', "%#{domain_name.strip}%") if domain_name.present?
|
||||
}
|
||||
|
||||
def self.pending(domain_name)
|
||||
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
class BlockedDomain < ApplicationRecord
|
||||
include Versions
|
||||
extend ToCsv
|
||||
before_save :generate_data
|
||||
after_destroy :remove_data
|
||||
|
||||
|
|
1
app/models/bulk_action.rb
Normal file
1
app/models/bulk_action.rb
Normal file
|
@ -0,0 +1 @@
|
|||
class BulkAction < Action; end
|
|
@ -1,22 +0,0 @@
|
|||
module Contact::Disclosable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
attr_accessor :disclosable_attributes
|
||||
end
|
||||
|
||||
included do
|
||||
self.disclosable_attributes = %w[name email]
|
||||
validate :validate_disclosed_attributes
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_disclosed_attributes
|
||||
return if disclosed_attributes.empty?
|
||||
|
||||
has_undisclosable_attributes = (disclosed_attributes - self.class.disclosable_attributes)
|
||||
.any?
|
||||
errors.add(:disclosed_attributes, :invalid) if has_undisclosable_attributes
|
||||
end
|
||||
end
|
|
@ -34,13 +34,7 @@ module Domain::ForceDelete
|
|||
reason = explicit&.downcase
|
||||
return reason if %w[invalid_email invalid_phone].include?(reason)
|
||||
|
||||
if contact_emails_verification_failed.present?
|
||||
'invalid_email'
|
||||
elsif registrant.org?
|
||||
'legal_person'
|
||||
else
|
||||
'private_person'
|
||||
end
|
||||
registrant.org? ? 'legal_person' : 'private_person'
|
||||
end
|
||||
|
||||
def force_delete_scheduled?
|
||||
|
|
|
@ -5,10 +5,6 @@ module EmailVerifable
|
|||
scope :recently_not_validated, -> { where.not(id: ValidationEvent.validated_ids_by(name)) }
|
||||
end
|
||||
|
||||
def email_verification_failed?
|
||||
need_to_start_force_delete?
|
||||
end
|
||||
|
||||
def validate_email_data(level:, count:)
|
||||
validation_events.order(created_at: :desc).limit(count).all? do |event|
|
||||
event.check_level == level.to_s && event.failed?
|
||||
|
@ -18,9 +14,7 @@ module EmailVerifable
|
|||
def need_to_start_force_delete?
|
||||
flag = false
|
||||
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count|
|
||||
if validation_events.count >= count && validate_email_data(level: level, count: count)
|
||||
flag = true
|
||||
end
|
||||
flag = true if validation_events.count >= count && validate_email_data(level: level, count: count)
|
||||
end
|
||||
|
||||
flag
|
||||
|
|
|
@ -7,7 +7,6 @@ class Contact < ApplicationRecord
|
|||
include UserEvents
|
||||
include Contact::Transferable
|
||||
include Contact::Identical
|
||||
include Contact::Disclosable
|
||||
include Contact::Archivable
|
||||
include EmailVerifable
|
||||
|
||||
|
@ -16,7 +15,7 @@ class Contact < ApplicationRecord
|
|||
has_many :domain_contacts
|
||||
has_many :domains, through: :domain_contacts
|
||||
has_many :legal_documents, as: :documentable
|
||||
has_many :validation_events, as: :validation_eventable
|
||||
has_many :validation_events, as: :validation_eventable, dependent: :destroy
|
||||
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
|
||||
has_many :actions, dependent: :destroy
|
||||
|
||||
|
@ -25,10 +24,18 @@ class Contact < ApplicationRecord
|
|||
alias_attribute :kind, :ident_type
|
||||
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
||||
|
||||
scope :email_verification_failed, lambda {
|
||||
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
||||
.where('success = false and verified_at IS NOT NULL')
|
||||
}
|
||||
scope :with_different_company_name, (lambda do |company|
|
||||
where("ident = ? AND ident_country_code = 'EE' AND name != ?",
|
||||
company.registration_number,
|
||||
company.company_name)
|
||||
end)
|
||||
|
||||
scope :with_different_registrant_name, (lambda do |user|
|
||||
where('ident = ? AND ident_country_code = ? AND UPPER(name) != UPPER(?)',
|
||||
user.ident,
|
||||
user.country.alpha2,
|
||||
user.username)
|
||||
end)
|
||||
|
||||
NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]|
|
||||
[\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x
|
||||
|
@ -42,7 +49,7 @@ class Contact < ApplicationRecord
|
|||
|
||||
validates :phone, presence: true, e164: true, phone: true
|
||||
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
# validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
|
||||
validates :code,
|
||||
uniqueness: { message: :epp_id_taken },
|
||||
|
@ -188,15 +195,6 @@ class Contact < ApplicationRecord
|
|||
]
|
||||
end
|
||||
|
||||
def to_csv
|
||||
CSV.generate do |csv|
|
||||
csv << column_names
|
||||
all.each do |contact|
|
||||
csv << contact.attributes.values_at(*column_names)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pdf(html)
|
||||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
|
@ -569,4 +567,27 @@ class Contact < ApplicationRecord
|
|||
def deletable?
|
||||
!linked?
|
||||
end
|
||||
|
||||
def ident_human_description
|
||||
description = "[#{ident_country_code} #{ident_type}]"
|
||||
description.prepend("#{ident} ") if ident.present?
|
||||
|
||||
description
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[
|
||||
name,
|
||||
code,
|
||||
ident_human_description,
|
||||
email,
|
||||
created_at.to_formatted_s(:db),
|
||||
registrar,
|
||||
phone,
|
||||
]
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Name', 'ID', 'Ident', 'E-mail', 'Created at', 'Registrar', 'Phone']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,8 @@ module Depp
|
|||
attr_accessor :id, :name, :email, :phone, :org_name,
|
||||
:ident, :ident_type, :ident_country_code,
|
||||
:street, :city, :zip, :state, :country_code,
|
||||
:password, :legal_document, :statuses, :code
|
||||
:password, :legal_document, :statuses, :code,
|
||||
:email_history
|
||||
|
||||
DISABLED = 'Disabled'
|
||||
DISCLOSURE_TYPES = [DISABLED, '1', '0']
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class Dispute < ApplicationRecord
|
||||
extend ToCsv
|
||||
include WhoisStatusPopulate
|
||||
validates :domain_name, :password, :starts_at, :expires_at, presence: true
|
||||
before_validation :fill_empty_passwords, :set_expiry_date
|
||||
|
|
|
@ -35,6 +35,7 @@ module DNS
|
|||
def sell_at_auction
|
||||
auction = Auction.new
|
||||
auction.domain = name
|
||||
auction.platform = 'auto'
|
||||
auction.start
|
||||
ToStdout.msg "Created the auction: #{auction.inspect}"
|
||||
update_whois_from_auction(auction)
|
||||
|
|
|
@ -161,14 +161,6 @@ class Domain < ApplicationRecord
|
|||
attribute: 'hostname'
|
||||
}
|
||||
|
||||
validates :tech_domain_contacts, uniqueness_multi: {
|
||||
attribute: 'contact_code_cache'
|
||||
}
|
||||
|
||||
validates :admin_domain_contacts, uniqueness_multi: {
|
||||
attribute: 'contact_code_cache'
|
||||
}
|
||||
|
||||
validates :dnskeys, uniqueness_multi: {
|
||||
attribute: 'public_key'
|
||||
}
|
||||
|
@ -289,21 +281,6 @@ class Domain < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def to_csv
|
||||
CSV.generate do |csv|
|
||||
headers = column_names.dup
|
||||
swap_elements(headers, [[0, 1], [1, 5]])
|
||||
headers[0] = 'Domain'
|
||||
headers[1] = headers[1].humanize
|
||||
csv << headers
|
||||
all.find_each do |item|
|
||||
row = item.attributes.values_at(*column_names)
|
||||
swap_elements(row, [[0, 1], [1, 5]])
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def registrant_user_domains_by_registrant(registrant_user)
|
||||
|
@ -749,8 +726,36 @@ class Domain < ApplicationRecord
|
|||
DNS::DomainName.new(name)
|
||||
end
|
||||
|
||||
def contact_emails_verification_failed
|
||||
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
|
||||
def as_csv_row
|
||||
[
|
||||
name,
|
||||
registrant_name,
|
||||
valid_to.to_formatted_s(:db),
|
||||
registrar,
|
||||
created_at.to_formatted_s(:db),
|
||||
statuses,
|
||||
contacts.pluck(:code),
|
||||
force_delete_date,
|
||||
force_delete_data,
|
||||
]
|
||||
end
|
||||
|
||||
def registrant_name
|
||||
return registrant.name if registrant
|
||||
|
||||
ver = Version::ContactVersion.where(item_id: registrant_id).last
|
||||
contact = Contact.all_versions_for([registrant_id], created_at).first
|
||||
|
||||
contact = ObjectVersionsParser.new(ver).parse if contact.nil? && ver
|
||||
|
||||
contact.try(:name) || 'Deleted'
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
[
|
||||
'Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at',
|
||||
'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'
|
||||
]
|
||||
end
|
||||
|
||||
def self.pdf(html)
|
||||
|
|
|
@ -6,32 +6,21 @@ class DomainContact < ApplicationRecord
|
|||
belongs_to :contact
|
||||
belongs_to :domain
|
||||
|
||||
validates :contact, presence: true
|
||||
|
||||
after_destroy :update_contact
|
||||
attr_accessor :value_typeahead
|
||||
attr_writer :contact_code
|
||||
|
||||
self.ignored_columns = %w[legacy_domain_id legacy_contact_id]
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [
|
||||
[:contact_code_cache, :taken, { value: { obj: 'contact', val: contact_code_cache } }]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def name
|
||||
return 'Tech' if type == 'TechDomainContact'
|
||||
return 'Admin' if type == 'AdminDomainContact'
|
||||
|
||||
''
|
||||
end
|
||||
|
||||
validates :contact, presence: true
|
||||
|
||||
before_save :update_contact_code_cache
|
||||
def update_contact_code_cache
|
||||
self.contact_code_cache = contact.code
|
||||
end
|
||||
|
||||
after_destroy :update_contact
|
||||
def update_contact
|
||||
Contact.find(contact_id).save
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ class Epp::Contact < Contact
|
|||
codes = codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }
|
||||
|
||||
res = []
|
||||
codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }.map { |c| c.strip.upcase }.each do |x|
|
||||
codes.map { |c| c.strip.upcase }.each do |x|
|
||||
c = find_by_epp_code(x)
|
||||
res << (c ? { code: c.code, avail: 0, reason: 'in use' } : { code: x, avail: 1 })
|
||||
end
|
||||
|
|
|
@ -3,7 +3,6 @@ class Invoice < ApplicationRecord
|
|||
include Invoice::Cancellable
|
||||
include Invoice::Payable
|
||||
include Invoice::BookKeeping
|
||||
extend ToCsv
|
||||
|
||||
belongs_to :buyer, class_name: 'Registrar'
|
||||
has_one :account_activity
|
||||
|
@ -117,6 +116,23 @@ class Invoice < ApplicationRecord
|
|||
e_invoice_sent_at.present?
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[
|
||||
number,
|
||||
buyer,
|
||||
cancelled? ? I18n.t(:cancelled) : due_date,
|
||||
receipt_date_status,
|
||||
issue_date,
|
||||
total,
|
||||
currency,
|
||||
seller_name,
|
||||
]
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name']
|
||||
end
|
||||
|
||||
def self.create_from_transaction!(transaction)
|
||||
registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number)
|
||||
return unless registrar_user
|
||||
|
@ -128,6 +144,16 @@ class Invoice < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def receipt_date_status
|
||||
if paid?
|
||||
receipt_date
|
||||
elsif cancelled?
|
||||
I18n.t(:cancelled)
|
||||
else
|
||||
I18n.t(:unpaid)
|
||||
end
|
||||
end
|
||||
|
||||
def apply_default_buyer_vat_no
|
||||
self.buyer_vat_no = buyer.vat_no
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class Notification < ApplicationRecord
|
|||
include Versions # version/notification_version.rb
|
||||
|
||||
belongs_to :registrar
|
||||
belongs_to :action
|
||||
belongs_to :action, optional: true
|
||||
|
||||
scope :unread, -> { where(read: false) }
|
||||
|
||||
|
|
|
@ -20,49 +20,45 @@ class RegistrantUser < User
|
|||
def companies(company_register = CompanyRegister::Client.new)
|
||||
return [] if ident.include?('-')
|
||||
|
||||
companies = company_register.representation_rights(citizen_personal_code: ident,
|
||||
citizen_country_code: country.alpha3)
|
||||
|
||||
companies = update_contacts_before_receive(companies)
|
||||
companies
|
||||
company_register.representation_rights(citizen_personal_code: ident,
|
||||
citizen_country_code: country.alpha3)
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
return []
|
||||
[]
|
||||
end
|
||||
|
||||
def update_contacts_before_receive(companies)
|
||||
return [] if companies.blank?
|
||||
def do_need_update_contacts?
|
||||
counter = 0
|
||||
|
||||
counter += Contact.with_different_registrant_name(self).size
|
||||
|
||||
companies.each do |company|
|
||||
contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE')
|
||||
|
||||
next if contacts.blank?
|
||||
|
||||
contacts.each do |contact|
|
||||
next if company.company_name == contact.name
|
||||
|
||||
update_company_name(contact: contact, company: company)
|
||||
end
|
||||
counter += Contact.with_different_company_name(company).size
|
||||
end
|
||||
|
||||
companies
|
||||
return { result: true, counter: counter } if counter.positive?
|
||||
|
||||
{ result: false, counter: 0 }
|
||||
end
|
||||
|
||||
def update_company_name(contact:, company:)
|
||||
old_contact_name = contact.name
|
||||
contact.name = company.company_name
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def update_contacts
|
||||
user = self
|
||||
contacts = []
|
||||
contacts.concat(Contact.with_different_registrant_name(user).each do |c|
|
||||
c.write_attribute(:name, user.username)
|
||||
end)
|
||||
companies.each do |company|
|
||||
contacts.concat(Contact.with_different_company_name(company).each do |c|
|
||||
c.write_attribute(:name, company.company_name)
|
||||
end)
|
||||
end
|
||||
|
||||
contact.save(validate: false)
|
||||
return [] if contacts.blank?
|
||||
|
||||
notify_registrar_data_updated(company_name: company.company_name,
|
||||
old_contact_name: old_contact_name,
|
||||
contact: contact)
|
||||
end
|
||||
|
||||
def notify_registrar_data_updated(company_name:, old_contact_name:, contact:)
|
||||
contact.registrar.notifications.create!(
|
||||
text: "Contact update: #{contact.id} name updated from #{old_contact_name} to #{company_name} by the registry"
|
||||
)
|
||||
group_and_bulk_update(contacts)
|
||||
contacts
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts(representable: true)
|
||||
Contact.registrant_user_contacts(self, representable: representable)
|
||||
|
@ -100,17 +96,6 @@ class RegistrantUser < User
|
|||
username.split.second
|
||||
end
|
||||
|
||||
def update_related_contacts
|
||||
contacts = Contact.where(ident: ident, ident_country_code: country.alpha2)
|
||||
.where('UPPER(name) != UPPER(?)', username)
|
||||
|
||||
contacts.each do |contact|
|
||||
contact.update(name: username)
|
||||
action = actions.create!(contact: contact, operation: :update)
|
||||
contact.registrar.notify(action)
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def find_or_create_by_api_data(user_data = {})
|
||||
return false unless user_data[:ident]
|
||||
|
@ -147,9 +132,27 @@ class RegistrantUser < User
|
|||
user = find_or_create_by(registrant_ident: "#{user_data[:country_code]}-#{user_data[:ident]}")
|
||||
user.username = "#{user_data[:first_name]} #{user_data[:last_name]}"
|
||||
user.save
|
||||
|
||||
user.update_related_contacts
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def group_and_bulk_update(contacts)
|
||||
contacts.group_by(&:registrar_id).each do |registrar_id, reg_contacts|
|
||||
bulk_action, action = actions.create!(operation: :bulk_update) if reg_contacts.size > 1
|
||||
reg_contacts.each do |c|
|
||||
if c.save(validate: false)
|
||||
action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id)
|
||||
end
|
||||
end
|
||||
notify_registrar_contacts_updated(action: bulk_action || action,
|
||||
registrar_id: registrar_id)
|
||||
end
|
||||
end
|
||||
|
||||
def notify_registrar_contacts_updated(action:, registrar_id:)
|
||||
registrar = Registrar.find(registrar_id)
|
||||
registrar&.notify(action)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,8 +34,8 @@ class Registrar < ApplicationRecord
|
|||
attribute :vat_rate, ::Type::VatRate.new
|
||||
after_initialize :set_defaults
|
||||
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
validate :correct_billing_email_format
|
||||
# validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
# validate :correct_billing_email_format
|
||||
|
||||
alias_attribute :contact_email, :email
|
||||
|
||||
|
@ -218,8 +218,15 @@ class Registrar < ApplicationRecord
|
|||
end
|
||||
|
||||
def notify(action)
|
||||
text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact.code)
|
||||
notifications.create!(text: text)
|
||||
text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact&.code,
|
||||
count: action.subactions&.count)
|
||||
if action.bulk_action?
|
||||
notifications.create!(text: text, action_id: action.id,
|
||||
attached_obj_type: 'BulkAction',
|
||||
attached_obj_id: action.id)
|
||||
else
|
||||
notifications.create!(text: text)
|
||||
end
|
||||
end
|
||||
|
||||
def e_invoice_iban
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class ReservedDomain < ApplicationRecord
|
||||
extend ToCsv
|
||||
include Versions # version/reserved_domain_version.rb
|
||||
include WhoisStatusPopulate
|
||||
before_save :fill_empty_passwords
|
||||
|
|
|
@ -35,8 +35,6 @@ class ValidationEvent < ApplicationRecord
|
|||
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
|
||||
scope :by_object, ->(object) { where(validation_eventable: object) }
|
||||
|
||||
after_create :check_for_force_delete
|
||||
|
||||
def self.validated_ids_by(klass)
|
||||
old_records
|
||||
.successful
|
||||
|
@ -59,28 +57,4 @@ class ValidationEvent < ApplicationRecord
|
|||
def object
|
||||
validation_eventable
|
||||
end
|
||||
|
||||
def check_for_force_delete
|
||||
if object.need_to_start_force_delete?
|
||||
start_force_delete
|
||||
elsif object.need_to_lift_force_delete?
|
||||
lift_force_delete
|
||||
end
|
||||
end
|
||||
|
||||
def start_force_delete
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
end
|
||||
|
||||
def lift_force_delete
|
||||
# domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
||||
# registrant_ids = Registrant.where(email: email).pluck(:id)
|
||||
#
|
||||
# domains = domain_contacts.map(&:domain).flatten +
|
||||
# Domain.where(registrant_id: registrant_ids)
|
||||
#
|
||||
# domains.each do |domain|
|
||||
# Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
class Version::ContactVersion < PaperTrail::Version
|
||||
extend ToCsv
|
||||
include VersionSession
|
||||
|
||||
self.table_name = :log_contacts
|
||||
self.sequence_name = :log_contacts_id_seq
|
||||
|
||||
def as_csv_row
|
||||
contact = ObjectVersionsParser.new(self).parse
|
||||
|
||||
[
|
||||
contact.name,
|
||||
contact.code,
|
||||
contact.ident_human_description,
|
||||
contact.registrar,
|
||||
event,
|
||||
created_at.to_formatted_s(:db)
|
||||
]
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class Version::DomainVersion < PaperTrail::Version
|
||||
extend ToCsv
|
||||
include VersionSession
|
||||
|
||||
self.table_name = :log_domains
|
||||
|
@ -7,6 +6,18 @@ class Version::DomainVersion < PaperTrail::Version
|
|||
|
||||
scope :deleted, -> { where(event: 'destroy') }
|
||||
|
||||
def as_csv_row
|
||||
domain = ObjectVersionsParser.new(self).parse
|
||||
|
||||
[
|
||||
domain.name,
|
||||
domain.registrant_name,
|
||||
domain.registrar,
|
||||
event,
|
||||
created_at.to_formatted_s(:db)
|
||||
]
|
||||
end
|
||||
|
||||
def self.was_contact_linked?(contact_id)
|
||||
sql = <<-SQL
|
||||
SELECT
|
||||
|
@ -43,4 +54,8 @@ class Version::DomainVersion < PaperTrail::Version
|
|||
|
||||
count_by_sql(sql).nonzero?
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Name', 'Registrant', 'Registrar', 'Action', 'Created at']
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue