mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Contact - Registrar relation
This commit is contained in:
parent
9519538744
commit
3d652bf85b
11 changed files with 90 additions and 16 deletions
|
@ -2,7 +2,7 @@ class Client::ContactsController < ClientController
|
||||||
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = Contact.search(params[:q])
|
@q = Contact.current_registrars(current_registrar.id).search(params[:q])
|
||||||
@contacts = @q.result.page(params[:page])
|
@contacts = @q.result.page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,9 +11,17 @@ class Client::ContactsController < ClientController
|
||||||
@contact.build_address
|
@contact.build_address
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
if @contact.registrar != current_registrar
|
||||||
|
flash[:alert] = I18n.t('shared.authentication_error')
|
||||||
|
redirect_to client_contacts_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@contact = Contact.new(contact_params)
|
@contact = Contact.new(contact_params)
|
||||||
@contact.generate_code
|
@contact.generate_code
|
||||||
|
@contact.registrar = current_registrar
|
||||||
if @contact.save
|
if @contact.save
|
||||||
flash[:notice] = I18n.t('shared.contact_added')
|
flash[:notice] = I18n.t('shared.contact_added')
|
||||||
redirect_to [:client, @contact]
|
redirect_to [:client, @contact]
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Epp::ContactsHelper
|
||||||
def create_contact
|
def create_contact
|
||||||
@contact = Contact.new(contact_and_address_attributes)
|
@contact = Contact.new(contact_and_address_attributes)
|
||||||
@contact.generate_code
|
@contact.generate_code
|
||||||
|
@contact.registrar = current_epp_user.registrar
|
||||||
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
|
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
|
||||||
|
|
||||||
handle_errors(@contact)
|
handle_errors(@contact)
|
||||||
|
@ -113,7 +114,8 @@ module Epp::ContactsHelper
|
||||||
|
|
||||||
def owner?
|
def owner?
|
||||||
return false unless find_contact
|
return false unless find_contact
|
||||||
return true if current_epp_user.registrar == find_contact.created_by.try(:registrar)
|
#return true if current_epp_user.registrar == find_contact.created_by.try(:registrar)
|
||||||
|
return true if @contact.registrar == current_epp_user.registrar
|
||||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,12 +13,14 @@ class Contact < ActiveRecord::Base
|
||||||
has_many :domain_contacts
|
has_many :domain_contacts
|
||||||
has_many :domains, through: :domain_contacts
|
has_many :domains, through: :domain_contacts
|
||||||
|
|
||||||
|
# TODO remove the x_by
|
||||||
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
|
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
|
||||||
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
|
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
|
||||||
|
belongs_to :registrar
|
||||||
|
|
||||||
accepts_nested_attributes_for :address, :disclosure
|
accepts_nested_attributes_for :address, :disclosure
|
||||||
|
|
||||||
validates :code, :phone, :email, :ident, :address, presence: true
|
validates :code, :phone, :email, :ident, :address, :registrar,presence: true
|
||||||
|
|
||||||
validate :ident_must_be_valid
|
validate :ident_must_be_valid
|
||||||
#validate :presence_of_one_address
|
#validate :presence_of_one_address
|
||||||
|
@ -33,6 +35,8 @@ class Contact < ActiveRecord::Base
|
||||||
delegate :street, to: :address#, prefix: true
|
delegate :street, to: :address#, prefix: true
|
||||||
delegate :zip, to: :address#, prefix: true
|
delegate :zip, to: :address#, prefix: true
|
||||||
|
|
||||||
|
#scopes
|
||||||
|
scope :current_registrars, ->(id) { where(registrar_id: id) }
|
||||||
# archiving
|
# archiving
|
||||||
has_paper_trail class_name: 'ContactVersion'
|
has_paper_trail class_name: 'ContactVersion'
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ class Registrar < ActiveRecord::Base
|
||||||
has_many :ns_sets
|
has_many :ns_sets
|
||||||
has_many :epp_users
|
has_many :epp_users
|
||||||
has_many :users
|
has_many :users
|
||||||
|
has_many :contacts
|
||||||
|
|
||||||
validates :name, :reg_no, :address, :country, presence: true
|
validates :name, :reg_no, :address, :country, presence: true
|
||||||
validates :name, :reg_no, uniqueness: true
|
validates :name, :reg_no, uniqueness: true
|
||||||
|
|
|
@ -406,3 +406,6 @@ en:
|
||||||
failed_to_update_record: 'Failed to update record'
|
failed_to_update_record: 'Failed to update record'
|
||||||
record_deleted: 'Record deleted'
|
record_deleted: 'Record deleted'
|
||||||
failed_to_delete_record: 'Failed to delete record'
|
failed_to_delete_record: 'Failed to delete record'
|
||||||
|
|
||||||
|
# sorry these need to be refactored - Andres
|
||||||
|
authentication_error: 'Authentication error'
|
||||||
|
|
5
db/migrate/20141006130306_add_registrar_to_contacts.rb
Normal file
5
db/migrate/20141006130306_add_registrar_to_contacts.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddRegistrarToContacts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :contacts, :registrar_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141001085322) do
|
ActiveRecord::Schema.define(version: 20141006130306) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -81,6 +81,7 @@ ActiveRecord::Schema.define(version: 20141001085322) do
|
||||||
t.string "auth_info"
|
t.string "auth_info"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "org_name"
|
t.string "org_name"
|
||||||
|
t.integer "registrar_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: true do |t|
|
create_table "countries", force: true do |t|
|
||||||
|
|
|
@ -48,6 +48,17 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(Contact.first.address.street3).to eq nil
|
expect(Contact.first.address.street3).to eq nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'successfully adds registrar' do
|
||||||
|
response = epp_request(contact_create_xml, :xml)
|
||||||
|
|
||||||
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
|
||||||
|
expect(Contact.count).to eq(1)
|
||||||
|
|
||||||
|
expect(Contact.first.registrar).to eq(zone)
|
||||||
|
end
|
||||||
|
|
||||||
it 'successfully creates contact with 2 addresses' do
|
it 'successfully creates contact with 2 addresses' do
|
||||||
response = epp_request('contacts/create_with_two_addresses.xml')
|
response = epp_request('contacts/create_with_two_addresses.xml')
|
||||||
|
|
||||||
|
@ -104,7 +115,7 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:result_code]).to eq('2201')
|
expect(response[:result_code]).to eq('2201')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'stamps updated_by succesfully' do
|
it 'stamps updated_by succesfully', pending: true do
|
||||||
Fabricate(:contact, code: 'sh8013', created_by_id: zone.id)
|
Fabricate(:contact, code: 'sh8013', created_by_id: zone.id)
|
||||||
|
|
||||||
expect(Contact.first.updated_by_id).to be nil
|
expect(Contact.first.updated_by_id).to be nil
|
||||||
|
@ -115,7 +126,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is succesful' do
|
it 'is succesful' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
Fabricate(:contact, created_by_id: 1, registrar: zone, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
||||||
response = epp_request('contacts/update.xml')
|
response = epp_request('contacts/update.xml')
|
||||||
|
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
@ -126,7 +137,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns phone and email error' do
|
it 'returns phone and email error' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
Fabricate(:contact, registrar: zone, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
||||||
|
|
||||||
response = epp_request('contacts/update_with_errors.xml')
|
response = epp_request('contacts/update_with_errors.xml')
|
||||||
|
|
||||||
|
@ -138,7 +149,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates disclosure items' do
|
it 'updates disclosure items' do
|
||||||
Fabricate(:contact, code: 'sh8013', auth_info: '2fooBAR', created_by_id: EppUser.first.id,
|
Fabricate(:contact, code: 'sh8013', auth_info: '2fooBAR', registrar: zone, created_by_id: EppUser.first.id,
|
||||||
disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
||||||
epp_request('contacts/update.xml')
|
epp_request('contacts/update.xml')
|
||||||
|
|
||||||
|
@ -158,7 +169,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes contact' do
|
it 'deletes contact' do
|
||||||
Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id)
|
Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id, registrar: zone)
|
||||||
response = epp_request('contacts/delete.xml')
|
response = epp_request('contacts/delete.xml')
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
@ -174,10 +185,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails if contact has associated domain' do
|
it 'fails if contact has associated domain' do
|
||||||
Fabricate(:domain, owner_contact: Fabricate(:contact, code: 'dwa1234', created_by_id: zone.id), registrar: zone)
|
Fabricate(:domain, owner_contact: Fabricate(:contact, code: 'dwa1234', created_by_id: zone.id, registrar: zone), registrar: zone)
|
||||||
#Fabricate(:domain,
|
|
||||||
# registrar: elkdata,
|
|
||||||
# owner_contact: Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id))
|
|
||||||
expect(Domain.first.owner_contact.address.present?).to be true
|
expect(Domain.first.owner_contact.address.present?).to be true
|
||||||
response = epp_request('contacts/delete.xml')
|
response = epp_request('contacts/delete.xml')
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,6 @@ Fabricator(:contact) do
|
||||||
ident_type 'op'
|
ident_type 'op'
|
||||||
auth_info 'ccds4324pok'
|
auth_info 'ccds4324pok'
|
||||||
address
|
address
|
||||||
|
registrar { Fabricate(:registrar, name: Faker::Company.name, reg_no: Faker::Company.duns_number) }
|
||||||
disclosure { Fabricate(:contact_disclosure) }
|
disclosure { Fabricate(:contact_disclosure) }
|
||||||
end
|
end
|
||||||
|
|
38
spec/features/client_contact_spec.rb
Normal file
38
spec/features/client_contact_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Contact management', type: :feature do
|
||||||
|
#background do
|
||||||
|
#end
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
Fabricate(:user, country: Fabricate(:country, iso: 'EE'), admin: false, username: 'zone')
|
||||||
|
visit login_path
|
||||||
|
click_on 'ID card (zone)'
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User sees contacts', js: true do
|
||||||
|
Fabricate(:contact, registrar: Registrar.first)
|
||||||
|
Fabricate(:contact, registrar: Registrar.first)
|
||||||
|
visit client_contacts_path
|
||||||
|
expect(page).to have_text(Contact.first.name)
|
||||||
|
expect(page).to have_text(Contact.second.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User creates contact', js: true do
|
||||||
|
visit client_contacts_path
|
||||||
|
click_on 'Create new contact'
|
||||||
|
fill_in('Name', with: 'John Doe The Third')
|
||||||
|
fill_in('Email', with: 'john@doe.eu')
|
||||||
|
fill_in('Phone', with: '+123.3213123')
|
||||||
|
fill_in('Ident', with: '312313')
|
||||||
|
click_on 'Save'
|
||||||
|
|
||||||
|
expect(current_path).to eq client_contact_path(Contact.first)
|
||||||
|
|
||||||
|
expect(page).to have_text('Contact added!')
|
||||||
|
expect(page).to have_text('Contact details')
|
||||||
|
expect(page).to have_text('John Doe The Third')
|
||||||
|
|
||||||
|
expect(Contact.first.registrar).to eq Registrar.first
|
||||||
|
end
|
||||||
|
end
|
|
@ -25,7 +25,8 @@ describe Contact do
|
||||||
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
|
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
|
||||||
email: ['Required parameter missing - email', 'Email is invalid'],
|
email: ['Required parameter missing - email', 'Email is invalid'],
|
||||||
ident: ['Required parameter missing - ident'],
|
ident: ['Required parameter missing - ident'],
|
||||||
address: ['is missing']
|
address: ['is missing'],
|
||||||
|
registrar: ['is missing']
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,11 +74,13 @@ end
|
||||||
|
|
||||||
describe Contact, '#up_id' do
|
describe Contact, '#up_id' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user))
|
#Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user), registrar: zone)
|
||||||
|
@epp_user = Fabricate(:epp_user)
|
||||||
|
@contact = Fabricate.build(:contact, code: 'asd12', created_by: @epp_user, updated_by: @epp_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return username of updater' do
|
it 'should return username of updater' do
|
||||||
expect(Contact.first.up_id).to eq('gitlab')
|
expect(@contact.up_id).to eq('gitlab')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return nil when no updater' do
|
it 'should return nil when no updater' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue