diff --git a/CHANGELOG.md b/CHANGELOG.md index 889aff165..68391b057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 2ee87d24c..5b0a39bbf 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index a9dfe8cbb..b6be9f76d 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index a1f781971..d85292bad 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -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? diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 3136beabd..8054d590b 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -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 diff --git a/app/views/registrar/contacts/form_partials/_general.haml b/app/views/registrar/contacts/form_partials/_general.haml index b5f9eb0f9..a6ecbb500 100644 --- a/app/views/registrar/contacts/form_partials/_general.haml +++ b/app/views/registrar/contacts/form_partials/_general.haml @@ -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) diff --git a/app/views/registrar/contacts/partials/_general.haml b/app/views/registrar/contacts/partials/_general.haml index b0728120c..37bd87555 100644 --- a/app/views/registrar/contacts/partials/_general.haml +++ b/app/views/registrar/contacts/partials/_general.haml @@ -10,7 +10,6 @@ %dd = text_field_tag :password, @contact.password, readonly: true, class: 'partially-hidden' - %br %dt= t(:ident) diff --git a/app/views/registrar/contacts/partials/_statuses.haml b/app/views/registrar/contacts/partials/_statuses.haml index 5d41db972..c926c04cf 100644 --- a/app/views/registrar/contacts/partials/_statuses.haml +++ b/app/views/registrar/contacts/partials/_statuses.haml @@ -12,5 +12,3 @@ %tr %td= s.first %td= s.second - - diff --git a/config/locales/en.yml b/config/locales/en.yml index a7af25dcf..df6c53b77 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/db/migrate/20150903105659_add_updated_token.rb b/db/migrate/20150903105659_add_updated_token.rb new file mode 100644 index 000000000..9e6418c60 --- /dev/null +++ b/db/migrate/20150903105659_add_updated_token.rb @@ -0,0 +1,5 @@ +class AddUpdatedToken < ActiveRecord::Migration + def change + add_column :contacts, :legacy_ident_updated_at, :datetime + end +end diff --git a/db/migrate/20150921110152_update_contacts_logs.rb b/db/migrate/20150921110152_update_contacts_logs.rb new file mode 100644 index 000000000..a43cb997a --- /dev/null +++ b/db/migrate/20150921110152_update_contacts_logs.rb @@ -0,0 +1,5 @@ +class UpdateContactsLogs < ActiveRecord::Migration + def change + add_column :log_contacts, :legacy_ident_updated_at, :datetime + end +end diff --git a/db/migrate/20150921111842_rename_contact_ident_updator.rb b/db/migrate/20150921111842_rename_contact_ident_updator.rb new file mode 100644 index 000000000..43dc40d9a --- /dev/null +++ b/db/migrate/20150921111842_rename_contact_ident_updator.rb @@ -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 diff --git a/db/schema-read-only.rb b/db/schema-read-only.rb index 615e64008..ca244af5f 100644 --- a/db/schema-read-only.rb +++ b/db/schema-read-only.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 75246ec42..fbe00eb4d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'); + diff --git a/doc/schemas/eis-1.0.xsd b/doc/schemas/eis-1.0.xsd index 262281cca..8093c832d 100644 --- a/doc/schemas/eis-1.0.xsd +++ b/doc/schemas/eis-1.0.xsd @@ -90,7 +90,7 @@ - + diff --git a/lib/schemas/eis-1.0.xsd b/lib/schemas/eis-1.0.xsd index 262281cca..8093c832d 100644 --- a/lib/schemas/eis-1.0.xsd +++ b/lib/schemas/eis-1.0.xsd @@ -90,7 +90,7 @@ - + diff --git a/lib/sorted_country.rb b/lib/sorted_country.rb index d05a31bab..1fc514d3f 100644 --- a/lib/sorted_country.rb +++ b/lib/sorted_country.rb @@ -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 diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 79d96030b..23c180647 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -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)