From 459dfa34343c499e9143a5bee9a6f59254a7ca34 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 22 Oct 2013 08:43:49 +0200 Subject: [PATCH] Improved history logging. --- .../application_model/history_log_base.rb | 35 ++++++++++--- app/models/history.rb | 49 ++++++++++++++++++- app/models/user.rb | 15 +++++- lib/auth.rb | 4 -- lib/sso.rb | 4 -- 5 files changed, 88 insertions(+), 19 deletions(-) diff --git a/app/models/application_model/history_log_base.rb b/app/models/application_model/history_log_base.rb index 255d1cbde..cacdab982 100644 --- a/app/models/application_model/history_log_base.rb +++ b/app/models/application_model/history_log_base.rb @@ -55,26 +55,45 @@ returns }, ] +to get history log for this object with all assets + + organization = Organization.find(123) + result = organization.history_get(true) + +returns + + result = { + :history => [ + { ... }, + { ... }, + ], + :assets => { + ... + } + } + =end def history_get(fulldata = false) - list = History.list( self.class.name, self['id'] ) - return list if !fulldata + if !fulldata + return History.list( self.class.name, self['id'] ) + end # get related objects - assets = {} - list.each {|item| + history = History.list( self.class.name, self['id'], nil, true ) + history[:list].each {|item| record = Kernel.const_get( item['object'] ).find( item['o_id'] ) - assets = record.assets(assets) + + history[:assets] = record.assets( history[:assets] ) if item['related_object'] record = Kernel.const_get( item['related_object'] ).find( item['related_o_id'] ) - assets = record.assets(assets) + history[:assets] = record.assets( history[:assets] ) end } return { - :history => list, - :assets => assets, + :history => history[:list], + :assets => history[:assets], } end diff --git a/app/models/history.rb b/app/models/history.rb index 99de3b235..2a474a497 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -111,9 +111,44 @@ return all history entries of an object history_list = History.list( 'Ticket', 123 ) +returns + + history_list = [ + { ... }, + { ... }, + { ... }, + { ... }, + ] + + +return all history entries of an object and it's related history objects + + history_list = History.list( 'Ticket', 123, true ) + +returns + + history_list = [ + { ... }, + { ... }, + { ... }, + { ... }, + ] + + +return all history entries of an object and it's assets + + history = History.list( 'Ticket', 123, nil, true ) + +returns + + history = { + :list => list, + :assets => assets, + } + =end - def self.list( requested_object, requested_object_id, related_history_object = nil ) + def self.list( requested_object, requested_object_id, related_history_object = nil, assets = nil ) if !related_history_object history_object = self.object_lookup( requested_object ) history = History.where( :history_object_id => history_object.id ). @@ -131,8 +166,14 @@ return all history entries of an object ). order('created_at ASC, id ASC') end + asset_list = {} list = [] history.each do |item| + + if assets + asset_list = item.assets( asset_list ) + end + data = item.attributes data['object'] = self.object_lookup_id( data['history_object_id'] ).name data['type'] = self.type_lookup_id( data['history_type_id'] ).name @@ -164,6 +205,12 @@ return all history entries of an object list.push data end + if assets + return { + :list => list, + :assets => asset_list, + } + end list end diff --git a/app/models/user.rb b/app/models/user.rb index c75f59ff1..0863c2b1b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,7 +25,11 @@ class User < ApplicationModel :last_login => true, } ) - history_support + history_support( + :ignore_attributes => { + :password => true, + } + ) =begin @@ -442,7 +446,7 @@ returns =begin -update last login date (is automatically done by auth and sso backend) +update last login date and reset login_failed (is automatically done by auth and sso backend) user = User.find(123) result = user.update_last_login @@ -455,6 +459,13 @@ returns def update_last_login self.last_login = Time.now + + # reset login failed + self.login_failed = 0 + + # set updated by user + self.updated_by_id = self.id + self.save end diff --git a/lib/auth.rb b/lib/auth.rb index 85b1e0867..046dd3599 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -50,10 +50,6 @@ returns # remember last login date user_auth.update_last_login - # reset login failed - user_auth.login_failed = 0 - user_auth.save - return user_auth end } diff --git a/lib/sso.rb b/lib/sso.rb index 9f04e1498..61695455f 100644 --- a/lib/sso.rb +++ b/lib/sso.rb @@ -50,10 +50,6 @@ returns # remember last login date user_auth.update_last_login - # reset login failed - user_auth.login_failed = 0 - user_auth.save - return user_auth end }