Show only priv contacts

This commit is contained in:
Priit Tark 2015-05-11 15:56:31 +03:00
parent e20de5b793
commit 2ed9672eb5
8 changed files with 28 additions and 3 deletions

View file

@ -121,5 +121,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
def init_contacts_autocomplete_map
@contacts_autocomplete_map ||=
current_user.registrar.contacts.pluck(:name, :code).map { |c| ["#{c.second} #{c.first}", c.second] }
@priv_contacts_autocomplete_map ||=
current_user.registrar.priv_contacts.pluck(:name, :code).map { |c| ["#{c.second} #{c.first}", c.second] }
end
end

View file

@ -69,6 +69,10 @@ class Contact < ActiveRecord::Base
count = find_orphans.destroy_all.count
logger.info "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n"
end
def privs
where("ident_type = '#{PRIV}'")
end
end
def to_s

View file

@ -9,6 +9,7 @@ class Registrar < ActiveRecord::Base
has_many :accounts
has_many :nameservers, through: :domains
has_many :whois_records
has_many :priv_contacts, -> { privs }, class_name: 'Contact'
validates :name, :reg_no, :country_code, :email, :code, presence: true
validates :name, :reg_no, :reference_no, :code, uniqueness: true

View file

@ -18,7 +18,7 @@
= label_tag "domain_contacts_attributes_#{k}_code", t(:contact_code), class: 'required'
.col-md-7.has-feedback
= select_tag "domain[contacts_attributes][#{k}][code]",
options_for_select(@contacts_autocomplete_map, selected: v['code']),
options_for_select(@priv_contacts_autocomplete_map, selected: v['code']),
include_blank: true, class: 'js-combobox', required: true
:coffee

View file

@ -0,0 +1,5 @@
class AddIndexToContactType < ActiveRecord::Migration
def change
add_index :contacts, [:registrar_id, :ident_type]
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150505111437) do
ActiveRecord::Schema.define(version: 20150511120755) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -188,6 +188,7 @@ ActiveRecord::Schema.define(version: 20150505111437) do
end
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
add_index "contacts", ["registrar_id", "ident_type"], name: "index_contacts_on_registrar_id_and_ident_type", using: :btree
add_index "contacts", ["registrar_id"], name: "index_contacts_on_registrar_id", using: :btree
create_table "countries", force: :cascade do |t|

View file

@ -24,7 +24,6 @@ describe ApiUser do
it 'should be active by default' do
@api_user.active.should == true
end
end
context 'with valid attributes' do

View file

@ -39,6 +39,10 @@ describe Registrar do
@registrar.reference_no.should_not be_blank
@registrar.reference_no.last(10).to_i.should_not == 0
end
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
end
context 'with valid attributes' do
@ -126,5 +130,14 @@ describe Registrar do
registrar.valid?
registrar.errors.full_messages.should == ['Code is forbidden to use']
end
it 'should have priv contacts' do
Fabricate(:contact, registrar: @registrar)
@registrar.reload.priv_contacts.size.should == 1
end
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
end
end