Refactor RegistrantUser class

* Extract frequently used country_code and ident methods
* Refactor domain query
* Add contact query method
* Add adminstrated_domains query method. Name will most likely change
  in the future developments
* Change registry locks integration test name
This commit is contained in:
Maciej Szlosarczyk 2018-08-23 16:00:44 +03:00
parent 9f7fc47f19
commit 9623e2fb97
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
6 changed files with 95 additions and 55 deletions

View file

@ -8,16 +8,30 @@ class RegistrantUser < User
delegate :can?, :cannot?, to: :ability
def ident
registrant_ident.to_s.split("-").last
registrant_ident.to_s.split('-').last
end
def country_code
registrant_ident.to_s.split('-').first
end
def domains
ident_cc, ident = registrant_ident.to_s.split '-'
Domain.includes(:registrar, :registrant).where(contacts: {
ident_type: 'priv',
ident: ident, #identity_code,
ident_country_code: ident_cc #country_code
})
Domain.includes(:registrar, :registrant).where(
contacts: {
ident_type: 'priv',
ident: ident,
ident_country_code: country_code
}
)
end
def contacts
Contact.where(ident_type: 'priv', ident: ident, ident_country_code: country_code)
end
def administrated_domains
Domain.joins(:domain_contacts)
.where(domain_contacts: { contact_id: contacts, type: AdminDomainContact })
end
def to_s