mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Merge branch 'story/116761157-contact-dyn-states' into staging
This commit is contained in:
commit
6a01c8c7ab
3 changed files with 26 additions and 18 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue