diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index f80c0dc5b..a98fe137b 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -4,11 +4,24 @@ module Repp prefix :repp http_basic do |username, password| - @current_user ||= EppUser.find_by(username: username, password: password) + @current_api_user ||= EppUser.find_by(username: username, password: password) end helpers do - attr_reader :current_user + attr_reader :current_api_user + end + + after do + ApiLog::ReppLog.create({ + request_path: request.path, + request_method: request.request_method, + request_params: request.params.except('route_info').to_json, + response: @response.to_json, + response_code: status, + api_user_name: current_api_user.try(:username), + api_user_registrar: current_api_user.try(:registrar).try(:to_s), + ip: request.ip + }) end mount Repp::DomainV1 diff --git a/app/api/repp/contact_v1.rb b/app/api/repp/contact_v1.rb index 26c06796a..6f844bb0b 100644 --- a/app/api/repp/contact_v1.rb +++ b/app/api/repp/contact_v1.rb @@ -5,8 +5,8 @@ module Repp resource :contacts do desc 'Return list of contact' get '/' do - contacts = current_user.registrar.contacts.page(params[:page]) - { + contacts = current_api_user.registrar.contacts.page(params[:page]) + @response = { contacts: contacts, total_pages: contacts.total_pages } diff --git a/app/api/repp/domain_v1.rb b/app/api/repp/domain_v1.rb index d4bd071e9..430df0856 100644 --- a/app/api/repp/domain_v1.rb +++ b/app/api/repp/domain_v1.rb @@ -5,8 +5,8 @@ module Repp resource :domains do desc 'Return list of domains' get '/' do - domains = current_user.registrar.domains.page(params[:page]) - { + domains = current_api_user.registrar.domains.page(params[:page]) + @response = { domains: domains, total_pages: domains.total_pages } diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index 0799fa5f7..43f7fd52b 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -121,14 +121,15 @@ module Epp::Common def write_to_epp_log request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame] - ApiLog::EppLog.create!({ + ApiLog::EppLog.create({ request: params[:frame], request_command: params[:command], request_successful: epp_errors.empty?, request_object: request_object, response: @response, api_user_name: @epp_user.try(:to_s) || current_epp_user.try(:to_s), - api_user_registrar: @epp_user.try(:registrar).try(:to_s) || current_epp_user.try(:registrar).try(:to_s) + api_user_registrar: @epp_user.try(:registrar).try(:to_s) || current_epp_user.try(:registrar).try(:to_s), + ip: request.ip }) end end diff --git a/app/views/admin/epp_logs/show.haml b/app/views/admin/epp_logs/show.haml index e8c5f7ef8..faabc4acc 100644 --- a/app/views/admin/epp_logs/show.haml +++ b/app/views/admin/epp_logs/show.haml @@ -28,6 +28,9 @@ %dt= t('registrar') %dd= @epp_log.api_user_registrar + %dt= t('ip') + %dd= @epp_log.ip + %dt= t('created_at') %dd= @epp_log.created_at diff --git a/config/locales/en.yml b/config/locales/en.yml index 69b05f89c..a189cd60a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -489,3 +489,4 @@ en: request: 'Request' response: 'Response' details: 'Details' + ip: 'IP' diff --git a/db/api_log_schema.rb b/db/api_log_schema.rb index ecaee6605..1ba83581c 100644 --- a/db/api_log_schema.rb +++ b/db/api_log_schema.rb @@ -24,18 +24,20 @@ ActiveRecord::Schema.define(version: 0) do t.boolean "request_successful" t.string "api_user_name" t.string "api_user_registrar" + t.string "ip" t.datetime "created_at" t.datetime "updated_at" end create_table "repp_logs", force: true do |t| - t.text "request" + t.string "request_path" + t.string "request_method" + t.text "request_params" t.text "response" - t.string "request_command" - t.string "request_object" - t.boolean "request_successful" + t.string "response_code" t.string "api_user_name" t.string "api_user_registrar" + t.string "ip" t.datetime "created_at" t.datetime "updated_at" end diff --git a/db/migrate/20150109081914_create_api_log_tables.rb b/db/migrate/20150109081914_create_api_log_tables.rb index 7bb074c0e..c1dd695bd 100644 --- a/db/migrate/20150109081914_create_api_log_tables.rb +++ b/db/migrate/20150109081914_create_api_log_tables.rb @@ -12,18 +12,20 @@ class CreateApiLogTables < ActiveRecord::Migration t.boolean :request_successful t.string :api_user_name t.string :api_user_registrar + t.string :ip t.timestamps end create_table :repp_logs do |t| - t.text :request + t.string :request_path + t.string :request_method + t.text :request_params t.text :response - t.string :request_command - t.string :request_object - t.boolean :request_successful + t.string :response_code t.string :api_user_name t.string :api_user_registrar + t.string :ip t.timestamps end