Class: Readiness::SupportSuperFormProcessor::GlobalSetOrgASE

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/support_super_form_processor/global_set_org_ase.rb

Overview

Defines the class GlobalSetOrgASE within the module Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.42

Class Method Summary collapse

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

.agentObject

Sets the global variable agent

Author:

  • Jason Colyer

Since:

  • 1.0.42



185
186
187
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 185

def self.agent
  @agent ||= Readiness::Zendesk::Users.find(@zendesk_client, agent_id)
end

.agent_idObject

Sets the global variable agent_id

Author:

  • Jason Colyer

Since:

  • 1.0.42



194
195
196
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 194

def self.agent_id
  @agent_id ||= ENV.fetch('ZENDESK_AGENT_ID')
end

.agent_infoObject

Returns the value to set the organization field to

Author:

  • Jason Colyer

Since:

  • 1.0.42



120
121
122
123
124
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 120

def self.agent_info
  return '' if agent_id == 'None'

  agent.id.to_s
end

.agent_valid?Boolean

Determines if the agent to use is valid

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.42



105
106
107
108
109
110
111
112
113
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 105

def self.agent_valid?
  return true if agent_id == 'None'
  return false if agent.is_a? Hash
  return false if agent.role == 'end-user'
  return false if agent.suspended
  return false if [360004984553, 12510471332508].include? agent.custom_role_id

  true
end

.approved_requester?Boolean

Determines if the requester is authorized to make the request

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.42



73
74
75
76
77
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 73

def self.approved_requester?
  return true if approved_requester_list.map { |t| t['email'] }.include? requester_email

  false
end

.approved_requester_listObject

Sets the global variable approved_requester_list

Author:

  • Jason Colyer

Since:

  • 1.0.42



84
85
86
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 84

def self.approved_requester_list
  @approved_requester_list ||= determine_approved_requesters
end

.bad_requesterObject

Since:

  • 1.0.42



41
42
43
44
45
46
47
48
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 41

def self.bad_requester
  issue = Readiness::GitLab::Issues.new
  issue.title = 'Invalid Request - Not approved to make this request'
  issue.description = bad_requester_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.bad_requester_messageObject

Since:

  • 1.0.42



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 248

def self.bad_requester_message
  <<~STRING
    ## Invalid Request - Not approved to make this request

    Greetings @#{requester.username} !

    We received a request from you recently to set an ASE on a Zendesk Global organization, however this type of request can only be made by specifc approved persons.

    Please contact one fo the following via [#support_leadership](https://gitlab.enterprise.slack.com/archives/C01F9S37AKT) to discuss this request:

    #{approved_requester_list.map { |a| "- #{a['email']}" }.join("\n")}

    /label ~"AutomatedRequests::Invalid Permissions" ~"Stage::Blocked" ~administrative ~p4 ~zendesk ~"Customer::Support"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username}
  STRING
end

.determine_approved_requestersObject

Determines the list of approved requesters

Author:

  • Jason Colyer

Since:

  • 1.0.42



93
94
95
96
97
98
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 93

def self.determine_approved_requesters
  members = []
  members += team.select { |t| t['title'] =~ /Director/ }
  members += team.select { |t| t['title'] =~ /Manager/ }
  members
end

.invalid_agentObject

Since:

  • 1.0.42



59
60
61
62
63
64
65
66
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 59

def self.invalid_agent
  issue = Readiness::GitLab::Issues.new
  issue.title = 'Invalid Request - Invalid agent provided'
  issue.description = invalid_user_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.invalid_user_messageObject

Returns the issue description for an invalid user

Author:

  • Jason Colyer

Since:

  • 1.0.42



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 273

def self.invalid_user_message
  <<~STRING
    ## Set an Assigned Support Engineer for a Zendesk Global organization - #{org.id}

    Greetings @#{requester.username} !

    We were unable to set the ASE on the Zendesk Global organization at this time, as we were encountered one of the following issues with the Zendesk Global agent with the ID of #{agent_id}:

    - The agent does not exist
    - The agent does not have write permissions on tickets
    - The agent is suspended
    - The agent is an end-user

    Please review the Zendesk agent you were wanting to use once more and file a new submission.

    If you need assistance in locating the agent's ID, please ask in the Slack channel [#support_operations](https://gitlab.slack.com/archives/C018ZGZAMPD)

    /label ~"AutomatedRequests::Set Org ASE" ~"Stage::Blocked" ~administrative ~p4 ~zendesk ~"Customer::Support"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username}
  STRING
