mirror of
https://github.com/internetee/registry.git
synced 2025-05-21 11:49:40 +02:00
Added current_user for papertrail
This commit is contained in:
parent
aebe137978
commit
1591d6a7b4
5 changed files with 29 additions and 22 deletions
|
@ -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
|
||||
admin_dashboard_path
|
||||
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
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
module Shared::UserStamper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def stamp(obj)
|
||||
return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
|
||||
# def stamp(obj)
|
||||
# return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
|
||||
|
||||
if obj.new_record?
|
||||
obj.created_by_id = current_api_user.id
|
||||
else
|
||||
obj.updated_by_id = current_api_user.id
|
||||
end
|
||||
# if obj.new_record?
|
||||
# obj.created_by_id = current_api_user.id
|
||||
# else
|
||||
# obj.updated_by_id = current_api_user.id
|
||||
# end
|
||||
|
||||
true
|
||||
end
|
||||
# true
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
class Epp::ContactsController < EppController
|
||||
include Shared::UserStamper ## 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
|
||||
@contact = Contact.new(contact_and_address_attributes)
|
||||
@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)
|
||||
end
|
||||
|
||||
|
@ -18,8 +13,8 @@ class Epp::ContactsController < EppController
|
|||
code = params_hash['epp']['command']['update']['update'][:id]
|
||||
|
||||
@contact = Contact.where(code: code).first
|
||||
# if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
# if update_rights? && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
if owner? && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
render_epp_response 'epp/contacts/update'
|
||||
else
|
||||
contact_exists?(code)
|
||||
|
|
|
@ -25,6 +25,11 @@ class EppController < ApplicationController
|
|||
@current_api_user ||= ApiUser.find(epp_session[:api_user_id]) if epp_session[:api_user_id]
|
||||
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
|
||||
def epp_errors
|
||||
@errors ||= []
|
||||
|
|
|
@ -9,9 +9,6 @@ class Contact < ActiveRecord::Base
|
|||
has_many :domains, through: :domain_contacts
|
||||
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
|
||||
|
||||
accepts_nested_attributes_for :address, :disclosure
|
||||
|
@ -88,11 +85,11 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def cr_id
|
||||
created_by ? created_by.username : nil
|
||||
# created_by ? created_by.username : nil
|
||||
end
|
||||
|
||||
def up_id
|
||||
updated_by ? updated_by.username : nil
|
||||
# updated_by ? updated_by.username : nil
|
||||
end
|
||||
|
||||
def auth_info_matches(pw)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue