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