Class: Readiness::Repos::ZendeskSalesforceSync
- Defined in:
- lib/support_readiness/repos/zendesk_salesforce_sync.rb
Overview
Defines the class ZendeskSalesforceSync within the module Readiness::Repos.
Class Method Summary collapse
-
.comparable_accounts ⇒ Hash
Create a comparable account object.
-
.compare_global_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk Global.
-
.compare_usgov_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk US Government organizations.
-
.compare_usgov_users(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk US Government users.
-
.create_global_contact?(org) ⇒ Boolean
Determines if a support contact should be created for Zendesk Global.
-
.determine_global_accounts ⇒ Array
Gather SFDC Accounts for Zendesk Global.
-
.determine_global_organizations ⇒ Array
Gather Zendesk Global organizations, either from Redis or Zendesk.
-
.determine_usgov_accounts ⇒ Array
Gather SFDC Accounts for Zendesk US Government.
-
.determine_usgov_contacts ⇒ Array
Gather SFDC Contacts for Zendesk US Government.
-
.determine_usgov_organizations ⇒ Array
Gather Zendesk US Government organizations, either from Redis or Zendesk.
-
.determine_usgov_users ⇒ Array
Gather Zendesk US Government users, either from Redis or Zendesk.
-
.global_comparable_org(org) ⇒ Hash
Create a comparable org object for Zendesk Global.
-
.global_comparable_orgs ⇒ Array
Modify Zendesk Global organizations into a comparable Array.
-
.global_custom_fields_from_account(account) ⇒ Hash
Translate SFDC account information into the custom field s Hash for Zendesk Global information.
-
.global_org_creation_object(account) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk Global creation purposes.
-
.global_org_update_object(account, organization) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk Global update purposes.
-
.global_report(differences) ⇒ Object
Print a comparison report for Zendesk Global.
- .global_slack_message(org) ⇒ Object
-
.global_sync(redis_client, zendesk_client, salesforce_client, slack_client) ⇒ Object
Perform a Zendesk-Salesforce Sync for Zendesk Global.
-
.global_zd_sync_object(org) ⇒ Hash
Generate a sync object from Zendesk Global information for comparison purposes.
-
.locate_org_from_user(user) ⇒ Object
Locate a Zendesk organization either via the Redis values or from Zendesk.
- .sfdc_links(sfdc_id) ⇒ Object
-
.usgov_comparable_org(org) ⇒ Hash
Create a comparable org object for Zendesk US Government.
-
.usgov_comparable_orgs ⇒ Array
Modify Zendesk US Government organizations into a comparable Array.
-
.usgov_comparable_user(user) ⇒ Hash
Create a comparable user object for Zendesk US Government.
-
.usgov_comparable_users ⇒ Array
Modify Zendesk US Government users into a comparable Array.
-
.usgov_custom_fields_from_account(account) ⇒ Hash
Translate SFDC account information into the custom field s Hash for Zendesk Global information.
- .usgov_exclude_from_tagging(user, emails) ⇒ Object
-
.usgov_org_creation_object(account) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk US Government creation purposes.
-
.usgov_org_report(differences) ⇒ Object
Print a organization comparison report for Zendesk US Government.
-
.usgov_org_sync(redis_client, zendesk_client, salesforce_client) ⇒ Object
Perform a Zendesk-Salesforce Sync for Zendesk US Government.
-
.usgov_org_update_object(account, organization) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk US Government update purposes.
-
.usgov_user_creation_object(contact) ⇒ Object
Create an instance of Zendesk::Users for Zendesk US Government creation purposes.
-
.usgov_user_report(differences) ⇒ Object
Print an user comparison report for Zendesk US Government.
- .usgov_user_sync(redis_client, zendesk_client, salesforce_client) ⇒ Object
-
.usgov_user_update_object(contact, zd_user) ⇒ Object
Create an instance of Zendesk::Users for Zendesk US Government update purposes.
-
.usgov_zd_org_sync_object(org) ⇒ Hash
Generate a sync object from Zendesk US Government organization information for comparison purposes.
-
.usgov_zd_user_sync_object(user) ⇒ Hash
Generate a sync object from Zendesk US Government user information for comparison purposes.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.comparable_accounts ⇒ Hash
Create a comparable account object
642 643 644 645 646 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 642 def self.comparable_accounts new_accounts = Marshal.load(Marshal.dump(@accounts)) new_accounts.map { |a| a.delete('sold_to') } new_accounts end |
.compare_global_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk Global
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 269 def self.compare_global_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) differences = { creates: [], updates: [], not_in_sfdc: [], contacts: [] } @redis_client = redis_client @zendesk_client = zendesk_client @salesforce_client = salesforce_client @verbose = verbose @accounts = determine_global_accounts @organizations = determine_global_organizations puts 'Determining differences...' if @verbose (comparable_accounts - global_comparable_orgs).each do |diff| org = @organizations.detect { |o| o['salesforce_id'] == diff['salesforce_id'] } if org.nil? unless diff['greatly_expired'] puts "- Need to create #{diff['name']} (#{diff['salesforce_id']})" if @verbose differences[:creates].push(global_org_creation_object(diff)) acc = @accounts.detect { |a| a['salesforce_id'] == diff['salesforce_id'] } differences[:contacts].push(acc['sold_to']) unless acc.nil? end else if @verbose puts "- Differences for #{diff['name']} (#{org['id']} / #{diff['salesforce_id']})" diff.keys.each do |k| next if diff[k] == org[k] puts " - #{k}" puts " - ZD: #{org[k]}" puts " - SFDC: #{diff[k]}" end end differences[:updates].push(global_org_update_object(diff, org)) end end print 'Determining organizations not in SFDC to tag...' if @verbose accounts_ids = @accounts.map { |a| a['salesforce_id'] } differences[:not_in_sfdc] = @organizations.reject { |o| accounts_ids.include?(o['salesforce_id']) || o['not_in_sfdc'] } puts 'done' if @verbose differences[:creates].compact! differences[:updates].compact! differences[:contacts].compact! global_report(differences) if @verbose differences end |
.compare_usgov_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk US Government organizations
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 361 def self.compare_usgov_organizations(redis_client, zendesk_client, salesforce_client, verbose = false) differences = { creates: [], updates: [], not_in_sfdc: [] } @redis_client = redis_client @zendesk_client = zendesk_client @salesforce_client = salesforce_client @verbose = verbose @accounts = determine_usgov_accounts @organizations = determine_usgov_organizations puts 'Determining differences...' if @verbose (comparable_accounts - usgov_comparable_orgs).each do |diff| org = @organizations.detect { |o| o['salesforce_id'] == diff['salesforce_id'] } if org.nil? unless diff['greatly_expired'] puts "- Need to create #{diff['name']} (#{diff['salesforce_id']})" if @verbose differences[:creates].push(usgov_org_creation_object(diff)) end else if @verbose puts "- Differences for #{diff['name']} (#{org['id']} / #{diff['salesforce_id']})" diff.keys.each do |k| next if diff[k] == org[k] puts " - #{k}" puts " - ZD: #{org[k]}" puts " - SFDC: #{diff[k]}" end end differences[:updates].push(usgov_org_update_object(diff, org)) end end print 'Determining organizations not in SFDC to tag...' if @verbose accounts_ids = @accounts.map { |a| a['salesforce_id'] } differences[:not_in_sfdc] = @organizations.reject { |o| accounts_ids.include?(o['salesforce_id']) || o['not_in_sfdc'] } puts 'done' if @verbose usgov_org_report(differences) if @verbose differences end |
.compare_usgov_users(redis_client, zendesk_client, salesforce_client, verbose = false) ⇒ Hash
Generate a comparison hash for Zendesk US Government users
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 447 def self.compare_usgov_users(redis_client, zendesk_client, salesforce_client, verbose = false) differences = { creates: [], updates: [], not_in_sfdc: [] } @redis_client = redis_client @zendesk_client = zendesk_client @salesforce_client = salesforce_client @verbose = verbose @organizations = determine_usgov_organizations @zd_users = determine_usgov_users @contacts = determine_usgov_contacts puts 'Determining differences...' if @verbose (@contacts - usgov_comparable_users).each do |diff| user = @zd_users.detect { |u| u['email'] == diff['email'] } if user.nil? puts "- Need to create #{diff['email']} (#{diff['name']})" if @verbose differences[:creates].push(usgov_user_creation_object(diff)) else if @verbose puts "- Differences for #{diff['email']} (#{user['id']})" diff.keys.each do |k| next if diff[k] == user[k] puts " - #{k}" puts " - ZD: #{user[k]}" puts " - SFDC: #{diff[k]}" end end differences[:updates].push(usgov_user_update_object(diff, user)) end end differences[:creates].compact! differences[:updates].compact! print 'Determining users not in SFDC to tag...' if @verbose emails = @contacts.map { |c| c['email'].downcase.strip } differences[:not_in_sfdc] = @zd_users.reject { |u| usgov_exclude_from_tagging(u, emails) } puts 'done' if @verbose usgov_user_report(differences) if @verbose differences end |
.create_global_contact?(org) ⇒ Boolean
Determines if a support contact should be created for Zendesk Global
218 219 220 221 222 223 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 218 def self.create_global_contact?(org) return false if org.organization_fields['account_type'].downcase =~ /_partner$/ return false if org.organization_fields['partner_customer'] true end |
.determine_global_accounts ⇒ Array
Gather SFDC Accounts for Zendesk Global
545 546 547 548 549 550 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 545 def self.determine_global_accounts print 'Gathering from Salesforce...' if @verbose accs = Readiness::Salesforce::Accounts.global_accounts(@salesforce_client) puts 'done' if @verbose accs end |
.determine_global_organizations ⇒ Array
Gather Zendesk Global organizations, either from Redis or Zendesk
584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 584 def self.determine_global_organizations print 'Gathering Organizations...' if @verbose orgs = Readiness::Redis.get(@redis_client, 'global_organizations') unless orgs.nil? puts 'received from Redis cache.' if @verbose return orgs end print 'needing to gather from Zendesk...' if @verbose orgs = Readiness::Zendesk::Organizations.list_many(@zendesk_client) puts 'done' if @verbose orgs.map { |o| global_zd_sync_object(o) } end |
.determine_usgov_accounts ⇒ Array
Gather SFDC Accounts for Zendesk US Government
558 559 560 561 562 563 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 558 def self.determine_usgov_accounts print 'Gathering from Salesforce...' if @verbose accs = Readiness::Salesforce::Accounts.usgov_accounts(@salesforce_client) puts 'done' if @verbose accs end |
.determine_usgov_contacts ⇒ Array
Gather SFDC Contacts for Zendesk US Government
571 572 573 574 575 576 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 571 def self.determine_usgov_contacts print 'Gathering from Salesforce...' if @verbose users = Readiness::Salesforce::Contacts.usgov_contacts(@salesforce_client) puts 'done' if @verbose users end |
.determine_usgov_organizations ⇒ Array
Gather Zendesk US Government organizations, either from Redis or Zendesk
603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 603 def self.determine_usgov_organizations print 'Gathering Organizations...' if @verbose orgs = Readiness::Redis.get(@redis_client, 'usgov_organizations') unless orgs.nil? puts 'received from Redis cache.' if @verbose return orgs end print 'needing to gather from Zendesk...' if @verbose orgs = Readiness::Zendesk::Organizations.list_many(@zendesk_client) puts 'done' if @verbose orgs.map { |o| usgov_zd_org_sync_object(o) } end |
.determine_usgov_users ⇒ Array
Gather Zendesk US Government users, either from Redis or Zendesk
622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 622 def self.determine_usgov_users print 'Gathering Users...' if @verbose users = Readiness::Redis.get(@redis_client, 'usgov_users') unless users.nil? puts 'received from Redis cache.' if @verbose return users end print 'needing to gather from Zendesk...' if @verbose users = Readiness::Zendesk::Users.list_many(@zendesk_client, 0, false, ['end-user']) puts 'done' if @verbose users.map { |u| usgov_zd_user_sync_object(u) }.compact end |
.global_comparable_org(org) ⇒ Hash
Create a comparable org object for Zendesk Global
688 689 690 691 692 693 694 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 688 def self.global_comparable_org(org) zd = org.dup zd.delete('id') zd['aar'] = zd['aar'].to_f zd['seats_decimal'] = zd['seats_decimal'].to_f zd end |
.global_comparable_orgs ⇒ Array
Modify Zendesk Global organizations into a comparable Array
654 655 656 657 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 654 def self.global_comparable_orgs new_orgs = Marshal.load(Marshal.dump(@organizations)) new_orgs.map { |zd| global_comparable_org(zd) } end |
.global_custom_fields_from_account(account) ⇒ Hash
Translate SFDC account information into the custom field s Hash for Zendesk Global information
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 985 def self.global_custom_fields_from_account(account) { 'aar' => account['aar'], 'account_owner' => account['account_owner'], 'account_type' => account['type'], 'expiration_date' => account['expiration_date'], 'greatly_expired' => account['greatly_expired'], 'health_score' => account['health_score'], 'not_in_sfdc' => account['not_in_sfdc'], 'org_in_escalated_state' => account['org_in_escalated_state'], 'org_region' => account['org_region'], 'partner_customer' => account['partner_customer'], 'restricted_account' => account['restricted_account'], 'salesforce_id' => account['salesforce_id'], 'sales_segmentation' => account['sales_segmentation'], 'seats_decimal' => account['seats_decimal'], 'sfdc_short_id' => account['sfdc_short_id'], 'solutions_architect' => account['solutions_architect'], 'sub_community_other' => account['sub_community_other'], 'sub_consumption_ai' => account['sub_consumption_ai'], 'sub_consumption_cicd_minutes' => account['sub_consumption_cicd_minutes'], 'sub_consumption_duo_enterprise' => account['sub_consumption_duo_enterprise'], 'sub_consumption_duo_premium' => account['sub_consumption_duo_premium'], 'sub_consumption_duo_amazon_q' => account['sub_consumption_duo_amazon_q'], 'sub_consumption_eap' => account['sub_consumption_eap'], 'sub_consumption_storage' => account['sub_consumption_storage'], 'sub_dotcom_premium' => account['sub_dotcom_premium'], 'sub_dotcom_ultimate' => account['sub_dotcom_ultimate'], 'sub_edu' => account['sub_edu'], 'sub_gitlab_dedicated' => account['sub_gitlab_dedicated'], 'sub_oss' => account['sub_oss'], 'sub_other' => account['sub_other'], 'sub_proserv' => account['sub_proserv'], 'sub_sm_premium' => account['sub_sm_premium'], 'sub_sm_starter' => account['sub_sm_starter'], 'sub_sm_ultimate' => account['sub_sm_ultimate'], 'sub_ss_ase' => account['sub_ss_ase'], 'sub_ss_growth' => account['sub_ss_growth'], 'sub_ss_enterprise' => account['sub_ss_enterprise'], 'sub_usgov_12x5' => account['sub_usgov_12x5'], 'sub_usgov_24x7' => account['sub_usgov_24x7'], 'support_hold' => account['support_hold'], 'support_level' => account['support_level'], 'technical_account_manager' => account['technical_account_manager'] } end |
.global_org_creation_object(account) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk Global creation purposes
889 890 891 892 893 894 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 889 def self.global_org_creation_object(account) org = Readiness::Zendesk::Organizations.new org.name = account['name'] org.organization_fields = global_custom_fields_from_account(account) org end |
.global_org_update_object(account, organization) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk Global update purposes
936 937 938 939 940 941 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 936 def self.global_org_update_object(account, organization) org = Readiness::Zendesk::Organizations.find!(@zendesk_client, organization['id']) org.name = account['name'] org.organization_fields = global_custom_fields_from_account(account) org end |
.global_report(differences) ⇒ Object
Print a comparison report for Zendesk Global
503 504 505 506 507 508 509 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 503 def self.global_report(differences) puts 'Comparison report:' puts "- Organization Creates: #{differences[:creates].count}" puts " - Contacts to create: #{differences[:contacts].count}" puts "- Organization Updates: #{differences[:updates].count}" puts "- Orgs Not in SFDC to tag: #{differences[:not_in_sfdc].count}" end |
.global_slack_message(org) ⇒ Object
1088 1089 1090 1091 1092 1093 1094 1095 1096 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 1088 def self.(org) <<~STRING :double-exclaimation: Attention Support Readiness! :double-exclaimation: 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. Please investigate this manually. If you are able to locate a contact to use for the created organization, please add/associate them manually. STRING end |
.global_sync(redis_client, zendesk_client, salesforce_client, slack_client) ⇒ Object
Perform a Zendesk-Salesforce Sync for Zendesk Global
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 143 def self.global_sync(redis_client, zendesk_client, salesforce_client, slack_client) print 'Determining differences...' differences = compare_global_organizations(redis_client, zendesk_client, salesforce_client) puts 'done' differences[:creates].each do |org| puts "Creating #{org.name}..." create = Readiness::Zendesk::Organizations.create!(zendesk_client, org) puts '- Organization created' if create_global_contact?(create) print '- Setting up contact for org...' contact = differences[:contacts].detect { |c| c['salesforce_id'] == org.organization_fields['salesforce_id'] } if contact.nil? Readiness::Slack::Messages.create!(slack_client, (create)) puts 'error' else search = Readiness::Zendesk::Search.users(zendesk_client, "email:#{contact['email']}") if search.count == 1 if search.first.organization_id.nil? user = search.first user.organization_id = create.id Readiness::Zendesk::Users.update!(zendesk_client, user) puts 'done' else Readiness::Slack::Messages.create!(slack_client, (create)) puts 'error' end elsif search.count.zero? user = Readiness::Zendesk::Users.new user.email = contact['email'] user.name = contact['name'] user.organization_id = create.id Readiness::Zendesk::Users.create!(zendesk_client, user) puts 'done' else Readiness::Slack::Messages.create!(slack_client, (create)) puts 'error' end end end @organizations.push(global_zd_sync_object(create)) end differences[:updates].each do |org| print "Updating #{org.name}..." update = Readiness::Zendesk::Organizations.update!(zendesk_client, org) puts 'done' index = @organizations.index { |o| o['id'] == update.id } @organizations[index] = global_zd_sync_object(update) unless index.nil? end differences[:not_in_sfdc].each do |diff| org = Readiness::Zendesk::Organizations.find!(zendesk_client, diff['id']) print "Marking #{org.name} as not being in SFDC" org.organization_fields['not_in_sfdc'] = true update = Readiness::Zendesk::Organizations.update!(zendesk_client, org) puts 'done' index = @organizations.index { |o| o['id'] == update.id } @organizations[index] = global_zd_sync_object(update) unless index.nil? end print 'Updating Redis cache...' Readiness::Redis.set(redis_client, 'global_organizations', @organizations) puts 'done' print 'Adding to Redis creation log...' current = Readiness::Redis.get(redis_client, 'global_org_creations_log') = Time.now.utc.strftime('%Y-%m-%dT%H:%MZ') current[] = differences[:creates].map { |c| c.organization_fields['salesforce_id'] } Readiness::Redis.set(redis_client, 'global_org_creations_log', current) puts 'done' end |
.global_zd_sync_object(org) ⇒ Hash
Generate a sync object from Zendesk Global information for comparison purposes
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 732 def self.global_zd_sync_object(org) { 'id' => org.id, 'name' => org.name, 'salesforce_id' => org.organization_fields['salesforce_id'], 'sfdc_short_id' => org.organization_fields['sfdc_short_id'], 'support_level' => org.organization_fields['support_level'], 'aar' => org.organization_fields['aar'], 'sales_segmentation' => org.organization_fields['sales_segmentation'], 'account_owner' => org.organization_fields['account_owner'], 'type' => org.organization_fields['account_type'], 'technical_account_manager' => org.organization_fields['technical_account_manager'], 'solutions_architect' => org.organization_fields['solutions_architect'], 'seats_decimal' => org.organization_fields['seats_decimal'], 'org_region' => org.organization_fields['org_region'], 'health_score' => org.organization_fields['health_score'], 'expiration_date' => org.organization_fields['expiration_date'], 'restricted_account' => org.organization_fields['restricted_account'], 'greatly_expired' => org.organization_fields['greatly_expired'], 'sub_consumption_ai' => org.organization_fields['sub_consumption_ai'], 'sub_consumption_cicd_minutes' => org.organization_fields['sub_consumption_cicd_minutes'], 'sub_consumption_duo_enterprise' => org.organization_fields['sub_consumption_duo_enterprise'], 'sub_consumption_duo_premium' => org.organization_fields['sub_consumption_duo_premium'], 'sub_consumption_duo_amazon_q' => org.organization_fields['sub_consumption_duo_amazon_q'], 'sub_consumption_eap' => org.organization_fields['sub_consumption_eap'], 'sub_consumption_storage' => org.organization_fields['sub_consumption_storage'], 'sub_proserv' => org.organization_fields['sub_proserv'], 'sub_dotcom_premium' => org.organization_fields['sub_dotcom_premium'], 'sub_dotcom_ultimate' => org.organization_fields['sub_dotcom_ultimate'], 'sub_sm_starter' => org.organization_fields['sub_sm_starter'], 'sub_sm_premium' => org.organization_fields['sub_sm_premium'], 'sub_sm_ultimate' => org.organization_fields['sub_sm_ultimate'], 'sub_usgov_12x5' => org.organization_fields['sub_usgov_12x5'], 'sub_usgov_24x7' => org.organization_fields['sub_usgov_24x7'], 'sub_gitlab_dedicated' => org.organization_fields['sub_gitlab_dedicated'], 'sub_edu' => org.organization_fields['sub_edu'], 'sub_oss' => org.organization_fields['sub_oss'], 'sub_community_other' => org.organization_fields['sub_community_other'], 'sub_ss_ase' => org.organization_fields['sub_ss_ase'], 'sub_ss_growth' => org.organization_fields['sub_ss_growth'], 'sub_ss_enterprise' => org.organization_fields['sub_ss_enterprise'], 'sub_other' => org.organization_fields['sub_other'], 'partner_customer' => org.organization_fields['partner_customer'], 'not_in_sfdc' => org.organization_fields['not_in_sfdc'], 'support_hold' => org.organization_fields['support_hold'], 'org_in_escalated_state' => org.organization_fields['org_in_escalated_state'] } end |
.locate_org_from_user(user) ⇒ Object
Locate a Zendesk organization either via the Redis values or from Zendesk
873 874 875 876 877 878 879 880 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 873 def self.locate_org_from_user(user) return nil if user.organization_id.nil? detect = @organizations.detect { |o| o['id'] == user.organization_id } return detect unless detect.nil? Readiness::Zendesk::Organizations.find!(@zendesk_client, user.organization_id) end |
.sfdc_links(sfdc_id) ⇒ Object
1084 1085 1086 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 1084 def self.sfdc_links(sfdc_id) "<https://gitlab.lightning.force.com/lightning/r/Account/#{sfdc_id}/view|#{sfdc_id}>" end |
.usgov_comparable_org(org) ⇒ Hash
Create a comparable org object for Zendesk US Government
703 704 705 706 707 708 709 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 703 def self.usgov_comparable_org(org) zd = org.dup zd.delete('id') zd['arr'] = zd['arr'].to_f zd['number_of_seats'] = zd['number_of_seats'].to_f zd end |
.usgov_comparable_orgs ⇒ Array
Modify Zendesk US Government organizations into a comparable Array
665 666 667 668 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 665 def self.usgov_comparable_orgs new_orgs = Marshal.load(Marshal.dump(@organizations)) new_orgs.map { |zd| usgov_comparable_org(zd) } end |
.usgov_comparable_user(user) ⇒ Hash
Create a comparable user object for Zendesk US Government
718 719 720 721 722 723 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 718 def self.usgov_comparable_user(user) zd = user.dup zd.delete('id') zd.delete('org_id') zd end |
.usgov_comparable_users ⇒ Array
Modify Zendesk US Government users into a comparable Array
676 677 678 679 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 676 def self.usgov_comparable_users new_users = Marshal.load(Marshal.dump(@zd_users)) new_users.map { |zd| usgov_comparable_user(zd) } end |
.usgov_custom_fields_from_account(account) ⇒ Hash
Translate SFDC account information into the custom field s Hash for Zendesk Global information
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 1039 def self.usgov_custom_fields_from_account(account) { 'arr' => account['arr'], 'account_owner' => account['account_owner'], 'account_type' => account['type'], 'emergency_support_24x7' => account['emergency_support_24x7'], 'expiration_date' => account['expiration_date'], 'greatly_expired' => account['greatly_expired'], 'health_score' => account['health_score'], 'market_segment' => account['market_segment'], 'not_in_sfdc' => account['not_in_sfdc'], 'restricted_account' => account['restricted_account'], 'salesforce_id' => account['salesforce_id'], 'sales_segmentation' => account['sales_segmentation'], 'number_of_seats' => account['number_of_seats'].to_i, 'sfdc_short_id' => account['sfdc_short_id'], 'solutions_architect' => account['solutions_architect'], 'sub_community_other' => account['sub_community_other'], 'sub_consumption_ai' => account['sub_consumption_ai'], 'sub_consumption_cicd_minutes' => account['sub_consumption_cicd_minutes'], 'sub_consumption_duo_enterprise' => account['sub_consumption_duo_enterprise'], 'sub_consumption_duo_premium' => account['sub_consumption_duo_premium'], 'sub_consumption_duo_amazon_q' => account['sub_consumption_duo_amazon_q'], 'sub_consumption_eap' => account['sub_consumption_eap'], 'sub_consumption_storage' => account['sub_consumption_storage'], 'sub_dotcom_premium' => account['sub_dotcom_premium'], 'sub_dotcom_ultimate' => account['sub_dotcom_ultimate'], 'sub_edu' => account['sub_edu'], 'sub_gitlab_dedicated' => account['sub_gitlab_dedicated'], 'sub_oss' => account['sub_oss'], 'sub_other' => account['sub_other'], 'sub_proserv' => account['sub_proserv'], 'sub_sm_premium' => account['sub_sm_premium'], 'sub_sm_starter' => account['sub_sm_starter'], 'sub_sm_ultimate' => account['sub_sm_ultimate'], 'sub_ss_ase' => account['sub_ss_ase'], 'sub_usgov_12x5' => account['sub_usgov_12x5'], 'sub_usgov_24x7' => account['sub_usgov_24x7'], 'support_hold' => account['support_hold'], 'support_level' => account['support_level'], 'technical_account_manager' => account['technical_account_manager'], 'date_marked_not_in_sfdc' => account['date_marked_not_in_sfdc'] } end |
.usgov_exclude_from_tagging(user, emails) ⇒ Object
490 491 492 493 494 495 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 490 def self.usgov_exclude_from_tagging(user, emails) return true if emails.include? user['email'] return true if user['not_in_sfdc'] false end |
.usgov_org_creation_object(account) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk US Government creation purposes
903 904 905 906 907 908 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 903 def self.usgov_org_creation_object(account) org = Readiness::Zendesk::Organizations.new org.name = account['name'] org.organization_fields = usgov_custom_fields_from_account(account) org end |
.usgov_org_report(differences) ⇒ Object
Print a organization comparison report for Zendesk US Government
517 518 519 520 521 522 523 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 517 def self.usgov_org_report(differences) puts 'Comparison report:' puts '- Organizations' puts " - Creates: #{differences[:creates].count}" puts " - Updates: #{differences[:updates].count}" puts " - Not in SFDC to tag: #{differences[:not_in_sfdc].count}" end |
.usgov_org_sync(redis_client, zendesk_client, salesforce_client) ⇒ Object
Perform a Zendesk-Salesforce Sync for Zendesk US Government
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 72 def self.usgov_org_sync(redis_client, zendesk_client, salesforce_client) print 'Determining differences...' differences = compare_usgov_organizations(redis_client, zendesk_client, salesforce_client) puts 'done' differences[:creates].each do |org| puts "Creating #{org.name}..." create = Readiness::Zendesk::Organizations.create!(zendesk_client, org) puts '- Organization created' @organizations.push(usgov_zd_org_sync_object(create)) end differences[:updates].each do |org| print "Updating #{org.name}..." update = Readiness::Zendesk::Organizations.update!(zendesk_client, org) puts 'done' index = @organizations.index { |o| o['id'] == update.id } @organizations[index] = usgov_zd_org_sync_object(update) unless index.nil? end differences[:not_in_sfdc].each do |diff| org = Readiness::Zendesk::Organizations.find!(zendesk_client, diff['id']) print "Marking #{org.name} as not being in SFDC..." org.organization_fields['not_in_sfdc'] = true org.organization_fields['date_marked_not_in_sfdc'] = Date.today.iso8601 update = Readiness::Zendesk::Organizations.update!(zendesk_client, org) puts 'done' index = @organizations.index { |o| o['id'] == update.id } @organizations[index] = usgov_zd_org_sync_object(update) unless index.nil? end print 'Updating Redis cache...' Readiness::Redis.set(redis_client, 'usgov_organizations', @organizations) puts 'done' print 'Adding to Redis creation log...' current = Readiness::Redis.get(redis_client, 'usgov_org_creations_log') = Time.now.utc.strftime('%Y-%m-%dT%H:%MZ') current[] = differences[:creates].map { |c| c.organization_fields['salesforce_id'] } Readiness::Redis.set(redis_client, 'usgov_org_creations_log', current) puts 'done' end |
.usgov_org_update_object(account, organization) ⇒ Object
Create an instance of Zendesk::Organizations for Zendesk US Government update purposes
951 952 953 954 955 956 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 951 def self.usgov_org_update_object(account, organization) org = Readiness::Zendesk::Organizations.find!(@zendesk_client, organization['id']) org.name = account['name'] org.organization_fields = usgov_custom_fields_from_account(account) org end |
.usgov_user_creation_object(contact) ⇒ Object
Create an instance of Zendesk::Users for Zendesk US Government creation purposes
917 918 919 920 921 922 923 924 925 926 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 917 def self.usgov_user_creation_object(contact) org = @organizations.detect { |o| o['salesforce_id'] == contact['salesforce_id'] } return nil if org.nil? user = Readiness::Zendesk::Users.new user.email = contact['email'] user.name = contact['name'] user.organization_id = org['id'] user end |
.usgov_user_report(differences) ⇒ Object
Print an user comparison report for Zendesk US Government
531 532 533 534 535 536 537 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 531 def self.usgov_user_report(differences) puts 'Comparison report:' puts '- Users' puts " - Creates: #{differences[:creates].count}" puts " - Updates: #{differences[:updates].count}" puts " - Not in SFDC to tag: #{differences[:not_in_sfdc].count}" end |
.usgov_user_sync(redis_client, zendesk_client, salesforce_client) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 13 def self.usgov_user_sync(redis_client, zendesk_client, salesforce_client) print 'Determining differences...' differences = compare_usgov_users(redis_client, zendesk_client, salesforce_client, false) puts 'done' differences[:creates].each do |user| print "Creating #{user.email}..." create = Readiness::Zendesk::Users.create_or_update!(zendesk_client, user) puts 'done' @zd_users.push(usgov_zd_user_sync_object(create)) end differences[:updates].each do |user| print "Updating #{user.email}..." update = Readiness::Zendesk::Users.update!(zendesk_client, user) puts 'done' index = @zd_users.index { |u| u['id'] == update.id } @zd_users[index] = usgov_zd_user_sync_object(update) unless index.nil? end differences[:not_in_sfdc].each do |diff| user = Readiness::Zendesk::Users.find!(zendesk_client, diff['id']) print "Marking #{user.email} as not being in SFDC..." user.user_fields['not_in_sfdc'] = true update = Readiness::Zendesk::Users.update!(zendesk_client, user) puts 'done' index = @zd_users.index { |u| u['id'] == update.id } @zd_users[index] = usgov_zd_user_sync_object(update) unless index.nil? end print 'Updating Redis cache...' Readiness::Redis.set(redis_client, 'usgov_users', @zd_users) puts 'done' end |
.usgov_user_update_object(contact, zd_user) ⇒ Object
Create an instance of Zendesk::Users for Zendesk US Government update purposes
966 967 968 969 970 971 972 973 974 975 976 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 966 def self.usgov_user_update_object(contact, zd_user) user = Readiness::Zendesk::Users.find!(@zendesk_client, zd_user['id']) org = @organizations.detect { |o| o['salesforce_id'] == contact['salesforce_id'] } return nil if org.nil? user.email = contact['email'] user.name = contact['name'] user.organization_id = org['id'] user.user_fields['not_in_sfdc'] = contact['not_in_sfdc'] user end |
.usgov_zd_org_sync_object(org) ⇒ Hash
Generate a sync object from Zendesk US Government organization information for comparison purposes
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 788 def self.usgov_zd_org_sync_object(org) { 'id' => org.id, 'name' => org.name, 'salesforce_id' => org.organization_fields['salesforce_id'], 'sfdc_short_id' => org.organization_fields['sfdc_short_id'], 'support_level' => org.organization_fields['support_level'], 'arr' => org.organization_fields['arr'], 'market_segment' => org.organization_fields['market_segment'], 'account_owner' => org.organization_fields['account_owner'], 'type' => org.organization_fields['account_type'], 'technical_account_manager' => org.organization_fields['technical_account_manager'], 'solutions_architect' => org.organization_fields['solutions_architect'], 'number_of_seats' => org.organization_fields['number_of_seats'], 'health_score' => org.organization_fields['health_score'], 'expiration_date' => org.organization_fields['expiration_date'], 'restricted_account' => org.organization_fields['restricted_account'], 'greatly_expired' => org.organization_fields['greatly_expired'], 'emergency_support_24x7' => org.organization_fields['emergency_support_24x7'], 'sub_consumption_ai' => org.organization_fields['sub_consumption_ai'], 'sub_consumption_cicd_minutes' => org.organization_fields['sub_consumption_cicd_minutes'], 'sub_consumption_duo_enterprise' => org.organization_fields['sub_consumption_duo_enterprise'], 'sub_consumption_duo_premium' => org.organization_fields['sub_consumption_duo_premium'], 'sub_consumption_duo_amazon_q' => org.organization_fields['sub_consumption_duo_amazon_q'], 'sub_consumption_eap' => org.organization_fields['sub_consumption_eap'], 'sub_consumption_storage' => org.organization_fields['sub_consumption_storage'], 'sub_proserv' => org.organization_fields['sub_proserv'], 'sub_dotcom_premium' => org.organization_fields['sub_dotcom_premium'], 'sub_dotcom_ultimate' => org.organization_fields['sub_dotcom_ultimate'], 'sub_sm_starter' => org.organization_fields['sub_sm_starter'], 'sub_sm_premium' => org.organization_fields['sub_sm_premium'], 'sub_sm_ultimate' => org.organization_fields['sub_sm_ultimate'], 'sub_usgov_12x5' => org.organization_fields['sub_usgov_12x5'], 'sub_usgov_24x7' => org.organization_fields['sub_usgov_24x7'], 'sub_gitlab_dedicated' => org.organization_fields['sub_gitlab_dedicated'], 'sub_edu' => org.organization_fields['sub_edu'], 'sub_oss' => org.organization_fields['sub_oss'], 'sub_community_other' => org.organization_fields['sub_community_other'], 'sub_ss_ase' => org.organization_fields['sub_ss_ase'], 'sub_other' => org.organization_fields['sub_other'], 'not_in_sfdc' => org.organization_fields['not_in_sfdc'], 'support_hold' => org.organization_fields['support_hold'], 'date_marked_not_in_sfdc' => org.organization_fields['date_marked_not_in_sfdc'], } end |
.usgov_zd_user_sync_object(user) ⇒ Hash
Generate a sync object from Zendesk US Government user information for comparison purposes
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
# File 'lib/support_readiness/repos/zendesk_salesforce_sync.rb', line 841 def self.usgov_zd_user_sync_object(user) return nil if user.email =~ /gitlab.com$/ org = locate_org_from_user(user) if org.nil? return { "id" => user.id, "name" => user.name, "email" => user.email, "org" => nil, "org_id" => nil, "salesforce_id" => nil, "not_in_sfdc" => user.user_fields['not_in_sfdc'] } end { "id" => user.id, "name" => user.name, "email" => user.email, "org" => (org.is_a?(Hash) ? org['name'] : org.name), "org_id" => user.organization_id, "salesforce_id" => (org.is_a?(Hash) ? org['salesforce_id'] : org.organization_fields['salesforce_id']), "not_in_sfdc" => user.user_fields['not_in_sfdc'] } end |