diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index b06a9de9b..5f4781902 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index 2f079e403..9cd758314 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/registrar.rb b/app/models/registrar.rb index fdff0426e..cb78c2ec4 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -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 diff --git a/app/views/registrar/domains/form_partials/_contacts.haml b/app/views/registrar/domains/form_partials/_contacts.haml index 38cc47564..ac5cd19b2 100644 --- a/app/views/registrar/domains/form_partials/_contacts.haml +++ b/app/views/registrar/domains/form_partials/_contacts.haml @@ -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 diff --git a/db/migrate/20150511120755_add_index_to_contact_type.rb b/db/migrate/20150511120755_add_index_to_contact_type.rb new file mode 100644 index 000000000..92f9e698f --- /dev/null +++ b/db/migrate/20150511120755_add_index_to_contact_type.rb @@ -0,0 +1,5 @@ +class AddIndexToContactType < ActiveRecord::Migration + def change + add_index :contacts, [:registrar_id, :ident_type] + end +end diff --git a/db/schema.rb b/db/schema.rb index f24eb3a64..fc41c9a95 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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| diff --git a/spec/models/api_user_spec.rb b/spec/models/api_user_spec.rb index 9fb0d2fdc..30c800cb6 100644 --- a/spec/models/api_user_spec.rb +++ b/spec/models/api_user_spec.rb @@ -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 diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index 42b0655a7..067c999af 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -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