Improved history logging.
This commit is contained in:
parent
e6e2fa1850
commit
459dfa3434
5 changed files with 88 additions and 19 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue