2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2017-06-16 20:43:09 +00:00
|
|
|
|
|
|
|
class Role
|
|
|
|
module Assets
|
2018-04-26 08:55:53 +00:00
|
|
|
extend ActiveSupport::Concern
|
2017-06-16 20:43:09 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get all assets / related models for this roles
|
|
|
|
|
|
|
|
role = Role.find(123)
|
|
|
|
result = role.assets(assets_if_exists)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = {
|
|
|
|
:Role => {
|
|
|
|
123 => role_model_123,
|
|
|
|
1234 => role_model_1234,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def assets(data)
|
|
|
|
|
|
|
|
app_model = self.class.to_app_model
|
|
|
|
|
|
|
|
if !data[ app_model ]
|
|
|
|
data[ app_model ] = {}
|
|
|
|
end
|
2019-11-18 19:19:35 +00:00
|
|
|
return data if data[ app_model ][ id ]
|
2017-06-16 20:43:09 +00:00
|
|
|
|
2019-11-18 19:19:35 +00:00
|
|
|
local_attributes = attributes_with_association_ids
|
2017-06-16 20:43:09 +00:00
|
|
|
|
2019-11-18 19:19:35 +00:00
|
|
|
# set temp. current attributes to assets pool to prevent
|
|
|
|
# loops, will be updated with lookup attributes later
|
|
|
|
data[ app_model ][ id ] = local_attributes
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2019-11-18 19:19:35 +00:00
|
|
|
local_attributes['group_ids'].each_key do |group_id|
|
|
|
|
next if data[:Group] && data[:Group][group_id]
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2019-11-18 19:19:35 +00:00
|
|
|
group = Group.lookup(id: group_id)
|
|
|
|
next if !group
|
|
|
|
|
|
|
|
data = group.assets(data)
|
2017-06-16 20:43:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return data if !self['created_by_id'] && !self['updated_by_id']
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
app_model_user = User.to_app_model
|
2017-11-23 08:09:44 +00:00
|
|
|
%w[created_by_id updated_by_id].each do |local_user_id|
|
2017-06-16 20:43:09 +00:00
|
|
|
next if !self[ local_user_id ]
|
|
|
|
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
user = User.lookup(id: self[ local_user_id ])
|
|
|
|
next if !user
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
data = user.assets(data)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-06-16 20:43:09 +00:00
|
|
|
data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|