2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2016-07-06 06:13:44 +00:00
|
|
|
|
|
|
|
class User
|
|
|
|
module SearchIndex
|
2018-04-26 08:55:53 +00:00
|
|
|
extend ActiveSupport::Concern
|
2016-07-06 06:13:44 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2017-09-11 00:50:05 +00:00
|
|
|
lookup name of ref. objects
|
|
|
|
|
|
|
|
user = User.find(123)
|
|
|
|
attributes = user.search_index_attribute_lookup
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
attributes # object with lookup data
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def search_index_attribute_lookup
|
|
|
|
attributes = super
|
|
|
|
|
|
|
|
attributes['permissions'] = []
|
|
|
|
permissions_with_child_ids.each do |permission_id|
|
2017-09-15 08:20:21 +00:00
|
|
|
permission = ::Permission.lookup(id: permission_id)
|
2017-09-11 00:50:05 +00:00
|
|
|
next if !permission
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-09-11 00:50:05 +00:00
|
|
|
attributes['permissions'].push permission.name
|
|
|
|
end
|
|
|
|
attributes['role_ids'] = role_ids
|
|
|
|
|
|
|
|
attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
get data to store in search index
|
|
|
|
|
|
|
|
user = User.find(2)
|
|
|
|
result = user.search_index_data
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = {
|
|
|
|
attribute1: 'some value',
|
|
|
|
attribute2: ['value 1', 'value 2'],
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def search_index_data
|
|
|
|
attributes = {}
|
2017-10-01 12:25:52 +00:00
|
|
|
self.attributes.each do |key, value|
|
2016-07-06 06:13:44 +00:00
|
|
|
next if key == 'password'
|
|
|
|
next if !value
|
2017-09-11 00:50:05 +00:00
|
|
|
next if value.respond_to?('blank?') && value.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
attributes[key] = value
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-09-11 00:50:05 +00:00
|
|
|
return if attributes.blank?
|
2016-07-06 06:13:44 +00:00
|
|
|
|
2017-09-11 00:50:05 +00:00
|
|
|
if attributes['organization_id'].present?
|
2016-07-06 06:13:44 +00:00
|
|
|
organization = Organization.lookup(id: attributes['organization_id'])
|
|
|
|
if organization
|
|
|
|
attributes['organization'] = organization.name
|
|
|
|
attributes['organization_ref'] = organization.search_index_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|