Streamline of user assets lookup.

This commit is contained in:
Martin Edenhofer 2015-05-22 20:52:34 +02:00
parent 158f6ab07d
commit cbe5a2b419
5 changed files with 28 additions and 33 deletions

View file

@ -30,12 +30,11 @@ returns
end
return data if !self['created_by_id'] && !self['updated_by_id']
%w(created_by_id updated_by_id).each {|item|
next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] )
%w(created_by_id updated_by_id).each {|local_user_id|
next if !self[ local_user_id ]
next data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ]
user = User.lookup( id: self[ local_user_id ] )
data = user.assets( data )
end
}
data
end

View file

@ -32,20 +32,19 @@ returns
if !data[ Organization.to_app_model ][ id ]
data[ Organization.to_app_model ][ id ] = attributes_with_associations
if data[ Organization.to_app_model ][ id ]['member_ids']
data[ Organization.to_app_model ][ id ]['member_ids'].each {|user_id|
if !data[ User.to_app_model ][ user_id ]
user = User.lookup( id: user_id )
data[ Organization.to_app_model ][ id ]['member_ids'].each {|local_user_id|
if !data[ User.to_app_model ][ local_user_id ]
user = User.lookup( id: local_user_id )
data = user.assets( data )
end
}
end
end
%w(created_by_id updated_by_id).each {|item|
next if !self[ item ]
if !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] )
%w(created_by_id updated_by_id).each {|local_user_id|
next if !self[ local_user_id ]
next if data[ User.to_app_model ][ self[ local_user_id ] ]
user = User.lookup( id: self[ local_user_id ] )
data = user.assets( data )
end
}
data
end

View file

@ -41,12 +41,11 @@ returns
data[ Ticket::Article.to_app_model ][ id ]['attachments'] = attachments
end
%w(created_by_id updated_by_id).each {|item|
next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] )
%w(created_by_id updated_by_id).each {|local_user_id|
next if !self[ local_user_id ]
next if data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ]
user = User.lookup( id: self[ local_user_id ] )
data = user.assets( data )
end
}
data
end

View file

@ -29,12 +29,11 @@ returns
if !data[ Ticket.to_app_model ][ id ]
data[ Ticket.to_app_model ][ id ] = attributes_with_associations
end
%w(created_by_id updated_by_id owner_id customer_id).each {|item|
next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] )
%w(created_by_id updated_by_id owner_id customer_id).each {|local_user_id|
next if !self[ local_user_id ]
next if data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ]
user = User.lookup( id: self[ local_user_id ] )
data = user.assets( data )
end
}
data
end

View file

@ -74,12 +74,11 @@ returns
data = organization.assets( data )
end
end
%w(created_by_id updated_by_id).each {|item|
next if !self[ item ]
if !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] )
%w(created_by_id updated_by_id).each {|local_user_id|
next if !self[ local_user_id ]
next if data[ User.to_app_model ][ self[ local_user_id ] ]
user = User.lookup( id: self[ local_user_id ] )
data = user.assets( data )
end
}
data
end