end

.messageObject

Returns the issue description

Author:

  • Jason Colyer

Since:

  • 1.0.42



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 203

def self.message
  <<~STRING
    ## Set an Assigned Support Engineer for a Zendesk Global organization - #{org.id}

    Greetings @#{requester.username} !

    We have set the Assigned Support Engineer of the Zendesk Global organization to that of #{agent_id} at this time.

    If that is not the ID of the agent you were intending to use, please review the Zendesk agent you were wanting to use once more and file a new submission.

    If you need assistance in locating the agent's ID, please ask in the Slack channel [#support_operations](https://gitlab.slack.com/archives/C018ZGZAMPD)

    /label ~"AutomatedRequests::Set Org ASE" ~"Stage::Completed" ~administrative ~p4 ~zendesk ~"Customer::Support"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username}
  STRING
end

.orgObject

Sets the global variable org

Author:

  • Jason Colyer

Since:

  • 1.0.42



167
168
169
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 167

def self.org
  @org ||= Readiness::Zendesk::Organizations.find(@zendesk_client, org_id)
end

.org_does_not_existObject

Since:

  • 1.0.42



50
51
52
53
54
55
56
57
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 50

def self.org_does_not_exist
  issue = Readiness::GitLab::Issues.new
  issue.title = 'Invalid Request - Organization Not Found'
  issue.description = org_does_not_exist_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.org_does_not_exist_messageObject

Returns the issue description

Author:

  • Jason Colyer

Since:

  • 1.0.42



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 228

def self.org_does_not_exist_message
  <<~STRING
    ## Invalid Request Organization Not Found

    Greetings @#{requester.username} !

    We received a request from you recently, however the organization ID given #{org_id} is not a valid Zendesk Global Organization ID. As such, we are not able to proceed.

    Please review the Zendesk Global organization you were wanting to use once more and file a new submission.

    If you need assistance in locating the organization's ID, please ask in the Slack channel [#support_operations](https://gitlab.slack.com/archives/C018ZGZAMPD)

    /label ~"AutomatedRequests::Invalid Organization" ~"Stage::Blocked" ~administrative ~p4 ~zendesk ~"Customer::Support"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username}
  STRING
end

.org_idObject

Sets the global variable org_id

Author:

  • Jason Colyer

Since:

  • 1.0.42



176
177
178
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 176

def self.org_id
  @org_id ||= ENV.fetch('ORG_ID')
end

.process!(gitlab_client, gitlab_admin_client, zendesk_client, redis_client) ⇒ Object

Process setting an ASE on a Global organization

Author:

  • Jason Colyer

Since:

  • 1.0.42



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 18

def self.process!(gitlab_client, gitlab_admin_client, zendesk_client, redis_client)
  @gitlab_client = gitlab_client
  @gitlab_admin_client = gitlab_admin_client
  @zendesk_client = zendesk_client
  @redis_client = redis_client
  requester
  bad_requester unless approved_requester?
  org_does_not_exist if org.is_a? Hash
  invalid_agent unless agent_valid?
  new_org = Readiness::Zendesk::Organizations.new
  new_org.id = org.id
  new_org.organization_fields = {
    "assigned_se" => agent_info
  }
  Readiness::Zendesk::Organizations.update!(@zendesk_client, new_org)
  issue = Readiness::GitLab::Issues.new
  issue.title = "Set an Assigned Support Engineer for a Zendesk Global organization - #{org.id}"
  issue.description = message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.projectObject

Sets the global variable project

Author:

  • Jason Colyer

Since:

  • 1.0.42



158
159
160
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 158

def self.project
  @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 68534119)
end

.requesterObject

Sets the global variable requester

Author:

  • Jason Colyer

Since:

  • 1.0.42



140
141
142
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 140

def self.requester
  @requester ||= Readiness::SupportSuperFormProcessor::Shared.gitlab_user_check(@gitlab_admin_client, requester_email)
end

.requester_emailObject

Sets the global variable requester_email

Author:

  • Jason Colyer

Since:

  • 1.0.42



149
150
151
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 149

def self.requester_email
  @requester_email ||= ENV.fetch('REQUESTER_EMAIL')
end

.teamObject

Sets the global variable team

Author:

  • Jason Colyer

Since:

  • 1.0.42



131
132
133
# File 'lib/support_readiness/support_super_form_processor/global_set_org_ase.rb', line 131

def self.team
  @team ||= Readiness::Redis.get(@redis_client, 'support_team')
end