2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2016-04-25 23:04:59 +00:00
|
|
|
|
|
|
|
class Transaction::ClearbitEnrichment
|
|
|
|
|
|
|
|
=begin
|
|
|
|
{
|
|
|
|
object: 'User',
|
|
|
|
type: 'create',
|
|
|
|
object_id: 123,
|
|
|
|
changes: {
|
|
|
|
'attribute1' => [before, now],
|
|
|
|
'attribute2' => [before, now],
|
2016-07-16 21:43:08 +00:00
|
|
|
},
|
|
|
|
created_at: Time.zone.now,
|
2016-04-27 07:31:11 +00:00
|
|
|
user_id: 123,
|
2016-04-25 23:04:59 +00:00
|
|
|
},
|
|
|
|
=end
|
|
|
|
|
|
|
|
def initialize(item, params = {})
|
|
|
|
@item = item
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
return if @item[:object] != 'User'
|
|
|
|
return if @item[:type] != 'create'
|
|
|
|
return if !Setting.get('clearbit_integration')
|
|
|
|
|
|
|
|
config = Setting.get('clearbit_config')
|
|
|
|
return if !config
|
2017-11-15 14:06:53 +00:00
|
|
|
return if config['api_key'].blank?
|
2016-04-25 23:04:59 +00:00
|
|
|
|
|
|
|
user = User.lookup(id: @item[:object_id])
|
|
|
|
return if !user
|
|
|
|
|
2017-03-09 10:32:05 +00:00
|
|
|
user_enrichment = Enrichment::Clearbit::User.new(user)
|
|
|
|
return if !user_enrichment.synced?
|
2016-04-25 23:04:59 +00:00
|
|
|
|
2021-05-20 06:59:02 +00:00
|
|
|
TransactionDispatcher.commit
|
2016-04-25 23:04:59 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|