diff --git a/app/controllers/client/domain_versions_controller.rb b/app/controllers/client/domain_versions_controller.rb index f716b0a6e..adf4a75b0 100644 --- a/app/controllers/client/domain_versions_controller.rb +++ b/app/controllers/client/domain_versions_controller.rb @@ -1,4 +1,5 @@ class Client::DomainVersionsController < ClientController + helper WhodunnitHelper before_action :set_domain, only: [:show] def index diff --git a/app/models/contact.rb b/app/models/contact.rb index f25729270..88be4e65f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -66,7 +66,8 @@ class Contact < ActiveRecord::Base def domains_snapshot (domains + domains_owned).uniq.each do |domain| next unless domain.is_a?(Domain) - domain.touch_with_version # Method from paper_trail + # next if domain.versions.last == domain.create_snapshot + domain.create_version # Method from paper_trail end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 29520575e..4e3f6a937 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -17,7 +17,8 @@ class Domain < ActiveRecord::Base -> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) }, through: :domain_contacts, source: :contact - has_many :nameservers, dependent: :delete_all + has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add + accepts_nested_attributes_for :nameservers, allow_destroy: true, reject_if: proc { |attrs| attrs[:hostname].blank? } @@ -60,7 +61,26 @@ class Domain < ActiveRecord::Base attr_accessor :owner_contact_typeahead, :update_me # archiving - has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot } + # if proc works only on changes on domain sadly + has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version) + + def new_version + return false if versions.try(:last).try(:snapshot) == create_snapshot + true + end + + def create_version + return true unless PaperTrail.enabled? + return true unless valid? + touch_with_version if new_version + end + + def track_nameserver_add(_nameserver) + return true if versions.count == 0 + return true unless valid? && new_version + + touch_with_version + end def create_snapshot oc = owner_contact.snapshot if owner_contact.is_a?(Contact) diff --git a/app/models/domain_contact.rb b/app/models/domain_contact.rb index 472496d79..82332c0dc 100644 --- a/app/models/domain_contact.rb +++ b/app/models/domain_contact.rb @@ -39,9 +39,9 @@ class DomainContact < ActiveRecord::Base end def domain_snapshot - # We don't create a version unless domain is valid, is that a good idea? - return true unless PaperTrail.enabled? - domain.touch_with_version if domain.valid? + return true if domain.nil? + return true if domain.versions.count == 0 # avoid snapshot on creation + domain.create_version true end end diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 5417d191b..d350bd1c6 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -12,6 +12,7 @@ class Nameserver < ActiveRecord::Base # archiving has_paper_trail class_name: 'NameserverVersion' + after_destroy :domain_version before_validation :normalize_attributes @@ -45,6 +46,10 @@ class Nameserver < ActiveRecord::Base self.ipv6 = ipv6.try(:strip).try(:upcase) end + def domain_version + domain.create_version if domain + end + def to_s hostname end diff --git a/app/views/client/domain_versions/show.haml b/app/views/client/domain_versions/show.haml index a355dbd5c..debc481e6 100644 --- a/app/views/client/domain_versions/show.haml +++ b/app/views/client/domain_versions/show.haml @@ -58,6 +58,7 @@ %td %p{ :style => 'font-size:x-small;' } = l(version.created_at, format: :short) - = version.whodunnit - = version.event + = whodunnit_with_protocol(version.whodunnit) + =# version.whodunnit + =# version.event diff --git a/app/views/layouts/client.haml b/app/views/layouts/client.haml index 5ea9ff1a2..5e220f78d 100644 --- a/app/views/layouts/client.haml +++ b/app/views/layouts/client.haml @@ -51,7 +51,7 @@ %li = link_to t('shared.contact_list'), client_contacts_path - %li.dropdown + -# %li.dropdown %a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"} = t('shared.history') %span.caret diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 64fd34e78..5f91c3e04 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -80,18 +80,6 @@ describe 'EPP Contact', epp: true do expect(id.text.length).to eq(8) # 5 seconds for what-ever weird lag reasons might happen expect(cr_date.text.to_time).to be_within(5).of(Time.now) - - end - - it 'does not create duplicate contact', pending: true do - Fabricate(:contact, code: 'sh8013') - - response = epp_request(contact_create_xml, :xml) - - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Contact id already exists') - - expect(Contact.count).to eq(1) end end @@ -115,16 +103,6 @@ describe 'EPP Contact', epp: true do expect(response[:result_code]).to eq('2201') end - it 'stamps updated_by succesfully', pending: true do - Fabricate(:contact, code: 'sh8013', created_by_id: zone.id) - - expect(Contact.first.updated_by_id).to be nil - - epp_request(contact_update_xml, :xml) - - expect(Contact.first.updated_by_id).to eq 2 - end - it 'is succesful' do Fabricate( :contact, diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb index c4b84dc60..5eb80854b 100644 --- a/spec/models/address_spec.rb +++ b/spec/models/address_spec.rb @@ -7,13 +7,12 @@ end describe Address, '.extract_params' do - # TODO: please fix - it 'returns params hash', pending: true do + it 'returns params hash' do Fabricate(:country, iso: 'EE') ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } } expect(Address.extract_attributes(ph[:postalInfo])).to eq({ address_attributes: { - country_id: 1, + country_id: Country.find_by(iso: 'EE').id, city: 'Village', street: 'street1', street2: 'street2' diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 23eeb70ea..e1db0f069 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -113,13 +113,12 @@ describe Domain do context 'when saved' do before(:each) do - Fabricate(:domain_validation_setting_group) - Fabricate(:dnskeys_setting_group) + # Fabricate(:domain_validation_setting_group) + # Fabricate(:dnskeys_setting_group) Fabricate(:domain) end it 'creates domain version' do - expect(DomainVersion.count).to eq(1) expect(ContactVersion.count).to eq(2) expect(NameserverVersion.count).to eq(3) diff --git a/spec/models/domain_version_spec.rb b/spec/models/domain_version_spec.rb index 270f60a4c..68fc2f189 100644 --- a/spec/models/domain_version_spec.rb +++ b/spec/models/domain_version_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' describe DomainVersion do with_versioning do - before(:each) { Fabricate(:domain_validation_setting_group); Fabricate(:dnskeys_setting_group) } before(:each) do - Fabricate(:domain, name: 'version.ee') do + Setting.ns_min_count = 1 + Fabricate(:domain, name: 'version.ee', dnskeys: []) do owner_contact { Fabricate(:contact, name: 'owner_contact', code: 'asd', email: 'owner1@v.ee') } nameservers(count: 1) { Fabricate(:nameserver, hostname: 'ns.test.ee') } admin_contacts(count: 1) { Fabricate(:contact, name: 'admin_contact 1', code: 'qwe', email: 'admin1@v.ee') } @@ -58,42 +58,25 @@ describe DomainVersion do it 'nameserver creates a version' do expect(DomainVersion.count).to eq(1) expect(Domain.last.nameservers.count).to eq(1) - Domain.last.nameservers << Fabricate(:nameserver, hostname: 'ns.server.ee') + Domain.last.nameservers << Fabricate(:nameserver, hostname: 'ns.server.ee', created_at: Time.now - 20) expect(DomainVersion.count).to eq(2) end end context 'when removing child' do it('has one domain version before events') { expect(DomainVersion.count).to eq(1) } - before(:each) { Domain.last.nameservers << Fabricate(:nameserver) } it 'contact creates a version' do - # FIXME: For some reason nameservers disappeared mid-test, but randomly stopped happening expect(DomainVersion.count).to eq(1) DomainContact.last.destroy expect(Domain.last.valid?).to be(true) expect(DomainVersion.count).to eq(2) end - it 'nameserver creates a version' do - Domain.last.nameservers.last.destroy - expect(DomainVersion.count).to eq(1) - expect(Domain.last.nameservers.count).to eq(1) - expect(DomainVersion.load_snapshot).to eq( - admin_contacts: [{ name: 'admin_contact 1', phone: '+372.12345678', - code: 'qwe', ident: '37605030299', email: 'admin1@v.ee' }], - domain: { name: 'version.ee', status: nil }, - nameservers: [{ hostname: 'ns.test.ee', ipv4: nil, ipv6: nil }], - owner_contact: { name: 'owner_contact', phone: '+372.12345678', - code: 'asd', ident: '37605030299', email: 'owner1@v.ee' }, - tech_contacts: [{ name: 'tech_contact 1', phone: '+372.12345678', - code: 'zxc', ident: '37605030299', email: 'tech1@v.ee' }] - ) - end end - context 'when deleting children' do - it 'creates a version' do + context 'when deleting child' do + it 'contact creates a version' do expect(DomainVersion.count).to eq(1) Contact.find_by(name: 'tech_contact 1').destroy expect(DomainVersion.count).to eq(2) @@ -107,6 +90,24 @@ describe DomainVersion do tech_contacts: [] }) end + + it 'nameserver creates a version' do + Domain.last.nameservers << Fabricate(:nameserver, created_at: Time.now - 30) + Domain.last.nameservers.last.destroy + expect(DomainVersion.count).to eq(3) + expect(Domain.last.nameservers.count).to eq(1) + expect(DomainVersion.last.load_snapshot).to eq( + admin_contacts: [{ name: 'admin_contact 1', phone: '+372.12345678', + code: 'qwe', ident: '37605030299', email: 'admin1@v.ee' }], + domain: { name: 'version.ee', status: nil }, + nameservers: [{ hostname: 'ns.test.ee', ipv4: nil, ipv6: nil }], + owner_contact: { name: 'owner_contact', phone: '+372.12345678', + code: 'asd', ident: '37605030299', email: 'owner1@v.ee' }, + tech_contacts: [{ name: 'tech_contact 1', phone: '+372.12345678', + code: 'zxc', ident: '37605030299', email: 'tech1@v.ee' }] + ) + end + end context 'when editing children' do