Allow invalid ident update #2859

This commit is contained in:
Priit Tark 2015-09-23 12:32:26 +03:00
parent 0944bd2077
commit 4a32c7641c
18 changed files with 101 additions and 32 deletions

View file

@ -1,3 +1,6 @@
21.09.2015
* eis-1.0.xsd schema file updated without a new version, please publish a new updated schema file to public.
17.09.2015
* deploy-example.rb has been updated with `@cron_group`.

View file

@ -126,9 +126,6 @@ class Epp::ContactsController < EppController
contact_org_disabled
fax_disabled
status_editing_disabled
if params[:parsed_frame].css('ident').present?
epp_errors << { code: '2306', msg: "#{I18n.t(:ident_update_error)} [ident]" }
end
requires 'id'
@prefix = nil
end

View file

@ -34,6 +34,7 @@ class Contact < ActiveRecord::Base
after_initialize do
self.statuses = [] if statuses.nil?
self.status_notes = {} if status_notes.nil?
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
end
before_validation :set_ident_country_code

View file

@ -10,9 +10,9 @@ module Depp
DISABLED = 'Disabled'
DISCLOSURE_TYPES = [DISABLED, '1', '0']
TYPES = %w( bic priv birthday )
TYPES = %w( org priv birthday )
SELECTION_TYPES = [
['Business code', 'bic'],
['Business code', 'org'],
['Personal identification code', 'priv'],
['Birthday', 'birthday']
]
@ -163,7 +163,7 @@ module Depp
}
hash[:id] = nil if code.blank?
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml)
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml(:create))
data = Depp::Contact.user.request(create_xml)
self.id = data.css('id').text
@ -210,7 +210,7 @@ module Depp
}
}
},
extension_xml
extension_xml(:update)
)
data = Depp::Contact.user.request(update_xml)
handle_errors(data)
@ -224,15 +224,25 @@ module Depp
id: { value: id },
authInfo: { pw: { value: password } }
},
extension_xml
extension_xml(:delete)
)
data = Depp::Contact.user.request(delete_xml)
handle_errors(data)
end
def extension_xml
def extension_xml(action)
xml = { _anonymus: [] }
ident = ident_xml[:_anonymus].try(:first) unless persisted?
case action
when :create
ident = ident_xml[:_anonymus].try(:first)
when :update
# detect if any ident has changed
if !(ident == self.ident && ident == self.ident_type && ident_country_code == self.ident_country_code)
ident = ident_xml[:_anonymus].try(:first)
end
end
legal = legal_document_xml[:_anonymus].try(:first)
xml[:_anonymus] << ident if ident.present?
xml[:_anonymus] << legal if legal.present?

View file

@ -118,6 +118,7 @@ class Epp::Contact < Contact
[:ident, :invalid_EE_identity_format],
[:ident, :invalid_birthday_format],
[:ident, :invalid_country_code],
[:ident_type, :missing],
[:code, :invalid],
[:code, :too_long_contact_code]
],
@ -144,6 +145,20 @@ class Epp::Contact < Contact
legal_frame = frame.css('legalDocument').first
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
self.deliver_emails = true # turn on email delivery for epp
# allow to update ident code for legacy contacts
if frame.css('ident').first.present?
if ident_updated_at.present?
throw :epp_error, {
code: '2306',
msg: I18n.t(:ident_update_error)
}
else
at.merge!(self.class.ident_attrs(frame.css('ident').first))
self.ident_updated_at = Time.zone.now
end
end
super(at)
end

View file

@ -1,3 +1,11 @@
- ident_complete = f.object.ident_country_code.present? && f.object.ident_type.present? && f.object.ident.present?
- if @contact.persisted?
- country_selected = f.object.ident_country_code || (params[:depp_contact].try(:[], :ident_country_code))
- type_selected = f.object.ident_type || (params[:depp_contact].try(:[], :ident_type))
- else
- country_selected = (params[:depp_contact].try(:[], :ident_country_code) || 'EE')
- type_selected = (params[:depp_contact].try(:[], :ident_type) || 'org')
.panel.panel-default
.panel-heading.clearfix
.pull-left= t(:ident)
@ -6,12 +14,11 @@
.col-md-3.control-label
= f.label :ident_country_code, t(:country) + '*'
.col-md-7
- if @contact.persisted? && f.object.ident_country_code.present?
- if ident_complete && @contact.persisted? && f.object.ident_country_code.present?
.disabled-value
= Country.new(f.object.ident_country_code).try(:to_s)
= " [#{f.object.ident_country_code}]"
- else
- country_selected = @contact.persisted? ? '' : (params[:depp_contact].try(:[], :ident_country_code) || 'EE')
= f.select(:ident_country_code, SortedCountry.all_options(country_selected), {},
class: 'js-ident-country-code', required: true)
@ -19,25 +26,23 @@
.col-md-3.control-label
= f.label :ident_type, t(:type) + '*'
.col-md-7
- if @contact.persisted? && f.object.ident_type.present?
- if ident_complete && @contact.persisted? && f.object.ident_type.present?
.disabled-value
= Depp::Contact.type_string(f.object.ident_type)
= " [#{f.object.ident_type}]"
- else
- type_selected = @contact.persisted? ? '' : (params[:depp_contact].try(:[], :ident_type) || 'bic')
= f.select(:ident_type, Depp::Contact::SELECTION_TYPES,
{ selected: type_selected },
= f.select(:ident_type, Depp::Contact::SELECTION_TYPES, { selected: type_selected },
class: 'js-ident-type', required: true)
.form-group
.col-md-3.control-label
= f.label :ident, t(:ident) + '*'
.col-md-7
- if @contact.persisted? && f.object.ident.present?
- if ident_complete && @contact.persisted? && f.object.ident.present?
.disabled-value
= f.object.ident
- else
= f.text_field :ident, class: 'form-control', required: true, disabled: @contact.persisted?
= f.text_field :ident, class: 'form-control', required: true
- tip_visibility = f.object.ident_type == 'birthday' ? '' : 'display: none'
.js-ident-tip{ style: tip_visibility }
= t(:birthday_format)

View file

@ -10,7 +10,6 @@
%dd
= text_field_tag :password, @contact.password, readonly: true, class: 'partially-hidden'
%br
%dt= t(:ident)

View file

@ -12,5 +12,3 @@
%tr
%td= s.first
%td= s.second

View file

@ -148,7 +148,6 @@ en:
value:
taken: 'Status already exists on this domain'
user:
attributes:
username:
@ -515,7 +514,7 @@ en:
crt_revoked: 'CRT (revoked)'
contact_org_error: 'Parameter value policy error. Org must be blank'
contact_fax_error: 'Parameter value policy error. Fax must be blank'
ident_update_error: 'Parameter value policy error. Update of ident data not allowed'
ident_update_error: 'Parameter value policy error. Update of ident data not allowed [ident]'
invoices: 'Invoices'
no_such_user: 'No such user'
log_in: 'Log in'

View file

@ -0,0 +1,5 @@
class AddUpdatedToken < ActiveRecord::Migration
def change
add_column :contacts, :legacy_ident_updated_at, :datetime
end
end

View file

@ -0,0 +1,5 @@
class UpdateContactsLogs < ActiveRecord::Migration
def change
add_column :log_contacts, :legacy_ident_updated_at, :datetime
end
end

View file

@ -0,0 +1,6 @@
class RenameContactIdentUpdator < ActiveRecord::Migration
def change
rename_column :contacts, :legacy_ident_updated_at, :ident_updated_at
rename_column :log_contacts, :legacy_ident_updated_at, :ident_updated_at
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: 20150915094707) do
ActiveRecord::Schema.define(version: 20150921111842) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -203,6 +203,7 @@ ActiveRecord::Schema.define(version: 20150915094707) do
t.hstore "status_notes"
t.integer "legacy_history_id"
t.integer "copy_from_id"
t.datetime "ident_updated_at"
end
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
@ -585,15 +586,16 @@ ActiveRecord::Schema.define(version: 20150915094707) do
add_index "log_contact_statuses", ["whodunnit"], name: "index_log_contact_statuses_on_whodunnit", using: :btree
create_table "log_contacts", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
t.string "session"
t.json "children"
t.datetime "ident_updated_at"
end
add_index "log_contacts", ["item_type", "item_id"], name: "index_log_contacts_on_item_type_and_item_id", using: :btree

View file

@ -598,7 +598,8 @@ CREATE TABLE contacts (
statuses character varying[],
status_notes hstore,
legacy_history_id integer,
copy_from_id integer
copy_from_id integer,
ident_updated_at timestamp without time zone
);
@ -1502,7 +1503,8 @@ CREATE TABLE log_contacts (
object_changes json,
created_at timestamp without time zone,
session character varying,
children json
children json,
ident_updated_at timestamp without time zone
);
@ -4934,7 +4936,13 @@ INSERT INTO schema_migrations (version) VALUES ('20150825125118');
INSERT INTO schema_migrations (version) VALUES ('20150827151906');
INSERT INTO schema_migrations (version) VALUES ('20150903105659');
INSERT INTO schema_migrations (version) VALUES ('20150910113839');
INSERT INTO schema_migrations (version) VALUES ('20150915094707');
INSERT INTO schema_migrations (version) VALUES ('20150921110152');
INSERT INTO schema_migrations (version) VALUES ('20150921111842');

View file

@ -90,7 +90,7 @@
<simpleType name="identEnumType">
<restriction base="token">
<enumeration value="bic"/>
<enumeration value="org"/>
<enumeration value="priv"/>
<enumeration value="birthday"/>
</restriction>

View file

@ -90,7 +90,7 @@
<simpleType name="identEnumType">
<restriction base="token">
<enumeration value="bic"/>
<enumeration value="org"/>
<enumeration value="priv"/>
<enumeration value="birthday"/>
</restriction>

View file

@ -6,7 +6,7 @@ class SortedCountry
include ActionView::Helpers
def all_options(selected = nil)
quick_options = options_for_select([['', '']] + quick_list, { selected: selected })
quick_options = options_for_select(quick_list, { selected: selected })
# no double select
selected = quick_list.map(&:second).include?(selected) ? '' : selected

View file

@ -116,6 +116,10 @@ describe Contact do
@contact.valid?
@contact.errors[:email].should == ['Email is invalid']
end
it 'should have ident updated because the logic itself is dedicated for legacy contacts ' do
@contact.ident_updated_at.should_not == nil
end
end
context 'with valid attributes' do
@ -234,6 +238,18 @@ describe Contact do
contact.status_notes['someotherstatus'].should == nil
end
it 'should have ident already updated because the logic itself is only for legacy contacts' do
@contact.ident_updated_at.should_not == nil
end
it 'should have not update ident updated at when initializing old contact' do
# creating a legacy contact
contact = Fabricate(:contact)
contact.update_column(:ident_updated_at, nil)
Contact.find(contact.id).ident_updated_at.should == nil
end
context 'as birthday' do
before do
@domain = Fabricate(:domain)