mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Api log contains only username + refactor #2793
This commit is contained in:
parent
682d2918ce
commit
7f44227370
8 changed files with 33 additions and 42 deletions
|
@ -56,15 +56,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_for_paper_trail
|
def user_for_paper_trail
|
||||||
if defined?(current_user) && current_user.present?
|
user_log_str(current_user)
|
||||||
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in
|
|
||||||
# before current_user is defined. PaperTrail is triggered also at current_user
|
|
||||||
api_user_log_str(current_user)
|
|
||||||
elsif current_user.present?
|
|
||||||
"#{current_user.id}-#{current_user.username}"
|
|
||||||
else
|
|
||||||
'public'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def depp_current_user
|
def depp_current_user
|
||||||
|
@ -74,11 +66,8 @@ class ApplicationController < ActionController::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_user_log_str(user)
|
def user_log_str(user)
|
||||||
if user.present?
|
return 'public' if user.nil?
|
||||||
"#{user.id}-api-#{user.username}"
|
"#{user.id}-#{user.class}: #{user.username}"
|
||||||
else
|
|
||||||
'api-public'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -120,7 +120,7 @@ class EppController < ApplicationController
|
||||||
@current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
@current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
||||||
# by default PaperTrail uses before filter and at that
|
# by default PaperTrail uses before filter and at that
|
||||||
# time current_user is not yet present
|
# time current_user is not yet present
|
||||||
::PaperTrail.whodunnit = api_user_log_str(@current_user)
|
::PaperTrail.whodunnit = user_log_str(@current_user)
|
||||||
::PaperSession.session = epp_session.session_id if epp_session.session_id.present?
|
::PaperSession.session = epp_session.session_id if epp_session.session_id.present?
|
||||||
@current_user
|
@current_user
|
||||||
end
|
end
|
||||||
|
@ -350,6 +350,7 @@ class EppController < ApplicationController
|
||||||
# rubocop: enable Style/PredicateName
|
# rubocop: enable Style/PredicateName
|
||||||
|
|
||||||
# rubocop: disable Metrics/CyclomaticComplexity
|
# rubocop: disable Metrics/CyclomaticComplexity
|
||||||
|
# rubocop: disable Metrics/PerceivedComplexity
|
||||||
def write_to_epp_log
|
def write_to_epp_log
|
||||||
# return nil if EPP_LOG_ENABLED
|
# return nil if EPP_LOG_ENABLED
|
||||||
request_command = params[:command] || params[:action] # error receives :command, other methods receive :action
|
request_command = params[:command] || params[:action] # error receives :command, other methods receive :action
|
||||||
|
@ -366,12 +367,13 @@ class EppController < ApplicationController
|
||||||
request_successful: epp_errors.empty?,
|
request_successful: epp_errors.empty?,
|
||||||
request_object: params[:epp_object_type],
|
request_object: params[:epp_object_type],
|
||||||
response: @response,
|
response: @response,
|
||||||
api_user_name: api_user_log_str(@api_user || current_user),
|
api_user_name: @api_user.try(:username) || current_user.try(:username) || 'api-public',
|
||||||
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
|
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
|
||||||
ip: request.ip
|
ip: request.ip
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/CyclomaticComplexity
|
# rubocop: enable Metrics/CyclomaticComplexity
|
||||||
|
# rubocop: enable Metrics/PerceivedComplexity
|
||||||
|
|
||||||
def iptables_counter_update
|
def iptables_counter_update
|
||||||
return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true'
|
return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true'
|
||||||
|
|
|
@ -20,17 +20,15 @@ module Versions
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# needs refactoring
|
|
||||||
# TODO: optimization work
|
|
||||||
# belongs_to :api_creator, class_name: 'ApiUser', foreign_key: :creator_str
|
|
||||||
# belongs_to :creator, class_name: 'User', foreign_key: :creator_str
|
|
||||||
def creator
|
def creator
|
||||||
return nil if creator_str.blank?
|
return nil if creator_str.blank?
|
||||||
|
|
||||||
if creator_str =~ /^\d-api-/
|
if creator_str =~ /^\d+-AdminUser:/
|
||||||
creator = ApiUser.find_by(id: creator_str)
|
|
||||||
else
|
|
||||||
creator = AdminUser.find_by(id: creator_str)
|
creator = AdminUser.find_by(id: creator_str)
|
||||||
|
elsif creator_str =~ /^\d+-ApiUser:/
|
||||||
|
creator = ApiUser.find_by(id: creator_str)
|
||||||
|
elsif creator_str =~ /^\d+-api-/ # depricated
|
||||||
|
creator = ApiUser.find_by(id: creator_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
creator.present? ? creator : creator_str
|
creator.present? ? creator : creator_str
|
||||||
|
@ -39,10 +37,12 @@ module Versions
|
||||||
def updator
|
def updator
|
||||||
return nil if updator_str.blank?
|
return nil if updator_str.blank?
|
||||||
|
|
||||||
if updator_str =~ /^\d-api-/
|
if updator_str =~ /^\d+-AdminUser:/
|
||||||
updator = ApiUser.find_by(id: updator_str)
|
|
||||||
else
|
|
||||||
updator = AdminUser.find_by(id: updator_str)
|
updator = AdminUser.find_by(id: updator_str)
|
||||||
|
elsif updator_str =~ /^\d+-ApiUser:/
|
||||||
|
updator = ApiUser.find_by(id: updator_str)
|
||||||
|
elsif updator_str =~ /^\d+-api-/ # depricated
|
||||||
|
updator = ApiUser.find_by(id: updator_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
updator.present? ? updator : updator_str
|
updator.present? ? updator : updator_str
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe 'EPP Contact', epp: true do
|
||||||
log.request_command.should == 'create'
|
log.request_command.should == 'create'
|
||||||
log.request_object.should == 'contact'
|
log.request_object.should == 'contact'
|
||||||
log.request_successful.should == true
|
log.request_successful.should == true
|
||||||
log.api_user_name.should == '1-api-registrar1'
|
log.api_user_name.should == 'registrar1'
|
||||||
log.api_user_registrar.should == 'registrar1'
|
log.api_user_registrar.should == 'registrar1'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ describe 'EPP Domain', epp: true do
|
||||||
log.request_command.should == 'create'
|
log.request_command.should == 'create'
|
||||||
log.request_object.should == 'domain'
|
log.request_object.should == 'domain'
|
||||||
log.request_successful.should == false
|
log.request_successful.should == false
|
||||||
log.api_user_name.should == '1-api-registrar1'
|
log.api_user_name.should == 'registrar1'
|
||||||
log.api_user_registrar.should == 'registrar1'
|
log.api_user_registrar.should == 'registrar1'
|
||||||
log.request.should_not be_blank
|
log.request.should_not be_blank
|
||||||
log.response.should_not be_blank
|
log.response.should_not be_blank
|
||||||
|
@ -1061,7 +1061,7 @@ describe 'EPP Domain', epp: true do
|
||||||
log.request_command.should == 'transfer'
|
log.request_command.should == 'transfer'
|
||||||
log.request_object.should == 'domain'
|
log.request_object.should == 'domain'
|
||||||
log.request_successful.should == true
|
log.request_successful.should == true
|
||||||
log.api_user_name.should == '2-api-registrar2'
|
log.api_user_name.should == 'registrar2'
|
||||||
log.api_user_registrar.should == 'registrar2'
|
log.api_user_registrar.should == 'registrar2'
|
||||||
log.request.should_not be_blank
|
log.request.should_not be_blank
|
||||||
log.response.should_not be_blank
|
log.response.should_not be_blank
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe 'EPP Poll', epp: true do
|
||||||
log.request_command.should == 'poll'
|
log.request_command.should == 'poll'
|
||||||
log.request_object.should == 'poll'
|
log.request_object.should == 'poll'
|
||||||
log.request_successful.should == true
|
log.request_successful.should == true
|
||||||
log.api_user_name.should == '1-api-registrar1'
|
log.api_user_name.should == 'registrar1'
|
||||||
log.api_user_registrar.should == @registrar1.name
|
log.api_user_registrar.should == @registrar1.name
|
||||||
log.request.should_not be_blank
|
log.request.should_not be_blank
|
||||||
log.response.should_not be_blank
|
log.response.should_not be_blank
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe 'EPP Session', epp: true do
|
||||||
log = ApiLog::EppLog.last
|
log = ApiLog::EppLog.last
|
||||||
log.request_command.should == 'login'
|
log.request_command.should == 'login'
|
||||||
log.request_successful.should == false
|
log.request_successful.should == false
|
||||||
log.api_user_name.should == '2-api-inactive-user'
|
log.api_user_name.should == 'inactive-user'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prohibits further actions unless logged in' do
|
it 'prohibits further actions unless logged in' do
|
||||||
|
@ -88,7 +88,7 @@ describe 'EPP Session', epp: true do
|
||||||
log = ApiLog::EppLog.last
|
log = ApiLog::EppLog.last
|
||||||
log.request_command.should == 'login'
|
log.request_command.should == 'login'
|
||||||
log.request_successful.should == true
|
log.request_successful.should == true
|
||||||
log.api_user_name.should == '1-api-gitlab'
|
log.api_user_name.should == 'gitlab'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not log in twice' do
|
it 'does not log in twice' do
|
||||||
|
@ -104,7 +104,7 @@ describe 'EPP Session', epp: true do
|
||||||
log = ApiLog::EppLog.last
|
log = ApiLog::EppLog.last
|
||||||
log.request_command.should == 'login'
|
log.request_command.should == 'login'
|
||||||
log.request_successful.should == false
|
log.request_successful.should == false
|
||||||
log.api_user_name.should == '1-api-gitlab'
|
log.api_user_name.should == 'gitlab'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'logs out epp user' do
|
it 'logs out epp user' do
|
||||||
|
|
|
@ -387,10 +387,10 @@ describe Domain do
|
||||||
@api_user = Fabricate(:api_user)
|
@api_user = Fabricate(:api_user)
|
||||||
@user.id.should == 1
|
@user.id.should == 1
|
||||||
@api_user.id.should == 2
|
@api_user.id.should == 2
|
||||||
::PaperTrail.whodunnit = '2-api-testuser'
|
::PaperTrail.whodunnit = '2-ApiUser: testuser'
|
||||||
|
|
||||||
@domain = Fabricate(:domain)
|
@domain = Fabricate(:domain)
|
||||||
@domain.creator_str.should == '2-api-testuser'
|
@domain.creator_str.should == '2-ApiUser: testuser'
|
||||||
|
|
||||||
@domain.creator.should == @api_user
|
@domain.creator.should == @api_user
|
||||||
@domain.creator.should_not == @user
|
@domain.creator.should_not == @user
|
||||||
|
@ -399,14 +399,14 @@ describe Domain do
|
||||||
|
|
||||||
it 'should return api_creator when created by api user' do
|
it 'should return api_creator when created by api user' do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
@user = Fabricate(:admin_user)
|
@user = Fabricate(:admin_user, id: 1000)
|
||||||
@api_user = Fabricate(:api_user)
|
@api_user = Fabricate(:api_user, id: 2000)
|
||||||
@user.id.should == 3
|
@user.id.should == 1000
|
||||||
@api_user.id.should == 4
|
@api_user.id.should == 2000
|
||||||
::PaperTrail.whodunnit = '3-testuser'
|
::PaperTrail.whodunnit = '1000-AdminUser: testuser'
|
||||||
|
|
||||||
@domain = Fabricate(:domain)
|
@domain = Fabricate(:domain)
|
||||||
@domain.creator_str.should == '3-testuser'
|
@domain.creator_str.should == '1000-AdminUser: testuser'
|
||||||
|
|
||||||
@domain.creator.should == @user
|
@domain.creator.should == @user
|
||||||
@domain.creator.should_not == @api_user
|
@domain.creator.should_not == @api_user
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue