mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Find contact/registrar directly via domain or via relations
This commit is contained in:
parent
bd7b6ddb73
commit
572510d7b0
3 changed files with 18 additions and 8 deletions
|
@ -3,9 +3,9 @@ class Registrant::ContactsController < RegistrantController
|
||||||
helper_method :fax_enabled?
|
helper_method :fax_enabled?
|
||||||
helper_method :domain_filter_params
|
helper_method :domain_filter_params
|
||||||
skip_authorization_check only: %i[edit update]
|
skip_authorization_check only: %i[edit update]
|
||||||
|
before_action :set_contact, only: [:show]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@contact = domain.contacts.find(params[:id])
|
|
||||||
@requester_contact = Contact.find_by(ident: current_registrant_user.ident).id
|
@requester_contact = Contact.find_by(ident: current_registrant_user.ident).id
|
||||||
authorize! :read, @contact
|
authorize! :read, @contact
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,13 @@ class Registrant::ContactsController < RegistrantController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_contact
|
||||||
|
id = params[:id]
|
||||||
|
contact = domain.contacts.find_by(id: id) || current_user_contacts.find_by(id: id)
|
||||||
|
contact ||= Contact.find_by(id: id, ident: domain.registrant.ident)
|
||||||
|
@contact = contact
|
||||||
|
end
|
||||||
|
|
||||||
def domain
|
def domain
|
||||||
current_user_domains.find(params[:domain_id])
|
current_user_domains.find(params[:domain_id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -415,7 +415,7 @@ class Contact < ApplicationRecord
|
||||||
# if total is smaller than needed, the load more
|
# if total is smaller than needed, the load more
|
||||||
# we also need to sort by valid_to
|
# we also need to sort by valid_to
|
||||||
# todo: extract to drapper. Then we can remove Domain#roles
|
# todo: extract to drapper. Then we can remove Domain#roles
|
||||||
def all_domains(page: nil, per: nil, params:, requester:)
|
def all_domains(page: nil, per: nil, params:, requester: nil)
|
||||||
filter_sql = qualified_domain_ids(params[:domain_filter])
|
filter_sql = qualified_domain_ids(params[:domain_filter])
|
||||||
|
|
||||||
# get sorting rules
|
# get sorting rules
|
||||||
|
@ -451,9 +451,12 @@ class Contact < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def qualified_domain_name_list(requester, filter_sql)
|
def qualified_domain_name_list(requester, filter_sql)
|
||||||
if requester
|
if requester != id
|
||||||
requester_domains = Contact.find(requester).domains
|
first_scope = Contact.find(requester).domains
|
||||||
domains = requester_domains.where('domains.id IN (?)', filter_sql)
|
second_scope = Contact.find(requester).registrant_domains
|
||||||
|
|
||||||
|
domains = Domain.from("(#{first_scope.to_sql} UNION #{second_scope.to_sql}) as domains")
|
||||||
|
.where('domains.id IN (?)', filter_sql)
|
||||||
else
|
else
|
||||||
domains = Domain.where('domains.id IN (?)', filter_sql)
|
domains = Domain.where('domains.id IN (?)', filter_sql)
|
||||||
end
|
end
|
||||||
|
@ -462,13 +465,13 @@ class Contact < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def qualified_domain_ids(domain_filter)
|
def qualified_domain_ids(domain_filter)
|
||||||
registrant_ids = Domain.select('id').where(registrant: id).pluck(:id)
|
registrant_ids = registrant_domains.pluck(:id)
|
||||||
return registrant_ids if domain_filter == 'Registrant'
|
return registrant_ids if domain_filter == 'Registrant'
|
||||||
|
|
||||||
if %w[AdminDomainContact TechDomainContact].include? domain_filter
|
if %w[AdminDomainContact TechDomainContact].include? domain_filter
|
||||||
DomainContact.select('domain_id').where(contact_id: id, type: domain_filter)
|
DomainContact.select('domain_id').where(contact_id: id, type: domain_filter)
|
||||||
else
|
else
|
||||||
(DomainContact.select('domain_id').where(contact_id: id).pluck(:id) +
|
(DomainContact.select('domain_id').where(contact_id: id).pluck(:domain_id) +
|
||||||
registrant_ids).uniq
|
registrant_ids).uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,4 +98,4 @@ class RegistrantUser < User
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue