Registrar: Allow to view other contacts of domain

This commit is contained in:
Karl Erik Õunapuu 2020-02-12 15:33:22 +02:00
parent bd9c9cd585
commit e50cf7d200
3 changed files with 11 additions and 5 deletions

View file

@ -5,7 +5,8 @@ class Registrant::ContactsController < RegistrantController
skip_authorization_check only: %i[edit update]
def show
@contact = current_user_contacts.find(params[:id])
@contact = domain.contacts.find(params[:id])
@requester_contact = domain.contacts.find_by(ident: current_registrant_user.ident).id
authorize! :read, @contact
end

View file

@ -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:)
def all_domains(page: nil, per: nil, params:, requester:)
# compose filter sql
filter_sql = case params[:domain_filter]
when "Registrant".freeze
@ -431,9 +431,14 @@ class Contact < ApplicationRecord
sort = Domain.column_names.include?(sorts.first) ? sorts.first : "valid_to"
order = {"asc"=>"desc", "desc"=>"asc"}[sorts.second] || "desc"
# fetch domains
domains = Domain.where("domains.id IN (#{filter_sql})")
if requester
requester_domains = Contact.find(requester).domains
domains = requester_domains.where("domains.id IN (#{filter_sql})")
else
domains = Domain.where("domains.id IN (#{filter_sql})")
end
domains = domains.includes(:registrar).page(page).per(per)
if sorts.first == "registrar_name".freeze

View file

@ -1,5 +1,5 @@
<% domains = contact.all_domains(page: params[:domain_page], per: 20,
params: domain_filter_params.to_h) %>
params: domain_filter_params.to_h, requester: @requester_contact) %>
<div class="panel panel-default">
<div class="panel-heading">