gitlab_support_readiness 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/support_readiness/repos/zendesk_salesforce_sync.rb +1079 -0
- data/lib/support_readiness/repos.rb +1 -0
- data/lib/support_readiness/salesforce/accounts.rb +2 -0
- data/lib/support_readiness/salesforce/contacts.rb +2 -0
- data/lib/support_readiness/salesforce/subscription_definitions.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d01a922cd60d9bf388892d58416853d41b222bdde7d239ad09d30af317cdf1
|
4
|
+
data.tar.gz: 66757babab7cd3b77b87ca30241411a39b08da2992970810854a3eac4682fc1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0417f8933df32fbbca9bd4f0a010e2640db67df871c68991eea905689eb2d58136a19d40b4bece974756fc296e391201d611fb974224acfb6243dc63190a0ad
|
7
|
+
data.tar.gz: 26d03850f65288ab7d90a79ad3535045dda6ebd05c8e88dc3cb184ec2eb15ba1c38903b73a455316205ced22622357ed1db7c769d1309681154b159a6530c367
|
@@ -0,0 +1,1079 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Repos
|
6
|
+
module Repos
|
7
|
+
##
|
8
|
+
# Defines the class ZendeskSalesforceSync within the module {Readiness::Repos}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.28
|
12
|
+
class ZendeskSalesforceSync < Readiness::Client
|
13
|
+
def self.usgov_user_sync(redis_client, zendesk_client, salesforce_client)
|
14
|
+
print 'Determining differences...'
|
15
|
+
differences = compare_usgov_users(redis_client, zendesk_client, salesforce_client, false)
|
16
|
+
puts 'done'
|
17
|
+
differences[:creates].each do |user|
|
18
|
+
print "Creating #{user.email}..."
|
19
|
+
create = Readiness::Zendesk::Users.create!(zendesk_client, user)
|
20
|
+
puts 'done'
|
21
|
+
@zd_users.push(usgov_zd_user_sync_object(create))
|
22
|
+
end
|
23
|
+
differences[:updates].each do |user|
|
24
|
+
print "Updating #{user.email}..."
|
25
|
+
update = Readiness::Zendesk::Users.update!(zendesk_client, user)
|
26
|
+
puts 'done'
|
27
|
+
index = @zd_users.index { |u| u['id'] == update.id }
|
28
|
+
@zd_users[index] = usgov_zd_user_sync_object(update) unless index.nil?
|
29
|
+
end
|
30
|
+
differences[:not_in_sfdc].each do |diff|
|
31
|
+
user = Readiness::Zendesk::Users.find!(zendesk_client, diff['id'])
|
32
|
+
print "Marking #{user.email} as not being in SFDC..."
|
33
|
+
user.user_fields['not_in_sfdc'] = true
|
34
|
+
update = Readiness::Zendesk::Users.update!(zendesk_client, user)
|
35
|
+
puts 'done'
|
36
|
+
index = @zd_users.index { |u| u['id'] == update.id }
|
37
|
+
@zd_users[index] = usgov_zd_user_sync_object(update) unless index.nil?
|
38
|
+
end
|
39
|
+
print 'Updating Redis cache...'
|
40
|
+
Readiness::Redis.set(redis_client, 'usgov_users', @zd_users)
|
41
|
+
puts 'done'
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Perform a Zendesk-Salesforce Sync for Zendesk US Government
|
46
|
+
#
|
47
|
+
# @author Jason Colyer
|
48
|
+
# @since 1.0.28
|
49
|
+
# @param redis_client [Object] An instance of {Readiness::Redis}
|
50
|
+
# @param zendesk_client [Object] An instance of {Readiness::Zendesk::Client}
|
51
|
+
# @param salesforce_client [Object] An instance of {Readiness::Salesforce::Client}
|
52
|
+
# @example
|
53
|
+
# require 'support_readiness'
|
54
|
+
# zendesk_config = Readiness::Zendesk::Configuration.new
|
55
|
+
# zendesk_config.username = ENV.fetch('US_ZD_USERNAME')
|
56
|
+
# zendesk_config.token = ENV.fetch('US_ZD_TOKEN')
|
57
|
+
# zendesk_config.url = ENV.fetch('US_ZD_URL')
|
58
|
+
# zendesk_client = Readiness::Zendesk::Client.new(zendesk_config)
|
59
|
+
#
|
60
|
+
# sfdc_config = Readiness::Salesforce::Configuration.new
|
61
|
+
# sfdc_config.api_version = '58.0'
|
62
|
+
# sfdc_config.client_id = ENV.fetch('SFDC_CLIENTID')
|
63
|
+
# sfdc_config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
64
|
+
# sfdc_config.password = ENV.fetch('SFDC_PASSWORD')
|
65
|
+
# sfdc_config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
66
|
+
# sfdc_config.username = ENV.fetch('SFDC_USERNAME')
|
67
|
+
# sfdc_client = Readiness::Salesforce::Client.new(sfdc_config)
|
68
|
+
#
|
69
|
+
# redis_client = Readiness::Redis.new(ENV.fetch('REDIS_HOST'), ENV.fetch('REDIS_PORT'), ENV.fetch('REDIS_PASSWORD'))
|
70
|
+
#
|
71
|
+
# Readiness::Repos::ZendeskSalesforceSync.usgov_org_sync(redis_client, zendesk_client, salesforce_client)
|
72
|
+
def self.usgov_org_sync(redis_client, zendesk_client, salesforce_client)
|
73
|
+
print 'Determining differences...'
|
74
|
+
differences = compare_usgov_organizations(redis_client, zendesk_client, salesforce_client)
|
75
|
+
puts 'done'
|
76
|
+
differences[:creates].each do |org|
|
77
|
+
puts "Creating #{org.name}..."
|
78
|
+
create = Readiness::Zendesk::Organizations.create!(zendesk_client, org)
|
79
|
+
puts '- Organization created'
|
80
|
+
@organizations.push(usgov_zd_org_sync_object(create))
|
81
|
+
end
|
82
|
+
differences[:updates].each do |org|
|
83
|
+
print "Updating #{org.name}..."
|
84
|
+
update = Readiness::Zendesk::Organizations.update!(zendesk_client, org)
|
85
|
+
puts 'done'
|
86
|
+
index = @organizations.index { |o| o['id'] == update.id }
|
87
|
+
@organizations[index] = usgov_zd_org_sync_object(update) unless index.nil?
|
88
|
+
end
|
89
|
+
differences[:not_in_sfdc].each do |diff|
|
90
|
+
org = Readiness::Zendesk::Organizations.find!(zendesk_client, diff['id'])
|
91
|
+
print "Marking #{org.name} as not being in SFDC..."
|
92
|
+
org.organization_fields['not_in_sfdc'] = true
|
93
|
+
update = Readiness::Zendesk::Organizations.update!(zendesk_client, org)
|
94
|
+
puts 'done'
|
95
|
+
index = @organizations.index { |o| o['id'] == update.id }
|
96
|
+
@organizations[index] = usgov_zd_org_sync_object(update) unless index.nil?
|
97
|
+
end
|
98
|
+
print 'Updating Redis cache...'
|
99
|
+
Readiness::Redis.set(redis_client, 'usgov_organizations', @organizations)
|
100
|
+
puts 'done'
|
101
|
+
print 'Adding to Redis creation log...'
|
102
|
+
current = Readiness::Redis.get(redis_client, 'usgov_org_creations_log')
|
103
|
+
timestamp = Time.now.utc.strftime('%Y-%m-%dT%H:%MZ')
|
104
|
+
current[timestamp] = differences[:creates].map { |c| c.organization_fields['salesforce_id'] }
|
105
|
+
Readiness::Redis.set(redis_client, 'usgov_org_creations_log', current)
|
106
|
+
puts 'done'
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Perform a Zendesk-Salesforce Sync for Zendesk Global
|
111
|
+
#
|
112
|
+
# @author Jason Colyer
|
113
|
+
# @since 1.0.28
|
114
|
+
# @param redis_client [Object] An instance of {Readiness::Redis}
|
115
|
+
# @param zendesk_client [Object] An instance of {Readiness::Zendesk::Client}
|
116
|
+
# @param salesforce_client [Object] An instance of {Readiness::Salesforce::Client}
|
117
|
+
# @param slack_client [Object] An instance of {Readiness::Slack::Client}
|
118
|
+
# @example
|
119
|
+
# require 'support_readiness'
|
120
|
+
# zendesk_config = Readiness::Zendesk::Configuration.new
|
121
|
+
# zendesk_config.username = ENV.fetch('ZD_USERNAME')
|
122
|
+
# zendesk_config.token = ENV.fetch('ZD_TOKEN')
|
123
|
+
# zendesk_config.url = ENV.fetch('ZD_URL')
|
124
|
+
# zendesk_client = Readiness::Zendesk::Client.new(zendesk_config)
|
125
|
+
#
|
126
|
+
# sfdc_config = Readiness::Salesforce::Configuration.new
|
127
|
+
# sfdc_config.api_version = '58.0'
|
128
|
+
# sfdc_config.client_id = ENV.fetch('SFDC_CLIENTID')
|
129
|
+
# sfdc_config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
130
|
+
# sfdc_config.password = ENV.fetch('SFDC_PASSWORD')
|
131
|
+
# sfdc_config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
132
|
+
# sfdc_config.username = ENV.fetch('SFDC_USERNAME')
|
133
|
+
# sfdc_client = Readiness::Salesforce::Client.new(sfdc_config)
|
134
|
+
#
|
135
|
+
# slack_config = Readiness::Slack::Configuration.new
|
136
|
+
# slack_config.url = ENV.fetch('SLACK_URL')
|
137
|
+
# slack_client = Readiness::Slack::Client.new(slack_config)
|
138
|
+
#
|
139
|
+
# redis_client = Readiness::Redis.new(ENV.fetch('REDIS_HOST'), ENV.fetch('REDIS_PORT'), ENV.fetch('REDIS_PASSWORD'))
|
140
|
+
#
|
141
|
+
# Readiness::Repos::ZendeskSalesforceSync.global_sync(redis_client, zendesk_client, salesforce_client, slack_client)
|
142
|
+
def self.global_sync(redis_client, zendesk_client, salesforce_client, slack_client)
|
143
|
+
print 'Determining differences...'
|
144
|
+
differences = compare_global_organizations(redis_client, zendesk_client, salesforce_client)
|
145
|
+
puts 'done'
|
146
|
+
differences[:creates].each do |org|
|
147
|
+
puts "Creating #{org.name}..."
|
148
|
+
create = Readiness::Zendesk::Organizations.create!(zendesk_client, org)
|
149
|
+
puts '- Organization created'
|
150
|
+
if create_global_contact?(create)
|
151
|
+
print '- Setting up contact for org...'
|
152
|
+
contact = differences[:contacts].detect { |c| ['salesforce_id'] == org.organization_fields['salesforce_id'] }
|
153
|
+
if contact.nil?
|
154
|
+
Readiness::Slack::Messages.create!(slack_client, global_slack_message(create))
|
155
|
+
puts 'error'
|
156
|
+
else
|
157
|
+
search = Readiness::Zendesk::Search..users(client, "email:#{contact['email']}")
|
158
|
+
if search.count == 1
|
159
|
+
if search.first.organization_id.nil?
|
160
|
+
user = search.first
|
161
|
+
user.organization_id = create.id
|
162
|
+
Readiness::Zendesk::Users.update!(zendesk_client, user)
|
163
|
+
puts 'done'
|
164
|
+
else
|
165
|
+
Readiness::Slack::Messages.create!(slack_client, global_slack_message(create))
|
166
|
+
puts 'error'
|
167
|
+
end
|
168
|
+
elsif search.count.zero?
|
169
|
+
user = Readiness::Zendesk::Users.new
|
170
|
+
user.email = contact['email']
|
171
|
+
user.name = contact['name']
|
172
|
+
user.organization_id = create.id
|
173
|
+
Readiness::Zendesk::Users.create!(zendesk_client, user)
|
174
|
+
puts 'done'
|
175
|
+
else
|
176
|
+
Readiness::Slack::Messages.create!(slack_client, global_slack_message(create))
|
177
|
+
puts 'error'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
@organizations.push(global_zd_sync_object(org))
|
182
|
+
end
|
183
|
+
differences[:updates].each do |org|
|
184
|
+
print "Updating #{org.name}..."
|
185
|
+
update = Readiness::Zendesk::Organizations.update!(zendesk_client, org)
|
186
|
+
puts 'done'
|
187
|
+
index = @organizations.index { |o| o['id'] == update.id }
|
188
|
+
@organizations[index] = global_zd_sync_object(update) unless index.nil?
|
189
|
+
end
|
190
|
+
differences[:not_in_sfdc].each do |diff|
|
191
|
+
org = Readiness::Zendesk::Organizations.find!(zendesk_client, diff['id'])
|
192
|
+
print "Marking #{org.name} as not being in SFDC"
|
193
|
+
org.organization_fields['not_in_sfdc'] = true
|
194
|
+
update = Readiness::Zendesk::Organizations.update!(zendesk_client, org)
|
195
|
+
puts 'done'
|
196
|
+
index = @organizations.index { |o| o['id'] == update.id }
|
197
|
+
@organizations[index] = global_zd_sync_object(update) unless index.nil?
|
198
|
+
end
|
199
|
+
print 'Updating Redis cache...'
|
200
|
+
Readiness::Redis.set(redis_client, 'global_organizations', @organizations)
|
201
|
+
puts 'done'
|
202
|
+
print 'Adding to Redis creation log...'
|
203
|
+
current = Readiness::Redis.get(redis_client, 'global_org_creations_log')
|
204
|
+
timestamp = Time.now.utc.strftime('%Y-%m-%dT%H:%MZ')
|
205
|
+
current[timestamp] = differences[:creates].map { |c| c.organization_fields['salesforce_id'] }
|
206
|
+
Readiness::Redis.set(redis_client, 'global_org_creations_log', current)
|
207
|
+
puts 'done'
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# Determines if a support contact should be created for Zendesk Global
|
212
|
+
#
|
213
|
+
# @author Jason Colyer
|
214
|
+
# @since 1.0.28
|
215
|
+
# @param org [Object] An instance of {Readiness::Zendesk::Organizations}
|
216
|
+
# @return [Boolean]
|
217
|
+
def self.create_global_contact?(org)
|
218
|
+
return false if org.organization_fields['account_type'].downcase =~ /_partner$/
|
219
|
+
return false if org.organization_fields['partner_customer']
|
220
|
+
|
221
|
+
true
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# Generate a comparison hash for Zendesk Global
|
226
|
+
#
|
227
|
+
# @author Jason Colyer
|
228
|
+
# @since 1.0.28
|
229
|
+
# @param redis_client [Object] An instance of {Readiness::Redis}
|
230
|
+
# @param zendesk_client [Object] An instance of {Readines::Zendesk::Client}
|
231
|
+
# @param salesforce_client [Object] An instance of {Readines::Salesforce::Client}
|
232
|
+
# @param verbose [Boolean] If you want verbose output or not
|
233
|
+
# @return [Hash]
|
234
|
+
# @example
|
235
|
+
# require 'support_readiness'
|
236
|
+
# zendesk_config = Readiness::Zendesk::Configuration.new
|
237
|
+
# zendesk_config.username = ENV.fetch('ZD_USERNAME')
|
238
|
+
# zendesk_config.token = ENV.fetch('ZD_TOKEN')
|
239
|
+
# zendesk_config.url = ENV.fetch('ZD_URL')
|
240
|
+
# zendesk_client = Readiness::Zendesk::Client.new(zendesk_config)
|
241
|
+
#
|
242
|
+
# sfdc_config = Readiness::Salesforce::Configuration.new
|
243
|
+
# sfdc_config.api_version = '58.0'
|
244
|
+
# sfdc_config.client_id = ENV.fetch('SFDC_CLIENTID')
|
245
|
+
# sfdc_config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
246
|
+
# sfdc_config.password = ENV.fetch('SFDC_PASSWORD')
|
247
|
+
# sfdc_config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
248
|
+
# sfdc_config.username = ENV.fetch('SFDC_USERNAME')
|
249
|
+
# sfdc_client = Readiness::Salesforce::Client.new(sfdc_config)
|
250
|
+
#
|
251
|
+
# redis_client = Readiness::Redis.new(ENV.fetch('REDIS_HOST'), ENV.fetch('REDIS_PORT'), ENV.fetch('REDIS_PASSWORD'))
|
252
|
+
#
|
253
|
+
# diffs = Readiness::Repos::ZendeskSalesforceSync.compare_global_organizations(redis_client, zendesk_client, sfdc_client, verbose = true)
|
254
|
+
# # => Gathering from Salesforce...done
|
255
|
+
# # => Gathering Organizations...received from Redis cache.
|
256
|
+
# # => Determining differences...
|
257
|
+
# # => - Differences for 123abc45 Example Org (123456789 / 001ABC123456)
|
258
|
+
# # => - account_owner
|
259
|
+
# # => - ZD: Alice
|
260
|
+
# # => - SFDC: Bob
|
261
|
+
# # => done determining differences
|
262
|
+
# # => Determining organizations not in SFDC to tag...done
|
263
|
+
# # => Comparison report:
|
264
|
+
# # => - Organization Creates: 0
|
265
|
+
# # => - Contacts to create: 0
|
266
|
+
# # => - Organization Updates: 1
|
267
|
+
# # => - Orgs Not in SFDC to tag: 0
|
268
|
+
def self.compare_global_organizations(redis_client, zendesk_client, salesforce_client, verbose = false)
|
269
|
+
differences = {
|
270
|
+
creates: [],
|
271
|
+
updates: [],
|
272
|
+
not_in_sfdc: [],
|
273
|
+
contacts: []
|
274
|
+
}
|
275
|
+
@redis_client = redis_client
|
276
|
+
@zendesk_client = zendesk_client
|
277
|
+
@salesforce_client = salesforce_client
|
278
|
+
@verbose = verbose
|
279
|
+
@accounts = determine_global_accounts
|
280
|
+
@organizations = determine_global_organizations
|
281
|
+
puts 'Determining differences...' if @verbose
|
282
|
+
(comparable_accounts - global_comparable_orgs).each do |diff|
|
283
|
+
org = @organizations.detect { |o| o['salesforce_id'] == diff['salesforce_id'] }
|
284
|
+
if org.nil?
|
285
|
+
unless diff['greatly_expired']
|
286
|
+
puts "- Need to create #{diff['name']} (#{diff['salesforce_id']})" if @verbose
|
287
|
+
differences[:creates].push(global_org_creation_object(diff))
|
288
|
+
acc = @accounts.detect { |a| a['salesforce_id'] == diff['salesforce_id'] }
|
289
|
+
differences[:contacts].push(acc['sold_to']) unless acc.nil?
|
290
|
+
end
|
291
|
+
else
|
292
|
+
if @verbose
|
293
|
+
puts "- Differences for #{diff['name']} (#{org['id']} / #{diff['salesforce_id']})"
|
294
|
+
diff.keys.each do |k|
|
295
|
+
next if diff[k] == org[k]
|
296
|
+
|
297
|
+
puts " - #{k}"
|
298
|
+
puts " - ZD: #{org[k]}"
|
299
|
+
puts " - SFDC: #{diff[k]}"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
differences[:updates].push(global_org_update_object(diff, org))
|
303
|
+
end
|
304
|
+
end
|
305
|
+
print 'Determining organizations not in SFDC to tag...' if @verbose
|
306
|
+
accounts_ids = @accounts.map { |a| a['salesforce_id'] }
|
307
|
+
differences[:not_in_sfdc] = @organizations.reject { |o| accounts_ids.include?(o['salesforce_id']) || o['not_in_sfdc'] }
|
308
|
+
puts 'done' if @verbose
|
309
|
+
global_report(differences) if @verbose
|
310
|
+
differences
|
311
|
+
end
|
312
|
+
|
313
|
+
##
|
314
|
+
# Generate a comparison hash for Zendesk US Government organizations
|
315
|
+
#
|
316
|
+
# @author Jason Colyer
|
317
|
+
# @since 1.0.28
|
318
|
+
# @param redis_client [Object] An instance of {Readiness::Redis}
|
319
|
+
# @param zendesk_client [Object] An instance of {Readines::Zendesk::Client}
|
320
|
+
# @param salesforce_client [Object] An instance of {Readines::Salesforce::Client}
|
321
|
+
# @param verbose [Boolean] If you want verbose output or not
|
322
|
+
# @return [Hash]
|
323
|
+
# @example
|
324
|
+
# require 'support_readiness'
|
325
|
+
# zendesk_config = Readiness::Zendesk::Configuration.new
|
326
|
+
# zendesk_config.username = ENV.fetch('ZD_US_USERNAME')
|
327
|
+
# zendesk_config.token = ENV.fetch('ZD_US_TOKEN')
|
328
|
+
# zendesk_config.url = ENV.fetch('ZD_US_URL')
|
329
|
+
# zendesk_client = Readiness::Zendesk::Client.new(zendesk_config)
|
330
|
+
#
|
331
|
+
# sfdc_config = Readiness::Salesforce::Configuration.new
|
332
|
+
# sfdc_config.api_version = '58.0'
|
333
|
+
# sfdc_config.client_id = ENV.fetch('SFDC_CLIENTID')
|
334
|
+
# sfdc_config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
335
|
+
# sfdc_config.password = ENV.fetch('SFDC_PASSWORD')
|
336
|
+
# sfdc_config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
337
|
+
# sfdc_config.username = ENV.fetch('SFDC_USERNAME')
|
338
|
+
# sfdc_client = Readiness::Salesforce::Client.new(sfdc_config)
|
339
|
+
#
|
340
|
+
# redis_client = Readiness::Redis.new(ENV.fetch('REDIS_HOST'), ENV.fetch('REDIS_PORT'), ENV.fetch('REDIS_PASSWORD'))
|
341
|
+
#
|
342
|
+
# diffs = Readiness::Repos::ZendeskSalesforceSync.compare_usgov_organizations(redis_client, zendesk_client, sfdc_client, verbose = true)
|
343
|
+
# # => Gathering from Salesforce...done
|
344
|
+
# # => Gathering Organizations...received from Redis cache.
|
345
|
+
# # => Determining differences...
|
346
|
+
# # => - Differences for 123abc45 Example Org (123456789 / 001ABC123456)
|
347
|
+
# # => - account_owner
|
348
|
+
# # => - ZD: Alice
|
349
|
+
# # => - SFDC: Bob
|
350
|
+
# # => done determining differences
|
351
|
+
# # => Determining organizations not in SFDC to tag...done
|
352
|
+
# # => Comparison report:
|
353
|
+
# # => - Organizations
|
354
|
+
# # => - Creates: 0
|
355
|
+
# # => - Updates: 1
|
356
|
+
# # => - Not in SFDC to tag: 0
|
357
|
+
def self.compare_usgov_organizations(redis_client, zendesk_client, salesforce_client, verbose = false)
|
358
|
+
differences = {
|
359
|
+
creates: [],
|
360
|
+
updates: [],
|
361
|
+
not_in_sfdc: []
|
362
|
+
}
|
363
|
+
@redis_client = redis_client
|
364
|
+
@zendesk_client = zendesk_client
|
365
|
+
@salesforce_client = salesforce_client
|
366
|
+
@verbose = verbose
|
367
|
+
@accounts = determine_usgov_accounts
|
368
|
+
@organizations = determine_usgov_organizations
|
369
|
+
puts 'Determining differences...' if @verbose
|
370
|
+
(comparable_accounts - usgov_comparable_orgs).each do |diff|
|
371
|
+
org = @organizations.detect { |o| o['salesforce_id'] == diff['salesforce_id'] }
|
372
|
+
if org.nil?
|
373
|
+
unless diff['greatly_expired']
|
374
|
+
puts "- Need to create #{diff['name']} (#{diff['salesforce_id']})" if @verbose
|
375
|
+
differences[:creates].push(usgov_org_creation_object(diff))
|
376
|
+
acc = @accounts.detect { |a| a['salesforce_id'] == diff['salesforce_id'] }
|
377
|
+
differences[:contacts].push(acc['sold_to']) unless acc.nil?
|
378
|
+
end
|
379
|
+
else
|
380
|
+
if @verbose
|
381
|
+
puts "- Differences for #{diff['name']} (#{org['id']} / #{diff['salesforce_id']})"
|
382
|
+
diff.keys.each do |k|
|
383
|
+
next if diff[k] == org[k]
|
384
|
+
|
385
|
+
puts " - #{k}"
|
386
|
+
puts " - ZD: #{org[k]}"
|
387
|
+
puts " - SFDC: #{diff[k]}"
|
388
|
+
end
|
389
|
+
end
|
390
|
+
differences[:updates].push(usgov_org_update_object(diff, org))
|
391
|
+
end
|
392
|
+
end
|
393
|
+
print 'Determining organizations not in SFDC to tag...' if @verbose
|
394
|
+
accounts_ids = @accounts.map { |a| a['salesforce_id'] }
|
395
|
+
differences[:not_in_sfdc] = @organizations.reject { |o| accounts_ids.include?(o['salesforce_id']) || o['not_in_sfdc'] }
|
396
|
+
puts 'done' if @verbose
|
397
|
+
usgov_org_report(differences) if @verbose
|
398
|
+
differences
|
399
|
+
end
|
400
|
+
|
401
|
+
##
|
402
|
+
# Generate a comparison hash for Zendesk US Government users
|
403
|
+
#
|
404
|
+
# @author Jason Colyer
|
405
|
+
# @since 1.0.28
|
406
|
+
# @param redis_client [Object] An instance of {Readiness::Redis}
|
407
|
+
# @param zendesk_client [Object] An instance of {Readines::Zendesk::Client}
|
408
|
+
# @param salesforce_client [Object] An instance of {Readines::Salesforce::Client}
|
409
|
+
# @param verbose [Boolean] If you want verbose output or not
|
410
|
+
# @return [Hash]
|
411
|
+
# @example
|
412
|
+
# require 'support_readiness'
|
413
|
+
# zendesk_config = Readiness::Zendesk::Configuration.new
|
414
|
+
# zendesk_config.username = ENV.fetch('ZD_US_USERNAME')
|
415
|
+
# zendesk_config.token = ENV.fetch('ZD_US_TOKEN')
|
416
|
+
# zendesk_config.url = ENV.fetch('ZD_US_URL')
|
417
|
+
# zendesk_client = Readiness::Zendesk::Client.new(zendesk_config)
|
418
|
+
#
|
419
|
+
# sfdc_config = Readiness::Salesforce::Configuration.new
|
420
|
+
# sfdc_config.api_version = '58.0'
|
421
|
+
# sfdc_config.client_id = ENV.fetch('SFDC_CLIENTID')
|
422
|
+
# sfdc_config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
423
|
+
# sfdc_config.password = ENV.fetch('SFDC_PASSWORD')
|
424
|
+
# sfdc_config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
425
|
+
# sfdc_config.username = ENV.fetch('SFDC_USERNAME')
|
426
|
+
# sfdc_client = Readiness::Salesforce::Client.new(sfdc_config)
|
427
|
+
#
|
428
|
+
# redis_client = Readiness::Redis.new(ENV.fetch('REDIS_HOST'), ENV.fetch('REDIS_PORT'), ENV.fetch('REDIS_PASSWORD'))
|
429
|
+
#
|
430
|
+
# diffs = Readiness::Repos::ZendeskSalesforceSync.compare_usgov_users(redis_client, zendesk_client, sfdc_client, verbose = true)
|
431
|
+
# # => Gathering from Salesforce...done
|
432
|
+
# # => Gathering Users...received from Redis cache.
|
433
|
+
# # => Determining differences...
|
434
|
+
# # => - Differences for alice@example.com (123456789)
|
435
|
+
# # => - name
|
436
|
+
# # => - ZD: Alice
|
437
|
+
# # => - SFDC: Alice Example
|
438
|
+
# # => done determining differences
|
439
|
+
# # => Determining organizations not in SFDC to tag...done
|
440
|
+
# # => Comparison report:
|
441
|
+
# # => - Users
|
442
|
+
# # => - Creates: 0
|
443
|
+
# # => - Updates: 1
|
444
|
+
# # => - Not in SFDC to tag: 0
|
445
|
+
def self.compare_usgov_users(redis_client, zendesk_client, salesforce_client, verbose = false)
|
446
|
+
differences = {
|
447
|
+
creates: [],
|
448
|
+
updates: [],
|
449
|
+
not_in_sfdc: []
|
450
|
+
}
|
451
|
+
@redis_client = redis_client
|
452
|
+
@zendesk_client = zendesk_client
|
453
|
+
@salesforce_client = salesforce_client
|
454
|
+
@verbose = verbose
|
455
|
+
@organizations = determine_usgov_organizations
|
456
|
+
@zd_users = determine_usgov_users
|
457
|
+
@contacts = determine_usgov_contacts
|
458
|
+
puts 'Determining differences...' if @verbose
|
459
|
+
(@contacts - usgov_comparable_users).each do |diff|
|
460
|
+
user = @zd_users.detect { |u| u['email'] == diff['email'] }
|
461
|
+
if user.nil?
|
462
|
+
puts "- Need to create #{diff['email']} (#{diff['name']})" if @verbose
|
463
|
+
differences[:creates].push(usgov_user_creation_object(diff))
|
464
|
+
else
|
465
|
+
if @verbose
|
466
|
+
puts "- Differences for #{diff['email']} (#{user['id']})"
|
467
|
+
diff.keys.each do |k|
|
468
|
+
next if diff[k] == user[k]
|
469
|
+
|
470
|
+
puts " - #{k}"
|
471
|
+
puts " - ZD: #{user[k]}"
|
472
|
+
puts " - SFDC: #{diff[k]}"
|
473
|
+
end
|
474
|
+
end
|
475
|
+
differences[:updates].push(usgov_user_update_object(diff, user))
|
476
|
+
end
|
477
|
+
end
|
478
|
+
differences[:creates].compact!
|
479
|
+
differences[:updates].compact!
|
480
|
+
print 'Determining users not in SFDC to tag...' if @verbose
|
481
|
+
emails = @contacts.map { |c| c['email'].downcase.strip }
|
482
|
+
differences[:not_in_sfdc] = @zd_users.reject { |u| usgov_exclude_from_tagging(u, emails) }
|
483
|
+
puts 'done' if @verbose
|
484
|
+
usgov_user_report(differences) if @verbose
|
485
|
+
differences
|
486
|
+
end
|
487
|
+
|
488
|
+
def self.usgov_exclude_from_tagging(user, emails)
|
489
|
+
return true if emails.include? user['email']
|
490
|
+
return true if user['not_in_sfdc']
|
491
|
+
|
492
|
+
false
|
493
|
+
end
|
494
|
+
|
495
|
+
##
|
496
|
+
# Print a comparison report for Zendesk Global
|
497
|
+
#
|
498
|
+
# @author Jason Colyer
|
499
|
+
# @since 1.0.28
|
500
|
+
# @param differences [Hash]
|
501
|
+
def self.global_report(differences)
|
502
|
+
puts 'Comparison report:'
|
503
|
+
puts "- Organization Creates: #{differences[:creates].count}"
|
504
|
+
puts " - Contacts to create: #{differences[:contacts].count}"
|
505
|
+
puts "- Organization Updates: #{differences[:updates].count}"
|
506
|
+
puts "- Orgs Not in SFDC to tag: #{differences[:not_in_sfdc].count}"
|
507
|
+
end
|
508
|
+
|
509
|
+
##
|
510
|
+
# Print a organization comparison report for Zendesk US Government
|
511
|
+
#
|
512
|
+
# @author Jason Colyer
|
513
|
+
# @since 1.0.28
|
514
|
+
# @param differences [Hash]
|
515
|
+
def self.usgov_org_report(differences)
|
516
|
+
puts 'Comparison report:'
|
517
|
+
puts '- Organizations'
|
518
|
+
puts " - Creates: #{differences[:creates].count}"
|
519
|
+
puts " - Updates: #{differences[:updates].count}"
|
520
|
+
puts " - Not in SFDC to tag: #{differences[:not_in_sfdc].count}"
|
521
|
+
end
|
522
|
+
|
523
|
+
##
|
524
|
+
# Print an user comparison report for Zendesk US Government
|
525
|
+
#
|
526
|
+
# @author Jason Colyer
|
527
|
+
# @since 1.0.28
|
528
|
+
# @param differences [Hash]
|
529
|
+
def self.usgov_user_report(differences)
|
530
|
+
puts 'Comparison report:'
|
531
|
+
puts '- Users'
|
532
|
+
puts " - Creates: #{differences[:creates].count}"
|
533
|
+
puts " - Updates: #{differences[:updates].count}"
|
534
|
+
puts " - Not in SFDC to tag: #{differences[:not_in_sfdc].count}"
|
535
|
+
end
|
536
|
+
|
537
|
+
##
|
538
|
+
# Gather SFDC Accounts for Zendesk Global
|
539
|
+
#
|
540
|
+
# @author Jason Colyer
|
541
|
+
# @since 1.0.28
|
542
|
+
# @return [Array]
|
543
|
+
def self.determine_global_accounts
|
544
|
+
print 'Gathering from Salesforce...' if @verbose
|
545
|
+
accs = Readiness::Salesforce::Accounts.global_accounts(@salesforce_client)
|
546
|
+
puts 'done' if @verbose
|
547
|
+
accs
|
548
|
+
end
|
549
|
+
|
550
|
+
##
|
551
|
+
# Gather SFDC Accounts for Zendesk US Government
|
552
|
+
#
|
553
|
+
# @author Jason Colyer
|
554
|
+
# @since 1.0.28
|
555
|
+
# @return [Array]
|
556
|
+
def self.determine_usgov_accounts
|
557
|
+
print 'Gathering from Salesforce...' if @verbose
|
558
|
+
accs = Readiness::Salesforce::Accounts.usgov_accounts(@salesforce_client)
|
559
|
+
puts 'done' if @verbose
|
560
|
+
accs
|
561
|
+
end
|
562
|
+
|
563
|
+
##
|
564
|
+
# Gather SFDC Contacts for Zendesk US Government
|
565
|
+
#
|
566
|
+
# @author Jason Colyer
|
567
|
+
# @since 1.0.28
|
568
|
+
# @return [Array]
|
569
|
+
def self.determine_usgov_contacts
|
570
|
+
print 'Gathering from Salesforce...' if @verbose
|
571
|
+
users = Readiness::Salesforce::Contacts.usgov_contacts(@salesforce_client)
|
572
|
+
puts 'done' if @verbose
|
573
|
+
users
|
574
|
+
end
|
575
|
+
|
576
|
+
##
|
577
|
+
# Gather Zendesk Global organizations, either from Redis or Zendesk
|
578
|
+
#
|
579
|
+
# @author Jason Colyer
|
580
|
+
# @since 1.0.28
|
581
|
+
# @return [Array]
|
582
|
+
def self.determine_global_organizations
|
583
|
+
print 'Gathering Organizations...' if @verbose
|
584
|
+
orgs = Readiness::Redis.get(@redis_client, 'global_organizations')
|
585
|
+
unless orgs.nil?
|
586
|
+
puts 'received from Redis cache.' if @verbose
|
587
|
+
return orgs
|
588
|
+
end
|
589
|
+
print 'needing to gather from Zendesk...' if @verbose
|
590
|
+
orgs = Readiness::Zendesk::Organizations.list_many(@zendesk_client)
|
591
|
+
puts 'done' if @verbose
|
592
|
+
orgs.map { |o| global_zd_sync_object(o) }
|
593
|
+
end
|
594
|
+
|
595
|
+
##
|
596
|
+
# Gather Zendesk US Government organizations, either from Redis or Zendesk
|
597
|
+
#
|
598
|
+
# @author Jason Colyer
|
599
|
+
# @since 1.0.28
|
600
|
+
# @return [Array]
|
601
|
+
def self.determine_usgov_organizations
|
602
|
+
print 'Gathering Organizations...' if @verbose
|
603
|
+
orgs = Readiness::Redis.get(@redis_client, 'usgov_organizations')
|
604
|
+
unless orgs.nil?
|
605
|
+
puts 'received from Redis cache.' if @verbose
|
606
|
+
return orgs
|
607
|
+
end
|
608
|
+
print 'needing to gather from Zendesk...' if @verbose
|
609
|
+
orgs = Readiness::Zendesk::Organizations.list_many(@zendesk_client)
|
610
|
+
puts 'done' if @verbose
|
611
|
+
orgs.map { |o| usgov_zd_org_sync_object(o) }
|
612
|
+
end
|
613
|
+
|
614
|
+
##
|
615
|
+
# Gather Zendesk US Government users, either from Redis or Zendesk
|
616
|
+
#
|
617
|
+
# @author Jason Colyer
|
618
|
+
# @since 1.0.28
|
619
|
+
# @return [Array]
|
620
|
+
def self.determine_usgov_users
|
621
|
+
print 'Gathering Users...' if @verbose
|
622
|
+
users = Readiness::Redis.get(@redis_client, 'usgov_users')
|
623
|
+
unless users.nil?
|
624
|
+
puts 'received from Redis cache.' if @verbose
|
625
|
+
return users
|
626
|
+
end
|
627
|
+
print 'needing to gather from Zendesk...' if @verbose
|
628
|
+
users = Readiness::Zendesk::Users.list_many(@zendesk_client, 0, false, ['end-user'])
|
629
|
+
puts 'done' if @verbose
|
630
|
+
users.map { |u| usgov_zd_user_sync_object(u) }.compact
|
631
|
+
end
|
632
|
+
|
633
|
+
##
|
634
|
+
# Create a comparable account object
|
635
|
+
#
|
636
|
+
# @author Jason Colyer
|
637
|
+
# @since 1.0.28
|
638
|
+
# @param org [Hash]
|
639
|
+
# @return [Hash]
|
640
|
+
def self.comparable_accounts
|
641
|
+
new_accounts = Marshal.load(Marshal.dump(@accounts))
|
642
|
+
new_accounts.map { |a| a.delete('sold_to') }
|
643
|
+
new_accounts
|
644
|
+
end
|
645
|
+
|
646
|
+
##
|
647
|
+
# Modify Zendesk Global organizations into a comparable Array
|
648
|
+
#
|
649
|
+
# @author Jason Colyer
|
650
|
+
# @since 1.0.28
|
651
|
+
# @return [Array]
|
652
|
+
def self.global_comparable_orgs
|
653
|
+
new_orgs = Marshal.load(Marshal.dump(@organizations))
|
654
|
+
new_orgs.map { |zd| global_comparable_org(zd) }
|
655
|
+
end
|
656
|
+
|
657
|
+
##
|
658
|
+
# Modify Zendesk US Government organizations into a comparable Array
|
659
|
+
#
|
660
|
+
# @author Jason Colyer
|
661
|
+
# @since 1.0.28
|
662
|
+
# @return [Array]
|
663
|
+
def self.usgov_comparable_orgs
|
664
|
+
new_orgs = Marshal.load(Marshal.dump(@organizations))
|
665
|
+
new_orgs.map { |zd| usgov_comparable_org(zd) }
|
666
|
+
end
|
667
|
+
|
668
|
+
##
|
669
|
+
# Modify Zendesk US Government users into a comparable Array
|
670
|
+
#
|
671
|
+
# @author Jason Colyer
|
672
|
+
# @since 1.0.28
|
673
|
+
# @return [Array]
|
674
|
+
def self.usgov_comparable_users
|
675
|
+
new_users = Marshal.load(Marshal.dump(@zd_users))
|
676
|
+
new_users.map { |zd| usgov_comparable_user(zd) }
|
677
|
+
end
|
678
|
+
|
679
|
+
##
|
680
|
+
# Create a comparable org object for Zendesk Global
|
681
|
+
#
|
682
|
+
# @author Jason Colyer
|
683
|
+
# @since 1.0.28
|
684
|
+
# @param org [Hash]
|
685
|
+
# @return [Hash]
|
686
|
+
def self.global_comparable_org(org)
|
687
|
+
zd = org.dup
|
688
|
+
zd.delete('id')
|
689
|
+
zd['aar'] = zd['aar'].to_f
|
690
|
+
zd['seats_decimal'] = zd['seats_decimal'].to_f
|
691
|
+
zd
|
692
|
+
end
|
693
|
+
|
694
|
+
##
|
695
|
+
# Create a comparable org object for Zendesk US Government
|
696
|
+
#
|
697
|
+
# @author Jason Colyer
|
698
|
+
# @since 1.0.28
|
699
|
+
# @param org [Hash]
|
700
|
+
# @return [Hash]
|
701
|
+
def self.usgov_comparable_org(org)
|
702
|
+
zd = org.dup
|
703
|
+
zd.delete('id')
|
704
|
+
zd['arr'] = zd['arr'].to_f
|
705
|
+
zd['number_of_seats'] = zd['number_of_seats'].to_f
|
706
|
+
zd
|
707
|
+
end
|
708
|
+
|
709
|
+
##
|
710
|
+
# Create a comparable user object for Zendesk US Government
|
711
|
+
#
|
712
|
+
# @author Jason Colyer
|
713
|
+
# @since 1.0.28
|
714
|
+
# @param org [Hash]
|
715
|
+
# @return [Hash]
|
716
|
+
def self.usgov_comparable_user(user)
|
717
|
+
zd = user.dup
|
718
|
+
zd.delete('id')
|
719
|
+
zd.delete('org_id')
|
720
|
+
zd
|
721
|
+
end
|
722
|
+
|
723
|
+
##
|
724
|
+
# Generate a sync object from Zendesk Global information for comparison purposes
|
725
|
+
#
|
726
|
+
# @author Jason Colyer
|
727
|
+
# @since 1.0.28
|
728
|
+
# @param org [Object] An instance of {Readiness::Zendesk::Organizations}
|
729
|
+
# @return [Hash]
|
730
|
+
def self.global_zd_sync_object(org)
|
731
|
+
{
|
732
|
+
'id' => org.id,
|
733
|
+
'name' => org.name,
|
734
|
+
'salesforce_id' => org.organization_fields['salesforce_id'],
|
735
|
+
'sfdc_short_id' => org.organization_fields['sfdc_short_id'],
|
736
|
+
'support_level' => org.organization_fields['support_level'],
|
737
|
+
'aar' => org.organization_fields['aar'],
|
738
|
+
'sales_segmentation' => org.organization_fields['sales_segmentation'],
|
739
|
+
'account_owner' => org.organization_fields['account_owner'],
|
740
|
+
'type' => org.organization_fields['account_type'],
|
741
|
+
'technical_account_manager' => org.organization_fields['technical_account_manager'],
|
742
|
+
'solutions_architect' => org.organization_fields['solutions_architect'],
|
743
|
+
'seats_decimal' => org.organization_fields['seats_decimal'],
|
744
|
+
'org_region' => org.organization_fields['org_region'],
|
745
|
+
'health_score' => org.organization_fields['health_score'],
|
746
|
+
'expiration_date' => org.organization_fields['expiration_date'],
|
747
|
+
'restricted_account' => org.organization_fields['restricted_account'],
|
748
|
+
'greatly_expired' => org.organization_fields['greatly_expired'],
|
749
|
+
'sub_consumption_ai' => org.organization_fields['sub_consumption_ai'],
|
750
|
+
'sub_consumption_cicd_minutes' => org.organization_fields['sub_consumption_cicd_minutes'],
|
751
|
+
'sub_consumption_eap' => org.organization_fields['sub_consumption_eap'],
|
752
|
+
'sub_consumption_storage' => org.organization_fields['sub_consumption_storage'],
|
753
|
+
'sub_proserv' => org.organization_fields['sub_proserv'],
|
754
|
+
'sub_dotcom_premium' => org.organization_fields['sub_dotcom_premium'],
|
755
|
+
'sub_dotcom_ultimate' => org.organization_fields['sub_dotcom_ultimate'],
|
756
|
+
'sub_sm_starter' => org.organization_fields['sub_sm_starter'],
|
757
|
+
'sub_sm_premium' => org.organization_fields['sub_sm_premium'],
|
758
|
+
'sub_sm_ultimate' => org.organization_fields['sub_sm_ultimate'],
|
759
|
+
'sub_usgov_12x5' => org.organization_fields['sub_usgov_12x5'],
|
760
|
+
'sub_usgov_24x7' => org.organization_fields['sub_usgov_24x7'],
|
761
|
+
'sub_gitlab_dedicated' => org.organization_fields['sub_gitlab_dedicated'],
|
762
|
+
'sub_edu' => org.organization_fields['sub_edu'],
|
763
|
+
'sub_oss' => org.organization_fields['sub_oss'],
|
764
|
+
'sub_community_other' => org.organization_fields['sub_community_other'],
|
765
|
+
'sub_ss_ase' => org.organization_fields['sub_ss_ase'],
|
766
|
+
'sub_other' => org.organization_fields['sub_other'],
|
767
|
+
'partner_customer' => org.organization_fields['partner_customer'],
|
768
|
+
'not_in_sfdc' => org.organization_fields['not_in_sfdc'],
|
769
|
+
'support_hold' => org.organization_fields['support_hold']
|
770
|
+
}
|
771
|
+
end
|
772
|
+
|
773
|
+
##
|
774
|
+
# Generate a sync object from Zendesk US Government organization information for comparison purposes
|
775
|
+
#
|
776
|
+
# @author Jason Colyer
|
777
|
+
# @since 1.0.28
|
778
|
+
# @param org [Object] An instance of {Readiness::Zendesk::Organizations}
|
779
|
+
# @return [Hash]
|
780
|
+
def self.usgov_zd_org_sync_object(org)
|
781
|
+
{
|
782
|
+
'id' => org.id,
|
783
|
+
'name' => org.name,
|
784
|
+
'salesforce_id' => org.organization_fields['salesforce_id'],
|
785
|
+
'sfdc_short_id' => org.organization_fields['sfdc_short_id'],
|
786
|
+
'support_level' => org.organization_fields['support_level'],
|
787
|
+
'arr' => org.organization_fields['arr'],
|
788
|
+
'market_segment' => org.organization_fields['market_segment'],
|
789
|
+
'account_owner' => org.organization_fields['account_owner'],
|
790
|
+
'type' => org.organization_fields['account_type'],
|
791
|
+
'technical_account_manager' => org.organization_fields['technical_account_manager'],
|
792
|
+
'solutions_architect' => org.organization_fields['solutions_architect'],
|
793
|
+
'number_of_seats' => org.organization_fields['number_of_seats'],
|
794
|
+
'health_score' => org.organization_fields['health_score'],
|
795
|
+
'expiration_date' => org.organization_fields['expiration_date'],
|
796
|
+
'restricted_account' => org.organization_fields['restricted_account'],
|
797
|
+
'greatly_expired' => org.organization_fields['greatly_expired'],
|
798
|
+
'emergency_support_24x7' => org.organization_fields['emergency_support_24x7'],
|
799
|
+
'sub_consumption_ai' => org.organization_fields['sub_consumption_ai'],
|
800
|
+
'sub_consumption_cicd_minutes' => org.organization_fields['sub_consumption_cicd_minutes'],
|
801
|
+
'sub_consumption_eap' => org.organization_fields['sub_consumption_eap'],
|
802
|
+
'sub_consumption_storage' => org.organization_fields['sub_consumption_storage'],
|
803
|
+
'sub_proserv' => org.organization_fields['sub_proserv'],
|
804
|
+
'sub_dotcom_premium' => org.organization_fields['sub_dotcom_premium'],
|
805
|
+
'sub_dotcom_ultimate' => org.organization_fields['sub_dotcom_ultimate'],
|
806
|
+
'sub_sm_starter' => org.organization_fields['sub_sm_starter'],
|
807
|
+
'sub_sm_premium' => org.organization_fields['sub_sm_premium'],
|
808
|
+
'sub_sm_ultimate' => org.organization_fields['sub_sm_ultimate'],
|
809
|
+
'sub_usgov_12x5' => org.organization_fields['sub_usgov_12x5'],
|
810
|
+
'sub_usgov_24x7' => org.organization_fields['sub_usgov_24x7'],
|
811
|
+
'sub_gitlab_dedicated' => org.organization_fields['sub_gitlab_dedicated'],
|
812
|
+
'sub_edu' => org.organization_fields['sub_edu'],
|
813
|
+
'sub_oss' => org.organization_fields['sub_oss'],
|
814
|
+
'sub_community_other' => org.organization_fields['sub_community_other'],
|
815
|
+
'sub_ss_ase' => org.organization_fields['sub_ss_ase'],
|
816
|
+
'sub_other' => org.organization_fields['sub_other'],
|
817
|
+
'not_in_sfdc' => org.organization_fields['not_in_sfdc'],
|
818
|
+
'support_hold' => org.organization_fields['support_hold']
|
819
|
+
}
|
820
|
+
end
|
821
|
+
|
822
|
+
##
|
823
|
+
# Generate a sync object from Zendesk US Government user information for comparison purposes
|
824
|
+
#
|
825
|
+
# @author Jason Colyer
|
826
|
+
# @since 1.0.28
|
827
|
+
# @param user [Object] An instance of {Readiness::Zendesk::Users}
|
828
|
+
# @return [Hash]
|
829
|
+
def self.usgov_zd_user_sync_object(user)
|
830
|
+
return nil if user.email =~ /gitlab.com$/
|
831
|
+
|
832
|
+
org = locate_org_from_user(user)
|
833
|
+
if org.nil?
|
834
|
+
return {
|
835
|
+
"id" => user.id,
|
836
|
+
"name" => user.name,
|
837
|
+
"email" => user.email,
|
838
|
+
"org" => nil,
|
839
|
+
"org_id" => nil,
|
840
|
+
"salesforce_id" => nil,
|
841
|
+
"not_in_sfdc" => user.user_fields['not_in_sfdc']
|
842
|
+
}
|
843
|
+
end
|
844
|
+
{
|
845
|
+
"id" => user.id,
|
846
|
+
"name" => user.name,
|
847
|
+
"email" => user.email,
|
848
|
+
"org" => (org.is_a?(Hash) ? org['name'] : org.name),
|
849
|
+
"org_id" => user.organization_id,
|
850
|
+
"salesforce_id" => (org.is_a?(Hash) ? org['salesforce_id'] : org.organization_fields['salesforce_id']),
|
851
|
+
"not_in_sfdc" => user.user_fields['not_in_sfdc']
|
852
|
+
}
|
853
|
+
end
|
854
|
+
|
855
|
+
##
|
856
|
+
# Locate a Zendesk organization either via the Redis values or from Zendesk
|
857
|
+
#
|
858
|
+
# @author Jason Colyer
|
859
|
+
# @since 1.0.28
|
860
|
+
# @param oid [Integer] The organization ID
|
861
|
+
def self.locate_org_from_user(user)
|
862
|
+
return nil if user.organization_id.nil?
|
863
|
+
|
864
|
+
detect = @organizations.detect { |o| o['id'] == user.organization_id }
|
865
|
+
return detect unless detect.nil?
|
866
|
+
|
867
|
+
Readiness::Zendesk::Organizations.find!(@zendesk_client, user.organization_id)
|
868
|
+
end
|
869
|
+
|
870
|
+
##
|
871
|
+
# Create an instance of {Readiness::Zendesk::Organizations} for Zendesk Global creation purposes
|
872
|
+
#
|
873
|
+
# @author Jason Colyer
|
874
|
+
# @since 1.0.28
|
875
|
+
# @param account [Hash]
|
876
|
+
# @return [Object]
|
877
|
+
def self.global_org_creation_object(account)
|
878
|
+
org = Readiness::Zendesk::Organizations.new
|
879
|
+
org.name = account['name']
|
880
|
+
org.organization_fields = global_custom_fields_from_account(account)
|
881
|
+
org
|
882
|
+
end
|
883
|
+
|
884
|
+
##
|
885
|
+
# Create an instance of {Readiness::Zendesk::Organizations} for Zendesk US Government creation purposes
|
886
|
+
#
|
887
|
+
# @author Jason Colyer
|
888
|
+
# @since 1.0.28
|
889
|
+
# @param account [Hash]
|
890
|
+
# @return [Object]
|
891
|
+
def self.usgov_org_creation_object(account)
|
892
|
+
org = Readiness::Zendesk::Organizations.new
|
893
|
+
org.name = account['name']
|
894
|
+
org.organization_fields = usgov_custom_fields_from_account(account)
|
895
|
+
org
|
896
|
+
end
|
897
|
+
|
898
|
+
##
|
899
|
+
# Create an instance of {Readiness::Zendesk::Users} for Zendesk US Government creation purposes
|
900
|
+
#
|
901
|
+
# @author Jason Colyer
|
902
|
+
# @since 1.0.28
|
903
|
+
# @param contact [Hash]
|
904
|
+
# @return [Object]
|
905
|
+
def self.usgov_user_creation_object(contact)
|
906
|
+
org = @organizations.detect { |o| o['salesforce_id'] == contact['salesforce_id'] }
|
907
|
+
return nil if org.nil?
|
908
|
+
|
909
|
+
user = Readiness::Zendesk::Users.new
|
910
|
+
user.email = contact['email']
|
911
|
+
user.name = contact['name']
|
912
|
+
user.organization_id = org['id']
|
913
|
+
user
|
914
|
+
end
|
915
|
+
|
916
|
+
##
|
917
|
+
# Create an instance of {Readiness::Zendesk::Organizations} for Zendesk Global update purposes
|
918
|
+
#
|
919
|
+
# @author Jason Colyer
|
920
|
+
# @since 1.0.28
|
921
|
+
# @param account [Hash]
|
922
|
+
# @param organization [Hash]
|
923
|
+
# @return [Object]
|
924
|
+
def self.global_org_update_object(account, organization)
|
925
|
+
org = Readiness::Zendesk::Organizations.find!(@zendesk_client, organization['id'])
|
926
|
+
org.name = account['name']
|
927
|
+
org.organization_fields = global_custom_fields_from_account(account)
|
928
|
+
org
|
929
|
+
end
|
930
|
+
|
931
|
+
##
|
932
|
+
# Create an instance of {Readiness::Zendesk::Organizations} for Zendesk US Government update purposes
|
933
|
+
#
|
934
|
+
# @author Jason Colyer
|
935
|
+
# @since 1.0.28
|
936
|
+
# @param account [Hash]
|
937
|
+
# @param organization [Hash]
|
938
|
+
# @return [Object]
|
939
|
+
def self.usgov_org_update_object(account, organization)
|
940
|
+
org = Readiness::Zendesk::Organizations.find!(@zendesk_client, organization['id'])
|
941
|
+
org.name = account['name']
|
942
|
+
org.organization_fields = usgov_custom_fields_from_account(account)
|
943
|
+
org
|
944
|
+
end
|
945
|
+
|
946
|
+
##
|
947
|
+
# Create an instance of {Readiness::Zendesk::Users} for Zendesk US Government update purposes
|
948
|
+
#
|
949
|
+
# @author Jason Colyer
|
950
|
+
# @since 1.0.28
|
951
|
+
# @param contact [Hash]
|
952
|
+
# @param user [Hash]
|
953
|
+
# @return [Object]
|
954
|
+
def self.usgov_user_update_object(contact, zd_user)
|
955
|
+
user = Readiness::Zendesk::Users.find!(@zendesk_client, zd_user['id'])
|
956
|
+
org = @organizations.detect { |o| o['salesforce_id'] == contact['salesforce_id'] }
|
957
|
+
return nil if org.nil?
|
958
|
+
|
959
|
+
user.email = contact['email']
|
960
|
+
user.name = contact['name']
|
961
|
+
user.organization_id = org['id']
|
962
|
+
user.user_fields['not_in_sfdc'] = contact['not_in_sfdc']
|
963
|
+
user
|
964
|
+
end
|
965
|
+
|
966
|
+
##
|
967
|
+
# Translate SFDC account information into the custom field s Hash for Zendesk Global information
|
968
|
+
#
|
969
|
+
# @author Jason Colyer
|
970
|
+
# @since 1.0.28
|
971
|
+
# @param acc [Hash]
|
972
|
+
# @return [Hash]
|
973
|
+
def self.global_custom_fields_from_account(account)
|
974
|
+
{
|
975
|
+
'aar' => account['aar'],
|
976
|
+
'account_owner' => account['account_owner'],
|
977
|
+
'account_type' => account['type'],
|
978
|
+
'expiration_date' => account['expiration_date'],
|
979
|
+
'greatly_expired' => account['greatly_expired'],
|
980
|
+
'health_score' => account['health_score'],
|
981
|
+
'not_in_sfdc' => account['not_in_sfdc'],
|
982
|
+
'org_region' => account['org_region'],
|
983
|
+
'partner_customer' => account['partner_customer'],
|
984
|
+
'restricted_account' => account['restricted_account'],
|
985
|
+
'salesforce_id' => account['salesforce_id'],
|
986
|
+
'sales_segmentation' => account['sales_segmentation'],
|
987
|
+
'seats_decimal' => account['seats_decimal'],
|
988
|
+
'sfdc_short_id' => account['sfdc_short_id'],
|
989
|
+
'solutions_architect' => account['solutions_architect'],
|
990
|
+
'sub_community_other' => account['sub_community_other'],
|
991
|
+
'sub_consumption_ai' => account['sub_consumption_ai'],
|
992
|
+
'sub_consumption_cicd_minutes' => account['sub_consumption_cicd_minutes'],
|
993
|
+
'sub_consumption_eap' => account['sub_consumption_eap'],
|
994
|
+
'sub_consumption_storage' => account['sub_consumption_storage'],
|
995
|
+
'sub_dotcom_premium' => account['sub_dotcom_premium'],
|
996
|
+
'sub_dotcom_ultimate' => account['sub_dotcom_ultimate'],
|
997
|
+
'sub_edu' => account['sub_edu'],
|
998
|
+
'sub_gitlab_dedicated' => account['sub_gitlab_dedicated'],
|
999
|
+
'sub_oss' => account['sub_oss'],
|
1000
|
+
'sub_other' => account['sub_other'],
|
1001
|
+
'sub_proserv' => account['sub_proserv'],
|
1002
|
+
'sub_sm_premium' => account['sub_sm_premium'],
|
1003
|
+
'sub_sm_starter' => account['sub_sm_starter'],
|
1004
|
+
'sub_sm_ultimate' => account['sub_sm_ultimate'],
|
1005
|
+
'sub_ss_ase' => account['sub_ss_ase'],
|
1006
|
+
'sub_usgov_12x5' => account['sub_usgov_12x5'],
|
1007
|
+
'sub_usgov_24x7' => account['sub_usgov_24x7'],
|
1008
|
+
'support_hold' => account['support_hold'],
|
1009
|
+
'support_level' => account['support_level'],
|
1010
|
+
'technical_account_manager' => account['technical_account_manager']
|
1011
|
+
}
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
##
|
1015
|
+
# Translate SFDC account information into the custom field s Hash for Zendesk Global information
|
1016
|
+
#
|
1017
|
+
# @author Jason Colyer
|
1018
|
+
# @since 1.0.28
|
1019
|
+
# @param acc [Hash]
|
1020
|
+
# @return [Hash]
|
1021
|
+
def self.usgov_custom_fields_from_account(account)
|
1022
|
+
{
|
1023
|
+
'arr' => account['arr'],
|
1024
|
+
'account_owner' => account['account_owner'],
|
1025
|
+
'account_type' => account['type'],
|
1026
|
+
'emergency_support_24x7' => account['emergency_support_24x7'],
|
1027
|
+
'expiration_date' => account['expiration_date'],
|
1028
|
+
'greatly_expired' => account['greatly_expired'],
|
1029
|
+
'health_score' => account['health_score'],
|
1030
|
+
'not_in_sfdc' => account['not_in_sfdc'],
|
1031
|
+
'restricted_account' => account['restricted_account'],
|
1032
|
+
'salesforce_id' => account['salesforce_id'],
|
1033
|
+
'sales_segmentation' => account['sales_segmentation'],
|
1034
|
+
'number_of_seats' => account['number_of_seats'].to_i,
|
1035
|
+
'sfdc_short_id' => account['sfdc_short_id'],
|
1036
|
+
'solutions_architect' => account['solutions_architect'],
|
1037
|
+
'sub_community_other' => account['sub_community_other'],
|
1038
|
+
'sub_consumption_ai' => account['sub_consumption_ai'],
|
1039
|
+
'sub_consumption_cicd_minutes' => account['sub_consumption_cicd_minutes'],
|
1040
|
+
'sub_consumption_eap' => account['sub_consumption_eap'],
|
1041
|
+
'sub_consumption_storage' => account['sub_consumption_storage'],
|
1042
|
+
'sub_dotcom_premium' => account['sub_dotcom_premium'],
|
1043
|
+
'sub_dotcom_ultimate' => account['sub_dotcom_ultimate'],
|
1044
|
+
'sub_edu' => account['sub_edu'],
|
1045
|
+
'sub_gitlab_dedicated' => account['sub_gitlab_dedicated'],
|
1046
|
+
'sub_oss' => account['sub_oss'],
|
1047
|
+
'sub_other' => account['sub_other'],
|
1048
|
+
'sub_proserv' => account['sub_proserv'],
|
1049
|
+
'sub_sm_premium' => account['sub_sm_premium'],
|
1050
|
+
'sub_sm_starter' => account['sub_sm_starter'],
|
1051
|
+
'sub_sm_ultimate' => account['sub_sm_ultimate'],
|
1052
|
+
'sub_ss_ase' => account['sub_ss_ase'],
|
1053
|
+
'sub_usgov_12x5' => account['sub_usgov_12x5'],
|
1054
|
+
'sub_usgov_24x7' => account['sub_usgov_24x7'],
|
1055
|
+
'support_hold' => account['support_hold'],
|
1056
|
+
'support_level' => account['support_level'],
|
1057
|
+
'technical_account_manager' => account['technical_account_manager']
|
1058
|
+
}
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
def self.sfdc_links(sfdc_id)
|
1062
|
+
[
|
1063
|
+
"<https://gitlab.my.salesforce.com/#{sfdc_id}|Classic>",
|
1064
|
+
"<https://gitlab.lightning.force.com/lightning/r/Account/#{sfdc_id}/view|Lightning>"
|
1065
|
+
].join(' | ')
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
def self.global_slack_message(org)
|
1069
|
+
<<~STRING
|
1070
|
+
:double-exclaimation: Attention Support Readiness! :double-exclaimation:
|
1071
|
+
|
1072
|
+
An organization (<https://gitlab.zendesk.com/agent/organizations/{#org.id}|#{org.id}>) was created for SFDC account #{org.organization_fields['salesforce_id']} (#{sfdc_links(org.organization_fields['salesforce_id'])}) but it had no corresponsing contacts.
|
1073
|
+
|
1074
|
+
Please investigate this manually. If you are able to locate a contact to use for the created organization, please add/associate them manually.
|
1075
|
+
STRING
|
1076
|
+
end
|
1077
|
+
end
|
1078
|
+
end
|
1079
|
+
end
|
@@ -202,6 +202,7 @@ module Readiness
|
|
202
202
|
"expiration_date" => expiration,
|
203
203
|
"restricted_account" => (account.Restricted_Account__c == 'Restricted Party'),
|
204
204
|
"greatly_expired" => (partner ? false : Date.parse(expiration) <= Date.today.years_ago(3)),
|
205
|
+
"emergency_support_24x7" => subscriptions.include?('sub_usgov_24x7'),
|
205
206
|
"sub_consumption_ai" => subscriptions.include?('sub_consumption_ai'),
|
206
207
|
"sub_consumption_cicd_minutes" => subscriptions.include?('sub_consumption_cicd_minutes'),
|
207
208
|
"sub_consumption_eap" => subscriptions.include?('sub_consumption_eap'),
|
@@ -364,6 +365,7 @@ module Readiness
|
|
364
365
|
def self.account_is_partner_customer?(account, type)
|
365
366
|
return false if account.Latest_Sold_To_Contact__r.nil?
|
366
367
|
return false if type != 'customer'
|
368
|
+
return false if account.Account_ID_18__c == '0016100000g04oWAAQ'
|
367
369
|
return true if account.Latest_Sold_To_Contact__r.Email == 'ecopo@us.ibm.com'
|
368
370
|
|
369
371
|
false
|
@@ -64,6 +64,7 @@ module Readiness
|
|
64
64
|
Name,
|
65
65
|
Email,
|
66
66
|
Account.Account_ID_18__c,
|
67
|
+
Account.Type,
|
67
68
|
Account.Name,
|
68
69
|
Role__c
|
69
70
|
FROM Contact
|
@@ -75,6 +76,7 @@ module Readiness
|
|
75
76
|
(
|
76
77
|
NOT Email LIKE '%gitlab.com'
|
77
78
|
) AND
|
79
|
+
Account.Type IN ('Customer', 'Former Customer') AND
|
78
80
|
(
|
79
81
|
(
|
80
82
|
Account.Account_Demographics_Territory__c LIKE 'PUBSEC%' AND
|
@@ -600,7 +600,11 @@ module Readiness
|
|
600
600
|
'Self-Managed - Success Plan Services - 1 Year',
|
601
601
|
'Self-Managed - Success Plan Services - 2 Year',
|
602
602
|
'Self-Managed - Success Plan Services - 3 Year',
|
603
|
-
'Self-Managed - Success Plan Services - Monthly'
|
603
|
+
'Self-Managed - Success Plan Services - Monthly',
|
604
|
+
'Success Essentials - Monthly',
|
605
|
+
'Success Essentials - 3 Year',
|
606
|
+
'Success Essentials - 2 Year',
|
607
|
+
'Success Essentials - 1 Year'
|
604
608
|
]
|
605
609
|
end
|
606
610
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_support_readiness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Colyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- lib/support_readiness/repos/triggers.rb
|
285
285
|
- lib/support_readiness/repos/user_fields.rb
|
286
286
|
- lib/support_readiness/repos/views.rb
|
287
|
+
- lib/support_readiness/repos/zendesk_salesforce_sync.rb
|
287
288
|
- lib/support_readiness/salesforce.rb
|
288
289
|
- lib/support_readiness/salesforce/accounts.rb
|
289
290
|
- lib/support_readiness/salesforce/cases.rb
|