Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Martin Lensment 2014-10-07 17:04:32 +03:00
commit f104cf8a17
13 changed files with 139 additions and 31 deletions

View file

@ -2,7 +2,7 @@ class Client::ContactsController < ClientController
before_action :set_contact, only: [:show, :destroy, :edit, :update]
def index
@q = Contact.search(params[:q])
@q = Contact.current_registrars(current_registrar.id).search(params[:q])
@contacts = @q.result.page(params[:page])
end
@ -11,9 +11,17 @@ class Client::ContactsController < ClientController
@contact.build_address
end
def show
if @contact.registrar != current_registrar
flash[:alert] = I18n.t('shared.authentication_error')
redirect_to client_contacts_path
end
end
def create
@contact = Contact.new(contact_params)
@contact.generate_code
@contact.registrar = current_registrar
if @contact.save
flash[:notice] = I18n.t('shared.contact_added')
redirect_to [:client, @contact]

View file

@ -2,6 +2,7 @@ module Epp::ContactsHelper
def create_contact
@contact = Contact.new(contact_and_address_attributes)
@contact.generate_code
@contact.registrar = current_epp_user.registrar
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact)
@ -113,7 +114,8 @@ module Epp::ContactsHelper
def owner?
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') }
false
end

View file

@ -13,12 +13,14 @@ class Contact < ActiveRecord::Base
has_many :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 :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
belongs_to :registrar
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 :presence_of_one_address
@ -33,6 +35,8 @@ class Contact < ActiveRecord::Base
delegate :street, to: :address#, prefix: true
delegate :zip, to: :address#, prefix: true
#scopes
scope :current_registrars, ->(id) { where(registrar_id: id) }
# archiving
has_paper_trail class_name: 'ContactVersion'

View file

@ -1,6 +1,7 @@
class Registrar < ActiveRecord::Base
belongs_to :country
has_many :domains, :dependent => :restrict_with_error
has_many :contacts, :dependent => :restrict_with_error
has_many :epp_users, :dependent => :restrict_with_error
has_many :users, :dependent => :restrict_with_error

View file

@ -2,6 +2,7 @@
#
# Build and run everything for automatic tests
#
set -o pipefail
# cd to Rails root directory

View file

@ -414,3 +414,6 @@ en:
failed_to_update_record: 'Failed to update record'
record_deleted: 'Record deleted'
failed_to_delete_record: 'Failed to delete record'
# sorry these need to be refactored - Andres
authentication_error: 'Authentication error'

View file

@ -0,0 +1,5 @@
class AddRegistrarToContacts < ActiveRecord::Migration
def change
add_column :contacts, :registrar_id, :integer
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: 20141006124904) do
ActiveRecord::Schema.define(version: 20141006130306) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -81,6 +81,7 @@ ActiveRecord::Schema.define(version: 20141006124904) do
t.string "auth_info"
t.string "name"
t.string "org_name"
t.integer "registrar_id"
end
create_table "countries", force: true do |t|

View file

