From 65d849cc36bac40d9366f11b965ab817acccd13e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 30 Jan 2015 11:53:33 +0200 Subject: [PATCH] Add some new contact fields to registrar --- .../admin/registrars_controller.rb | 5 +++- app/controllers/epp/domains_controller.rb | 1 - app/models/registrar.rb | 4 ++- app/views/admin/registrars/_form.haml | 18 ++++++++++-- app/views/admin/registrars/show.haml | 11 +++++++- config/locales/en.yml | 25 ++++++----------- ...0130085458_add_more_fields_to_registrar.rb | 7 +++++ db/schema.rb | 5 +++- spec/models/keyrelay_spec.rb | 1 + spec/models/registrar_spec.rb | 28 +++++++++++++++++++ 10 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20150130085458_add_more_fields_to_registrar.rb diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 2667bd534..0b19f9e34 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -55,6 +55,9 @@ class Admin::RegistrarsController < AdminController end def registrar_params - params.require(:registrar).permit(:name, :reg_no, :vat_no, :address, :billing_address, :country_id) + params.require(:registrar).permit( + :name, :reg_no, :vat_no, :address, :billing_address, + :country_id, :email, :phone, :billing_email + ) end end diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 11fda68e9..cd6fc0d5e 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -29,7 +29,6 @@ class Epp::DomainsController < EppController end def renew - # TODO: support period unit @domain = find_domain handle_errors(@domain) and return unless @domain diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 78647a11d..29df5ccd3 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -5,9 +5,11 @@ class Registrar < ActiveRecord::Base has_many :api_users, dependent: :restrict_with_error has_many :messages - validates :name, :reg_no, :address, :country, presence: true + validates :name, :reg_no, :address, :country, :email, presence: true validates :name, :reg_no, uniqueness: true + validates :email, :billing_email, format: /@/, allow_blank: true + def domain_transfers at = DomainTransfer.arel_table DomainTransfer.where( diff --git a/app/views/admin/registrars/_form.haml b/app/views/admin/registrars/_form.haml index 474844a76..a2bf07a84 100644 --- a/app/views/admin/registrars/_form.haml +++ b/app/views/admin/registrars/_form.haml @@ -1,6 +1,6 @@ = form_for([:admin, @registrar]) do |f| - if @registrar.errors.any? - - @registrar.errors.each do |attr, err| + - @registrar.errors.full_messages.each do |err| = err %br - if @registrar.errors.any? @@ -14,9 +14,16 @@ .form-group = f.label :reg_no = f.text_field(:reg_no, class: 'form-control') + / EIS does not want VAT + / .form-group + / = f.label :vat_no + / = f.text_field(:vat_no, class: 'form-control') .form-group - = f.label :vat_no - = f.text_field(:vat_no, class: 'form-control') + = f.label :email + = f.text_field(:email, class: 'form-control') + .form-group + = f.label :phone + = f.text_field(:phone, class: 'form-control') .col-md-6.text-left .form-group @@ -25,9 +32,14 @@ .form-group = f.label :address = f.text_field(:address, class: 'form-control') + %p.help-block= t('address_help') .form-group = f.label :billing_address = f.text_field(:billing_address, class: 'form-control') + %p.help-block= t('address_help') + .form-group + = f.label :billing_email + = f.text_field(:billing_email, class: 'form-control') %hr .row .col-md-12.text-right diff --git a/app/views/admin/registrars/show.haml b/app/views/admin/registrars/show.haml index 3cdfc300d..79d0de582 100644 --- a/app/views/admin/registrars/show.haml +++ b/app/views/admin/registrars/show.haml @@ -33,7 +33,7 @@ .col-md-6 .panel.panel-default .panel-heading - %h3.panel-title= t('address') + %h3.panel-title= t('contact') .panel-body %dl.dl-horizontal %dt= t('country') @@ -42,9 +42,18 @@ %dt= t('address') %dd= @registrar.address + %dt= t('contact_phone') + %dd= @registrar.phone + + %dt= t('contact_email') + %dd= @registrar.email + %dt= t('billing_address') %dd= @registrar.billing_address + %dt= t('billing_email') + %dd= @registrar.billing_email + .row .col-md-12 #epp-users.panel.panel-default diff --git a/config/locales/en.yml b/config/locales/en.yml index dba33dbdc..b1578e13c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -151,22 +151,6 @@ en: setting_id: taken: 'Status already exists on this domain' - - registrar: - attributes: - name: - blank: 'Name is missing' - taken: 'Name already exists' - reg_no: - blank: 'Reg. number is missing' - taken: 'Reg no. already exists' - vat_no: - blank: 'Vat number is missing' - country: - blank: 'Country is missing' - address: - blank: 'Address is missing' - user: attributes: username: @@ -248,6 +232,10 @@ en: expire: 'Expire' minimum_ttl: 'Minimum TTL' email: 'E-Mail' + registrar: + billing_email: 'Billing e-mail' + phone: 'Contact phone' + email: 'Contact e-mail' errors: messages: @@ -505,3 +493,8 @@ en: clear_fields: 'Clear fields' created_before: 'Created before' created_after: 'Created after' + billing_address: 'Billing address' + billing_email: 'Billing e-mail' + contact_phone: 'Contact phone' + contact_email: 'Contact e-mail' + address_help: 'Street name, house no - apartment no, city, county, country, zip' diff --git a/db/migrate/20150130085458_add_more_fields_to_registrar.rb b/db/migrate/20150130085458_add_more_fields_to_registrar.rb new file mode 100644 index 000000000..a14606a81 --- /dev/null +++ b/db/migrate/20150130085458_add_more_fields_to_registrar.rb @@ -0,0 +1,7 @@ +class AddMoreFieldsToRegistrar < ActiveRecord::Migration + def change + add_column :registrars, :phone, :string + add_column :registrars, :email, :string + add_column :registrars, :billing_email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7054ebe0d..7c9a0d47f 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: 20150129114042) do +ActiveRecord::Schema.define(version: 20150130085458) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -293,6 +293,9 @@ ActiveRecord::Schema.define(version: 20150129114042) do t.string "billing_address", limit: 255 t.datetime "created_at" t.datetime "updated_at" + t.string "phone" + t.string "email" + t.string "billing_email" end create_table "reserved_domains", force: :cascade do |t| diff --git a/spec/models/keyrelay_spec.rb b/spec/models/keyrelay_spec.rb index 918d4cc08..2b76c50b9 100644 --- a/spec/models/keyrelay_spec.rb +++ b/spec/models/keyrelay_spec.rb @@ -4,6 +4,7 @@ describe Keyrelay do it { should belong_to(:domain) } it { should belong_to(:requester) } it { should belong_to(:accepter) } + it { should have_many(:legal_documents) } it 'is in pending status' do kr = Fabricate(:keyrelay) diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index f0d8b3bed..40b243fc1 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -5,4 +5,32 @@ describe Registrar do it { should have_many(:domains) } it { should have_many(:api_users) } it { should have_many(:messages) } + + context 'with invalid attribute' do + before :all do + @registrar = Registrar.new + end + + it 'is not valid' do + @registrar.valid? + @registrar.errors.full_messages.should match_array([ + 'Address is missing', + 'Contact e-mail is missing', + 'Country is missing', + 'Name is missing', + 'Reg no is missing' + ]) + end + + it 'returns an error with invalid email' do + @registrar.email = 'bla' + @registrar.billing_email = 'bla' + + @registrar.valid? + @registrar.errors[:email].should == ['is invalid'] + @registrar.errors[:billing_email].should == ['is invalid'] + end + + + end end