Merge branch 'story/116761157-contact-dyn-states' into staging

This commit is contained in:
Vladimir Krylov 2016-05-30 12:49:31 +03:00
commit 6a01c8c7ab
3 changed files with 26 additions and 18 deletions

View file

@ -174,6 +174,27 @@ class Contact < ActiveRecord::Base
')
end
def find_linked
where('
EXISTS(
select 1 from domains d where d.registrant_id = contacts.id
) OR EXISTS(
select 1 from domain_contacts dc where dc.contact_id = contacts.id
)
')
end
def filter_by_states in_states
states = Array(in_states).dup
scope = all
# all contacts has state ok, so no need to filter by it
states.delete(OK)
scope = scope.find_linked if states.delete(LINKED)
scope = scope.where( "contacts.statuses @> ?::varchar[]", "{#{states.join(',')}}") if states.any?
scope
end
# To leave only new ones we need to check
# if contact was at any time used in domain.
# This can be checked by domain history.