mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
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:
parent
9f7fc47f19
commit
9623e2fb97
6 changed files with 95 additions and 55 deletions
|
@ -39,7 +39,8 @@ module Api
|
|||
if decryptor.valid?
|
||||
sign_in decryptor.user
|
||||
else
|
||||
render json: { errors: [{base: ['Not authorized']}] }, status: :unauthorized
|
||||
render json: { errors: [{ base: ['Not authorized'] }] },
|
||||
status: :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ module Api
|
|||
private
|
||||
|
||||
def set_domain
|
||||
domain_pool = associated_domains(current_user)
|
||||
domain_pool = current_user.administrated_domains
|
||||
@domain = domain_pool.find_by(uuid: params[:domain_uuid])
|
||||
|
||||
return if @domain
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue