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
|
=end
|
||||||
|
|
||||||
def history_get(fulldata = false)
|
def history_get(fulldata = false)
|
||||||
list = History.list( self.class.name, self['id'] )
|
if !fulldata
|
||||||
return list if !fulldata
|
return History.list( self.class.name, self['id'] )
|
||||||
|
end
|
||||||
|
|
||||||
# get related objects
|
# get related objects
|
||||||
assets = {}
|
history = History.list( self.class.name, self['id'], nil, true )
|
||||||
list.each {|item|
|
history[:list].each {|item|
|
||||||
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
|
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
|
||||||
assets = record.assets(assets)
|
|
||||||
|
history[:assets] = record.assets( history[:assets] )
|
||||||
|
|
||||||
if item['related_object']
|
if item['related_object']
|
||||||
record = Kernel.const_get( item['related_object'] ).find( item['related_o_id'] )
|
record = Kernel.const_get( item['related_object'] ).find( item['related_o_id'] )
|
||||||
assets = record.assets(assets)
|
history[:assets] = record.assets( history[:assets] )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
:history => list,
|
:history => history[:list],
|
||||||
:assets => assets,
|
:assets => history[:assets],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,44 @@ return all history entries of an object
|
||||||
|
|
||||||
history_list = History.list( 'Ticket', 123 )
|
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
|
=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
|
if !related_history_object
|
||||||
history_object = self.object_lookup( requested_object )
|
history_object = self.object_lookup( requested_object )
|
||||||
history = History.where( :history_object_id => history_object.id ).
|
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')
|
order('created_at ASC, id ASC')
|
||||||
end
|
end
|
||||||
|
asset_list = {}
|
||||||
list = []
|
list = []
|
||||||
history.each do |item|
|
history.each do |item|
|
||||||
|
|
||||||
|
if assets
|
||||||
|
asset_list = item.assets( asset_list )
|
||||||
|
end
|
||||||
|
|
||||||
data = item.attributes
|
data = item.attributes
|
||||||
data['object'] = self.object_lookup_id( data['history_object_id'] ).name
|
data['object'] = self.object_lookup_id( data['history_object_id'] ).name
|
||||||
data['type'] = self.type_lookup_id( data['history_type_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
|
list.push data
|
||||||
end
|
end
|
||||||
|
if assets
|
||||||
|
return {
|
||||||
|
:list => list,
|
||||||
|
:assets => asset_list,
|
||||||
|
}
|
||||||
|
end
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,11 @@ class User < ApplicationModel
|
||||||
:last_login => true,
|
:last_login => true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
history_support
|
history_support(
|
||||||
|
:ignore_attributes => {
|
||||||
|
:password => true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
@ -442,7 +446,7 @@ returns
|
||||||
|
|
||||||
=begin
|
=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)
|
user = User.find(123)
|
||||||
result = user.update_last_login
|
result = user.update_last_login
|
||||||
|
@ -455,6 +459,13 @@ returns
|
||||||
|
|
||||||
def update_last_login
|
def update_last_login
|
||||||
self.last_login = Time.now
|
self.last_login = Time.now
|
||||||
|
|
||||||
|
# reset login failed
|
||||||
|
self.login_failed = 0
|
||||||
|
|
||||||
|
# set updated by user
|
||||||
|
self.updated_by_id = self.id
|
||||||
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,6 @@ returns
|
||||||
# remember last login date
|
# remember last login date
|
||||||
user_auth.update_last_login
|
user_auth.update_last_login
|
||||||
|
|
||||||
# reset login failed
|
|
||||||
user_auth.login_failed = 0
|
|
||||||
user_auth.save
|
|
||||||
|
|
||||||
return user_auth
|
return user_auth
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,6 @@ returns
|
||||||
# remember last login date
|
# remember last login date
|
||||||
user_auth.update_last_login
|
user_auth.update_last_login
|
||||||
|
|
||||||
# reset login failed
|
|
||||||
user_auth.login_failed = 0
|
|
||||||
user_auth.save
|
|
||||||
|
|
||||||
return user_auth
|
return user_auth
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue