Added current_user for papertrail

This commit is contained in:
Priit Tark 2015-01-29 15:37:40 +02:00
parent aebe137978
commit 1591d6a7b4
5 changed files with 29 additions and 22 deletions

View file

@ -13,6 +13,16 @@ class ApplicationController < ActionController::Base
return session[:user_return_to].to_s if session[:user_return_to] && session[:user_return_to] != login_path return session[:user_return_to].to_s if session[:user_return_to] && session[:user_return_to] != login_path
admin_dashboard_path admin_dashboard_path
end end
def user_for_paper_trail
if defined?(current_api_user) && current_api_user.present?
"#{current_api_user.id}-api-#{current_api_user.username}"
elsif current_user.present?
"#{current_user.id}-#{current_user.username}"
else
'public'
end
end
end end
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base

View file

@ -1,15 +1,15 @@
module Shared::UserStamper module Shared::UserStamper
extend ActiveSupport::Concern extend ActiveSupport::Concern
def stamp(obj) # def stamp(obj)
return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id) # return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
if obj.new_record? # if obj.new_record?
obj.created_by_id = current_api_user.id # obj.created_by_id = current_api_user.id
else # else
obj.updated_by_id = current_api_user.id # obj.updated_by_id = current_api_user.id
end # end
true # true
end # end
end end

View file

@ -1,15 +1,10 @@
class Epp::ContactsController < EppController class Epp::ContactsController < EppController
include Shared::UserStamper ## Refactor this?
helper WhodunnitHelper ## Refactor this? helper WhodunnitHelper ## Refactor this?
def user_for_paper_trail ## Refactor this?
current_api_user ? "#{current_api_user.id}-ApiUser" : nil
end
def create def create
@contact = Contact.new(contact_and_address_attributes) @contact = Contact.new(contact_and_address_attributes)
@contact.registrar = current_api_user.registrar @contact.registrar = current_api_user.registrar
render_epp_response '/epp/contacts/create' and return if stamp(@contact) && @contact.save render_epp_response '/epp/contacts/create' and return if @contact.save
handle_errors(@contact) handle_errors(@contact)
end end
@ -18,8 +13,8 @@ class Epp::ContactsController < EppController
code = params_hash['epp']['command']['update']['update'][:id] code = params_hash['epp']['command']['update']['update'][:id]
@contact = Contact.where(code: code).first @contact = Contact.where(code: code).first
# if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) # if update_rights? && @contact.update_attributes(contact_and_address_attributes(:update))
if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) if owner? && @contact.update_attributes(contact_and_address_attributes(:update))
render_epp_response 'epp/contacts/update' render_epp_response 'epp/contacts/update'
else else
contact_exists?(code) contact_exists?(code)

View file

@ -25,6 +25,11 @@ class EppController < ApplicationController
@current_api_user ||= ApiUser.find(epp_session[:api_user_id]) if epp_session[:api_user_id] @current_api_user ||= ApiUser.find(epp_session[:api_user_id]) if epp_session[:api_user_id]
end end
# temp until Martin is ready
def current_api_user
@current_epp_user ||= EppUser.find(epp_session[:epp_user_id]) if epp_session[:epp_user_id]
end
# ERROR + RESPONSE HANDLING # ERROR + RESPONSE HANDLING
def epp_errors def epp_errors
@errors ||= [] @errors ||= []

View file

@ -9,9 +9,6 @@ class Contact < ActiveRecord::Base
has_many :domains, through: :domain_contacts has_many :domains, through: :domain_contacts
has_many :statuses, class_name: 'ContactStatus' has_many :statuses, class_name: 'ContactStatus'
# TODO: remove the x_by
belongs_to :created_by, class_name: 'ApiUser', foreign_key: :created_by_id
belongs_to :updated_by, class_name: 'ApiUser', foreign_key: :updated_by_id
belongs_to :registrar belongs_to :registrar
accepts_nested_attributes_for :address, :disclosure accepts_nested_attributes_for :address, :disclosure
@ -88,11 +85,11 @@ class Contact < ActiveRecord::Base
end end
def cr_id def cr_id
created_by ? created_by.username : nil # created_by ? created_by.username : nil
end end
def up_id def up_id
updated_by ? updated_by.username : nil # updated_by ? updated_by.username : nil
end end
def auth_info_matches(pw) def auth_info_matches(pw)