Improved style of assets backends.
This commit is contained in:
parent
08782ec52e
commit
8a36fac9fd
11 changed files with 108 additions and 109 deletions
|
@ -6,7 +6,7 @@ module ApplicationModel::Assets
|
|||
get all assets / related models for this user
|
||||
|
||||
user = User.find(123)
|
||||
result = user.assets( assets_if_exists )
|
||||
result = user.assets(assets_if_exists)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -19,13 +19,15 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data = {})
|
||||
def assets(data = {})
|
||||
|
||||
if !data[ self.class.to_app_model ]
|
||||
data[ self.class.to_app_model ] = {}
|
||||
app_model = self.class.to_app_model
|
||||
|
||||
if !data[ app_model ]
|
||||
data[ app_model ] = {}
|
||||
end
|
||||
if !data[ self.class.to_app_model ][ id ]
|
||||
data[ self.class.to_app_model ][ id ] = attributes_with_associations
|
||||
if !data[ app_model ][ id ]
|
||||
data[ app_model ][ id ] = attributes_with_associations
|
||||
end
|
||||
|
||||
return data if !self['created_by_id'] && !self['updated_by_id']
|
||||
|
|
|
@ -8,7 +8,7 @@ class Channel
|
|||
get all assets / related models for this channel
|
||||
|
||||
channel = Channel.find(123)
|
||||
result = channel.assets( assets_if_exists )
|
||||
result = channel.assets(assets_if_exists)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -21,12 +21,14 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data = {})
|
||||
def assets(data = {})
|
||||
|
||||
if !data[ self.class.to_app_model ]
|
||||
data[ self.class.to_app_model ] = {}
|
||||
app_model = self.class.to_app_model
|
||||
|
||||
if !data[ app_model ]
|
||||
data[ app_model ] = {}
|
||||
end
|
||||
if !data[ self.class.to_app_model ][ id ]
|
||||
if !data[ app_model ][ id ]
|
||||
attributes = attributes_with_associations
|
||||
|
||||
# remove passwords if use is no admin
|
||||
|
|
|
@ -8,7 +8,7 @@ class History
|
|||
get all assets / related models for this history entry
|
||||
|
||||
history = History.find(123)
|
||||
result = history.assets( assets_if_exists )
|
||||
result = history.assets(assets_if_exists)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -21,9 +21,11 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self['created_by_id'] ]
|
||||
app_model = User.to_app_model
|
||||
|
||||
if !data[ app_model ] || !data[ app_model ][ self['created_by_id'] ]
|
||||
user = User.lookup(id: self['created_by_id'])
|
||||
if user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -21,16 +21,18 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ Job.to_app_model ]
|
||||
data[ Job.to_app_model ] = {}
|
||||
app_model = Job.to_app_model
|
||||
|
||||
if !data[ app_model ]
|
||||
data[ app_model ] = {}
|
||||
end
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
end
|
||||
if !data[ Job.to_app_model ][ id ]
|
||||
data[ Job.to_app_model ][ id ] = attributes_with_associations
|
||||
if !data[ app_model ][ id ]
|
||||
data[ app_model ][ id ] = attributes_with_associations
|
||||
data = assets_of_selector('condition', data)
|
||||
data = assets_of_selector('perform', data)
|
||||
end
|
||||
|
|
|
@ -21,20 +21,23 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ Organization.to_app_model ]
|
||||
data[ Organization.to_app_model ] = {}
|
||||
app_model_organization = Organization.to_app_model
|
||||
app_model_user = User.to_app_model
|
||||
|
||||
if !data[ app_model_organization ]
|
||||
data[ app_model_organization ] = {}
|
||||
end
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
if !data[ app_model_user ]
|
||||
data[ app_model_user ] = {}
|
||||
end
|
||||
if !data[ Organization.to_app_model ][ id ]
|
||||
if !data[ app_model_organization ][ id ]
|
||||
local_attributes = attributes
|
||||
|
||||
# set temp. current attributes to assets pool to prevent
|
||||
# loops, will be updated with lookup attributes later
|
||||
data[ Organization.to_app_model ][ id ] = local_attributes
|
||||
data[ app_model_organization ][ id ] = local_attributes
|
||||
|
||||
# get organizations
|
||||
key = "Organization::member_ids::#{id}"
|
||||
|
@ -46,18 +49,18 @@ returns
|
|||
local_attributes['member_ids'] = local_member_ids
|
||||
if local_member_ids
|
||||
local_member_ids.each { |local_user_id|
|
||||
next if data[ User.to_app_model ][ local_user_id ]
|
||||
next if data[ app_model_user ][ local_user_id ]
|
||||
user = User.lookup(id: local_user_id)
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
}
|
||||
end
|
||||
|
||||
data[ Organization.to_app_model ][ id ] = local_attributes
|
||||
data[ app_model_organization ][ id ] = local_attributes
|
||||
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 ] ]
|
||||
next if data[ app_model_user ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -21,19 +21,22 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ Overview.to_app_model ]
|
||||
data[ Overview.to_app_model ] = {}
|
||||
app_model_overview = Overview.to_app_model
|
||||
app_model_user = User.to_app_model
|
||||
|
||||
if !data[ app_model_overview ]
|
||||
data[ app_model_overview ] = {}
|
||||
end
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
if !data[ app_model_user ]
|
||||
data[ app_model_user ] = {}
|
||||
end
|
||||
if !data[ Overview.to_app_model ][ id ]
|
||||
data[ Overview.to_app_model ][ id ] = attributes_with_associations
|
||||
if !data[ app_model_overview ][ id ]
|
||||
data[ app_model_overview ][ id ] = attributes_with_associations
|
||||
if user_ids
|
||||
user_ids.each { |local_user_id|
|
||||
next if data[ User.to_app_model ][ local_user_id ]
|
||||
next if data[ app_model_user ][ local_user_id ]
|
||||
user = User.lookup(id: local_user_id)
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
@ -45,7 +48,7 @@ returns
|
|||
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 ] ]
|
||||
next if data[ app_model_user ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -23,14 +23,17 @@ returns
|
|||
|
||||
def assets (data)
|
||||
|
||||
if !data[ Sla.to_app_model ]
|
||||
data[ Sla.to_app_model ] = {}
|
||||
app_model_sla = Sla.to_app_model
|
||||
app_model_user = User.to_app_model
|
||||
|
||||
if !data[ app_model_sla ]
|
||||
data[ app_model_sla ] = {}
|
||||
end
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
if !data[ app_model_user ]
|
||||
data[ app_model_user ] = {}
|
||||
end
|
||||
if !data[ Sla.to_app_model ][ id ]
|
||||
data[ Sla.to_app_model ][ id ] = attributes_with_associations
|
||||
if !data[ app_model_sla ][ id ]
|
||||
data[ app_model_sla ][ id ] = attributes_with_associations
|
||||
data = assets_of_selector('condition', data)
|
||||
if calendar_id
|
||||
calendar = Calendar.lookup(id: calendar_id)
|
||||
|
@ -41,7 +44,7 @@ returns
|
|||
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 ] ]
|
||||
next if data[ app_model_user ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ticket::Article::Assets
|
|||
get all assets / related models for this article
|
||||
|
||||
article = Ticket::Article.find(123)
|
||||
result = article.assets( assets_if_exists )
|
||||
result = article.assets(assets_if_exists)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -21,35 +21,39 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ Ticket.to_app_model ]
|
||||
data[ Ticket.to_app_model ] = {}
|
||||
app_model_ticket = Ticket.to_app_model
|
||||
app_model_article = Ticket::Article.to_app_model
|
||||
app_model_user = User.to_app_model
|
||||
|
||||
if !data[ app_model_ticket ]
|
||||
data[ app_model_ticket ] = {}
|
||||
end
|
||||
if !data[ Ticket.to_app_model ][ ticket_id ]
|
||||
ticket = Ticket.find( ticket_id )
|
||||
if !data[ app_model_ticket ][ ticket_id ]
|
||||
ticket = Ticket.lookup(id: ticket_id)
|
||||
data = ticket.assets(data)
|
||||
end
|
||||
|
||||
if !data[ Ticket::Article.to_app_model ]
|
||||
data[ Ticket::Article.to_app_model ] = {}
|
||||
if !data[ app_model_article ]
|
||||
data[ app_model_article ] = {}
|
||||
end
|
||||
if !data[ Ticket::Article.to_app_model ][ id ]
|
||||
data[ Ticket::Article.to_app_model ][ id ] = attributes
|
||||
if !data[ app_model_article ][ id ]
|
||||
data[ app_model_article ][ id ] = attributes
|
||||
|
||||
# add attachment list to article
|
||||
data[ Ticket::Article.to_app_model ][ id ]['attachments'] = attachments
|
||||
data[ app_model_article ][ id ]['attachments'] = attachments
|
||||
|
||||
if !data[ Ticket::Article.to_app_model ][ id ]['attachments'].empty?
|
||||
if data[ Ticket::Article.to_app_model ][ id ]['content_type'] =~ %r{text/html}i
|
||||
if data[ Ticket::Article.to_app_model ][ id ]['body'] =~ /<img/i
|
||||
if !data[ app_model_article ][ id ]['attachments'].empty?
|
||||
if data[ app_model_article ][ id ]['content_type'] =~ %r{text/html}i
|
||||
if data[ app_model_article ][ id ]['body'] =~ /<img/i
|
||||
|
||||
# insert inline images with urls
|
||||
attributes = Ticket::Article.insert_urls(
|
||||
data[ Ticket::Article.to_app_model ][ id ],
|
||||
data[ Ticket::Article.to_app_model ][ id ]['attachments']
|
||||
data[ app_model_article ][ id ],
|
||||
data[ app_model_article ][ id ]['attachments']
|
||||
)
|
||||
data[ Ticket::Article.to_app_model ][ id ] = attributes
|
||||
data[ app_model_article ][ id ] = attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -57,7 +61,7 @@ returns
|
|||
|
||||
%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 ] ]
|
||||
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -20,17 +20,20 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
def assets(data)
|
||||
|
||||
if !data[ Ticket.to_app_model ]
|
||||
data[ Ticket.to_app_model ] = {}
|
||||
app_model_ticket = Ticket.to_app_model
|
||||
app_model_user = User.to_app_model
|
||||
|
||||
if !data[ app_model_ticket ]
|
||||
data[ app_model_ticket ] = {}
|
||||
end
|
||||
if !data[ Ticket.to_app_model ][ id ]
|
||||
data[ Ticket.to_app_model ][ id ] = attributes_with_associations
|
||||
if !data[ app_model_ticket ][ id ]
|
||||
data[ app_model_ticket ][ id ] = attributes_with_associations
|
||||
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 ] ]
|
||||
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
|
@ -685,12 +685,6 @@ returns
|
|||
# delete asset caches
|
||||
key = "User::authorizations::#{id}"
|
||||
Cache.delete(key)
|
||||
key = "User::role_ids::#{id}"
|
||||
Cache.delete(key)
|
||||
key = "User::group_ids::#{id}"
|
||||
Cache.delete(key)
|
||||
key = "User::organization_ids::#{id}"
|
||||
Cache.delete(key)
|
||||
end
|
||||
|
||||
def check_name
|
||||
|
|
|
@ -23,18 +23,20 @@ returns
|
|||
|
||||
def assets (data)
|
||||
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
app_model = User.to_app_model
|
||||
|
||||
if !data[ app_model ]
|
||||
data[ app_model ] = {}
|
||||
end
|
||||
if !data[ User.to_app_model ][ id ]
|
||||
local_attributes = attributes
|
||||
if !data[ app_model ][ id ]
|
||||
local_attributes = attributes_with_associations
|
||||
|
||||
# do not transfer crypted pw
|
||||
local_attributes['password'] = ''
|
||||
|
||||
# set temp. current attributes to assets pool to prevent
|
||||
# loops, will be updated with lookup attributes later
|
||||
data[ User.to_app_model ][ id ] = local_attributes
|
||||
data[ app_model ][ id ] = local_attributes
|
||||
|
||||
# get linked accounts
|
||||
local_attributes['accounts'] = {}
|
||||
|
@ -54,30 +56,16 @@ returns
|
|||
local_attributes['accounts'] = local_accounts
|
||||
|
||||
# get roles
|
||||
key = "User::role_ids::#{id}"
|
||||
local_role_ids = Cache.get(key)
|
||||
if !local_role_ids
|
||||
local_role_ids = role_ids
|
||||
Cache.write(key, local_role_ids)
|
||||
end
|
||||
local_attributes['role_ids'] = local_role_ids
|
||||
if local_role_ids
|
||||
local_role_ids.each { |role_id|
|
||||
if local_attributes['role_ids']
|
||||
local_attributes['role_ids'].each { |role_id|
|
||||
role = Role.lookup(id: role_id)
|
||||
data = role.assets(data)
|
||||
}
|
||||
end
|
||||
|
||||
# get groups
|
||||
key = "User::group_ids::#{id}"
|
||||
local_group_ids = Cache.get(key)
|
||||
if !local_group_ids
|
||||
local_group_ids = group_ids
|
||||
Cache.write(key, local_group_ids)
|
||||
end
|
||||
local_attributes['group_ids'] = local_group_ids
|
||||
if local_group_ids
|
||||
local_group_ids.each { |group_id|
|
||||
if local_attributes['group_ids']
|
||||
local_attributes['group_ids'].each { |group_id|
|
||||
group = Group.lookup(id: group_id)
|
||||
next if !group
|
||||
data = group.assets(data)
|
||||
|
@ -85,22 +73,15 @@ returns
|
|||
end
|
||||
|
||||
# get organizations
|
||||
key = "User::organization_ids::#{id}"
|
||||
local_organization_ids = Cache.get(key)
|
||||
if !local_organization_ids
|
||||
local_organization_ids = organization_ids
|
||||
Cache.write(key, local_organization_ids)
|
||||
end
|
||||
local_attributes['organization_ids'] = local_organization_ids
|
||||
if local_organization_ids
|
||||
local_organization_ids.each { |organization_id|
|
||||
if local_attributes['organization_ids']
|
||||
local_attributes['organization_ids'].each { |organization_id|
|
||||
organization = Organization.lookup(id: organization_id)
|
||||
next if !organization
|
||||
data = organization.assets(data)
|
||||
}
|
||||
end
|
||||
|
||||
data[ User.to_app_model ][ id ] = local_attributes
|
||||
data[ app_model ][ id ] = local_attributes
|
||||
end
|
||||
|
||||
# add organization
|
||||
|
@ -114,7 +95,7 @@ returns
|
|||
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 ] ]
|
||||
next if data[ app_model ][ self[ local_user_id ] ]
|
||||
user = User.lookup(id: self[ local_user_id ])
|
||||
next if !user
|
||||
data = user.assets(data)
|
||||
|
|
Loading…
Reference in a new issue