From 577762a2bc25b534e8a06c5ff61507d94ec8fa41 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 25 Feb 2016 13:54:46 +0200 Subject: [PATCH] 110687814-migrations_and_values --- app/controllers/epp/contacts_controller.rb | 2 +- app/models/epp/contact.rb | 13 ++++++++++++- app/models/epp/domain.rb | 2 +- .../20160225113801_add_up_id_value_to_domain.rb | 5 +++++ .../20160225113812_add_up_id_value_to_contact.rb | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20160225113801_add_up_id_value_to_domain.rb create mode 100644 db/migrate/20160225113812_add_up_id_value_to_contact.rb diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 5b0a39bbf..22473bae7 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -29,7 +29,7 @@ class Epp::ContactsController < EppController def update authorize! :update, @contact, @password - if @contact.update_attributes(params[:parsed_frame]) + if @contact.update_attributes(params[:parsed_frame], current_user) render_epp_response 'epp/contacts/update' else handle_errors(@contact) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 54806b88d..7727666d2 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -1,16 +1,25 @@ class Epp::Contact < Contact include EppErrors + attr_accessor :current_user + # disable STI, there is type column present self.inheritance_column = :sti_disabled before_validation :manage_permissions + before_update :write_update_values + def manage_permissions return unless update_prohibited? || delete_prohibited? add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation)) false end + def write_update_values + self.upid = current_user.identity_code if current_user + self.updated_at = Time.zone.now + end + class << self # support legacy search def find_by_epp_code(code) @@ -142,7 +151,7 @@ class Epp::Contact < Contact end # rubocop:disable Metrics/AbcSize - def update_attributes(frame) + def update_attributes(frame, current_user) return super if frame.blank? at = {}.with_indifferent_access at.deep_merge!(self.class.attrs_from(frame.css('chg'), new_record: false)) @@ -177,6 +186,8 @@ class Epp::Contact < Contact end end + @current_user = current_user + super(at) end # rubocop:enable Metrics/AbcSize diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 62c6ee7ac..8769acc1e 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -17,7 +17,7 @@ class Epp::Domain < Domain end def write_update_values - self.updator_str = current_user.identity_code if current_user + self.upid = current_user.identity_code if current_user self.updated_at = Time.zone.now end diff --git a/db/migrate/20160225113801_add_up_id_value_to_domain.rb b/db/migrate/20160225113801_add_up_id_value_to_domain.rb new file mode 100644 index 000000000..df3d70e6f --- /dev/null +++ b/db/migrate/20160225113801_add_up_id_value_to_domain.rb @@ -0,0 +1,5 @@ +class AddUpIdValueToDomain < ActiveRecord::Migration + def change + add_column :domains, :upid, :string + end +end diff --git a/db/migrate/20160225113812_add_up_id_value_to_contact.rb b/db/migrate/20160225113812_add_up_id_value_to_contact.rb new file mode 100644 index 000000000..927950bd2 --- /dev/null +++ b/db/migrate/20160225113812_add_up_id_value_to_contact.rb @@ -0,0 +1,5 @@ +class AddUpIdValueToContact < ActiveRecord::Migration + def change + add_column :contacts, :upid, :string + end +end