From cbe5a2b419d2840d223e90be120be9088422d2fa Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 22 May 2015 20:52:34 +0200 Subject: [PATCH] Streamline of user assets lookup. --- app/models/application_model/assets.rb | 11 +++++------ app/models/organization/assets.rb | 17 ++++++++--------- app/models/ticket/article/assets.rb | 11 +++++------ app/models/ticket/assets.rb | 11 +++++------ app/models/user/assets.rb | 11 +++++------ 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/app/models/application_model/assets.rb b/app/models/application_model/assets.rb index 93dd6099e..f5bf4d5c0 100644 --- a/app/models/application_model/assets.rb +++ b/app/models/application_model/assets.rb @@ -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 ] ) - data = user.assets( data ) - end + %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 ) } data end diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb index 36958f1d7..2f48e771a 100644 --- a/app/models/organization/assets.rb +++ b/app/models/organization/assets.rb @@ -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 ] ) - data = user.assets( data ) - end + %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 ) } data end diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb index 7a3c3f016..e3dcf8807 100644 --- a/app/models/ticket/article/assets.rb +++ b/app/models/ticket/article/assets.rb @@ -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 ] ) - data = user.assets( data ) - end + %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 ) } data end diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb index f02e7e1d7..a2fe4feef 100644 --- a/app/models/ticket/assets.rb +++ b/app/models/ticket/assets.rb @@ -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 ] ) - data = user.assets( data ) - end + %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 ) } data end diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index de8db1a9b..8309f55b1 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -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 ] ) - data = user.assets( data ) - end + %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 ) } data end