110687814-migrations_and_values

This commit is contained in:
Stas 2016-02-25 13:54:46 +02:00
parent 185e1d5c93
commit 577762a2bc
5 changed files with 24 additions and 3 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,5 @@
class AddUpIdValueToDomain < ActiveRecord::Migration
def change
add_column :domains, :upid, :string
end
end

View file

@ -0,0 +1,5 @@
class AddUpIdValueToContact < ActiveRecord::Migration
def change
add_column :contacts, :upid, :string
end
end