Class: ForestAdminDatasourceZendesk::Plugins::CloseTicket

Inherits:
ForestAdminDatasourceCustomizer::Plugins::Plugin
  • Object
show all
Defined in:
lib/forest_admin_datasource_zendesk/plugins/close_ticket.rb,
lib/forest_admin_datasource_zendesk/plugins/close_ticket/errors.rb,
lib/forest_admin_datasource_zendesk/plugins/close_ticket/messages.rb

Overview

The Zendesk ticket id is read from a configurable column on the host record(s); Zendesk sometimes rejects the direct ‘open -> closed` transition so failures are surfaced per-id rather than retried.

Defined Under Namespace

Modules: Errors, Messages

Constant Summary collapse

BaseAction =
ForestAdminDatasourceCustomizer::Decorators::Action::BaseAction
ActionScope =
ForestAdminDatasourceCustomizer::Decorators::Action::Types::ActionScope
ForestException =
ForestAdminDatasourceToolkit::Exceptions::ForestException
STATUSES =
%w[solved closed].freeze
SCOPE_KEYS =
%i[single bulk].freeze
NAMES =
{
  'solved' => { single: 'Mark Zendesk ticket as solved',
                bulk: 'Mark selected Zendesk tickets as solved' }.freeze,
  'closed' => { single: 'Mark Zendesk ticket as closed',
                bulk: 'Mark selected Zendesk tickets as closed' }.freeze
}.freeze
SCOPES =
{ single: ActionScope::SINGLE, bulk: ActionScope::BULK }.freeze

Instance Method Summary collapse

Instance Method Details

#run(_datasource_customizer, collection_customizer = nil, options = {}) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/forest_admin_datasource_zendesk/plugins/close_ticket.rb', line 23

def run(_datasource_customizer, collection_customizer = nil, options = {})
  datasource = options[:datasource]
  ticket_id_field = options[:ticket_id_field]
  raise ForestException, 'CloseTicket plugin requires :datasource' unless datasource
  raise ForestException, 'CloseTicket plugin requires :ticket_id_field' unless ticket_id_field
  raise ForestException, 'CloseTicket plugin requires a collection' unless collection_customizer

  statuses = normalize_statuses(options[:statuses])
  scopes   = normalize_scopes(options[:scopes])

  variants(statuses, scopes).each do |name, status, scope|
    collection_customizer.add_action(name, build_action(datasource, status, scope, ticket_id_field))
  end
end