@ -6,29 +6,62 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
Country.where(name: 'Estonia', iso: 'EE').first_or_create
Country.where(name: 'Latvia', iso: 'LV').first_or_create
Country.where(name: 'Estonia', iso: 'EE').first_or_create!
Country.where(name: 'Latvia', iso: 'LV').first_or_create!
zone = Registrar.where(
name: 'Zone Media OÜ',
reg_no: '10577829',
address: 'Lõõtsa 2, Tallinna linn, Harju maakond, 11415'
#country: Country.first
).first_or_create
address: 'Lõõtsa 2, Tallinna linn, Harju maakond, 11415',
country: Country.first
).first_or_create!
EppUser.where(username: 'zone', password: 'ghyt9e4fu', active: true, registrar: zone).first_or_create
EppUser.where(
username: 'zone',
password: 'ghyt9e4fu',
active: true,
registrar: zone
).first_or_create!
elkdata = Registrar.where(
name: 'Elkdata OÜ',
reg_no: '10510593',
address: 'Tondi 51-10, 11316 Tallinn'
#country: Country.first
).first_or_create
address: 'Tondi 51-10, 11316 Tallinn',
country: Country.first
).first_or_create!
EppUser.where(username: 'elkdata', password: '8932iods', active: true, registrar: elkdata).first_or_create
EppUser.where(
username: 'elkdata',
password: '8932iods',
active: true,
registrar: elkdata
).first_or_create!
User.where(username: 'gitlab', password: '12345', email: 'enquiries@gitlab.eu', admin: true, identity_code: '37810013855', country: Country.where(name: 'Estonia').first).first_or_create
User.where(username: 'zone', password: '54321', email: 'info-info@zone.ee', admin: false, identity_code: '37810010085',
registrar_id: zone.id, country: Country.where(name: 'Estonia').first).first_or_create
User.where(username: 'elkdata', password: '32154', email: 'info-info@elkdata.ee', admin: false, identity_code: '37810010727',
registrar_id: elkdata.id, country: Country.where(name: 'Estonia').first).first_or_create
User.where(
username: 'gitlab',
password: '12345',
email: 'enquiries@gitlab.eu',
admin: true,
identity_code: '37810013855',
country: Country.where(name: 'Estonia').first
).first_or_create!
User.where(
username: 'zone',
password: '54321',
email: 'info-info@zone.ee',
admin: false,
identity_code: '37810010085',
registrar_id: zone.id,
country: Country.where(name: 'Estonia').first
).first_or_create!
User.where(
username: 'elkdata',
password: '32154',
email: 'info-info@elkdata.ee',
admin: false,
identity_code: '37810010727',
registrar_id: elkdata.id,
country: Country.where(name: 'Estonia').first
).first_or_create!

View file

@ -48,6 +48,17 @@ describe 'EPP Contact', epp: true do
expect(Contact.first.address.street3).to eq nil
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
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')
end
it 'stamps updated_by succesfully' do
it 'stamps updated_by succesfully', pending: true do
Fabricate(:contact, code: 'sh8013', created_by_id: zone.id)
expect(Contact.first.updated_by_id).to be nil
@ -115,7 +126,7 @@ describe 'EPP Contact', epp: true do
end
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')
expect(response[:msg]).to eq('Command completed successfully')
@ -126,7 +137,7 @@ describe 'EPP Contact', epp: true do
end
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')
@ -138,7 +149,7 @@ describe 'EPP Contact', epp: true do
end
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))
epp_request('contacts/update.xml')
@ -158,7 +169,7 @@ describe 'EPP Contact', epp: true do
end
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')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
@ -174,10 +185,7 @@ describe 'EPP Contact', epp: true do
end
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,
# registrar: elkdata,
# owner_contact: Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id))
Fabricate(:domain, owner_contact: Fabricate(:contact, code: 'dwa1234', created_by_id: zone.id, registrar: zone), registrar: zone)
expect(Domain.first.owner_contact.address.present?).to be true
response = epp_request('contacts/delete.xml')

View file

@ -7,5 +7,6 @@ Fabricator(:contact) do
ident_type 'op'
auth_info 'ccds4324pok'
address
registrar { Fabricate(:registrar, name: Faker::Company.name, reg_no: Faker::Company.duns_number) }
disclosure { Fabricate(:contact_disclosure) }
end

View 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

View file

@ -25,7 +25,8 @@ describe Contact do
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
email: ['Required parameter missing - email', 'Email is invalid'],
ident: ['Required parameter missing - ident'],
address: ['is missing']
address: ['is missing'],
registrar: ['is missing']
})
end
end
@ -73,11 +74,13 @@ end
describe Contact, '#up_id' 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
it 'should return username of updater' do
expect(Contact.first.up_id).to eq('gitlab')
expect(@contact.up_id).to eq('gitlab')
end
it 'should return nil when no updater' do