mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
Submit only object ID to DomainVersion linked methods instead of full object
This commit is contained in:
parent
7a24eab63a
commit
821c52a8ad
3 changed files with 24 additions and 27 deletions
|
@ -27,12 +27,9 @@ module Concerns
|
|||
private
|
||||
|
||||
def inactive?
|
||||
if DomainVersion.was_contact_linked?(self)
|
||||
DomainVersion.contact_unlinked_more_than?(contact: self,
|
||||
period: inactivity_period)
|
||||
else
|
||||
created_at <= inactivity_period.ago
|
||||
end
|
||||
return (created_at <= inactivity_period.ago) unless DomainVersion.was_contact_linked?(id)
|
||||
|
||||
DomainVersion.contact_unlinked_more_than?(contact_id: id, period: inactivity_period)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,24 +6,24 @@ class DomainVersion < PaperTrail::Version
|
|||
|
||||
scope :deleted, -> { where(event: 'destroy') }
|
||||
|
||||
def self.was_contact_linked?(contact)
|
||||
def self.was_contact_linked?(contact_id)
|
||||
sql = <<-SQL
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
#{table_name}
|
||||
WHERE
|
||||
(children->'registrant') @> '#{contact.id}'
|
||||
(children->'registrant') @> '#{contact_id}'
|
||||
OR
|
||||
(children->'admin_contacts') @> '#{contact.id}'
|
||||
(children->'admin_contacts') @> '#{contact_id}'
|
||||
OR
|
||||
(children->'tech_contacts') @> '#{contact.id}'
|
||||
(children->'tech_contacts') @> '#{contact_id}'
|
||||
SQL
|
||||
|
||||
count_by_sql(sql).nonzero?
|
||||
end
|
||||
|
||||
def self.contact_unlinked_more_than?(contact:, period:)
|
||||
def self.contact_unlinked_more_than?(contact_id:, period:)
|
||||
sql = <<-SQL
|
||||
SELECT
|
||||
COUNT(*)
|
||||
|
@ -32,14 +32,14 @@ class DomainVersion < PaperTrail::Version
|
|||
WHERE
|
||||
created_at < TIMESTAMP WITH TIME ZONE '#{period.ago}'
|
||||
AND (
|
||||
(children->'registrant') @> '#{contact.id}'
|
||||
(children->'registrant') @> '#{contact_id}'
|
||||
OR
|
||||
(children->'admin_contacts') @> '#{contact.id}'
|
||||
(children->'admin_contacts') @> '#{contact_id}'
|
||||
OR
|
||||
(children->'tech_contacts') @> '#{contact.id}'
|
||||
(children->'tech_contacts') @> '#{contact_id}'
|
||||
)
|
||||
SQL
|
||||
|
||||
count_by_sql(sql).nonzero?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
tech_contacts: [],
|
||||
registrant: [@contact.id] })
|
||||
|
||||
assert DomainVersion.was_contact_linked?(@contact)
|
||||
assert DomainVersion.was_contact_linked?(@contact.id)
|
||||
end
|
||||
|
||||
def test_was_contact_linked_returns_true_when_contact_was_used_as_admin_contact
|
||||
|
@ -19,7 +19,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
tech_contacts: [],
|
||||
registrant: [] })
|
||||
|
||||
assert DomainVersion.was_contact_linked?(@contact)
|
||||
assert DomainVersion.was_contact_linked?(@contact.id)
|
||||
end
|
||||
|
||||
def test_was_contact_linked_returns_true_when_contact_was_used_as_tech_contact
|
||||
|
@ -27,7 +27,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
tech_contacts: [@contact.id],
|
||||
registrant: [] })
|
||||
|
||||
assert DomainVersion.was_contact_linked?(@contact)
|
||||
assert DomainVersion.was_contact_linked?(@contact.id)
|
||||
end
|
||||
|
||||
def test_was_contact_linked_returns_false_when_contact_was_not_used
|
||||
|
@ -35,7 +35,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
tech_contacts: [],
|
||||
registrant: [] })
|
||||
|
||||
assert_not DomainVersion.was_contact_linked?(@contact)
|
||||
assert_not DomainVersion.was_contact_linked?(@contact.id)
|
||||
end
|
||||
|
||||
def test_contact_unlinked_more_than_returns_true_when_contact_was_linked_as_registrant_more_than_given_period
|
||||
|
@ -45,7 +45,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [@contact.id] })
|
||||
travel_to Time.zone.parse('2010-07-05 00:00:01')
|
||||
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_unlinked_more_than_given_period_as_admin_contact
|
||||
|
@ -55,7 +55,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [] })
|
||||
travel_to Time.zone.parse('2010-07-05 00:00:01')
|
||||
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_unlinked_more_than_given_period_as_tech_contact
|
||||
|
@ -65,7 +65,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [] })
|
||||
travel_to Time.zone.parse('2010-07-05 00:00:01')
|
||||
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_linked_within_given_period_as_registrant
|
||||
|
@ -75,7 +75,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [@contact.id] })
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_linked_within_given_period_as_admin_contact
|
||||
|
@ -85,7 +85,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [] })
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_linked_within_given_period_as_tech_contact
|
||||
|
@ -95,11 +95,11 @@ class DomainVersionTest < ActiveSupport::TestCase
|
|||
registrant: [] })
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
|
||||
def test_contact_was_never_linked
|
||||
DomainVersion.delete_all
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact: @contact, period: 1.day)
|
||||
assert_not DomainVersion.contact_unlinked_more_than?(contact_id: @contact.id, period: 1.day)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue