mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +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 :domain_filter_params
|
||||
skip_authorization_check only: %i[edit update]
|
||||
before_action :set_contact, only: [:show]
|
||||
|
||||
def show
|
||||
@contact = domain.contacts.find(params[:id])
|
||||
@requester_contact = Contact.find_by(ident: current_registrant_user.ident).id
|
||||
authorize! :read, @contact
|
||||
end
|
||||
|
@ -31,6 +31,13 @@ class Registrant::ContactsController < RegistrantController
|
|||
|
||||
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
|
||||
current_user_domains.find(params[:domain_id])
|
||||
end
|
||||
|
|
|
@ -415,7 +415,7 @@ class Contact < ApplicationRecord
|
|||
# if total is smaller than needed, the load more
|
||||
# we also need to sort by valid_to
|
||||
# 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])
|
||||
|
||||
# get sorting rules
|
||||
|
@ -451,9 +451,12 @@ class Contact < ApplicationRecord
|
|||
end
|
||||
|
||||
def qualified_domain_name_list(requester, filter_sql)
|
||||
if requester
|
||||
requester_domains = Contact.find(requester).domains
|
||||
domains = requester_domains.where('domains.id IN (?)', filter_sql)
|
||||
if requester != id
|
||||
first_scope = Contact.find(requester).domains
|
||||
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
|
||||
domains = Domain.where('domains.id IN (?)', filter_sql)
|
||||
end
|
||||
|
@ -462,13 +465,13 @@ class Contact < ApplicationRecord
|
|||
end
|
||||
|
||||
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'
|
||||
|
||||
if %w[AdminDomainContact TechDomainContact].include? domain_filter
|
||||
DomainContact.select('domain_id').where(contact_id: id, type: domain_filter)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,4 +98,4 @@ class RegistrantUser < User
|
|||
user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue