Class: PhoneQueueOrderChange

Inherits:
ApplicationRecord show all
Defined in:
app/models/phone_queue_order_change.rb

Overview

Audit record: one phone-queue ring-order change.

Written by EmployeePhoneStatusesController#update_queue_order (manual drag
on the switchboard, +source+ 'manual', +employee+ set), by
RotatePhoneQueuesWorker (weekly rotation, +source+ 'worker'), and by
PullPhoneQueueStatusWorker's drift check (order changed directly in
Switchvox, +source+ 'external-switchvox'). +previous_order+ / +new_order+
hold the Switchvox member account ids in ring order before and after the
change. Append-only — this IS the audit trail, so no Models::Auditable here.

Constant Summary collapse

SOURCES =

Allowed sources for an order change.

%w[manual worker external-switchvox].freeze

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#queue_account_idString

Returns Switchvox queue account id.

Returns:

  • (String)

    Switchvox queue account id.



21
# File 'app/models/phone_queue_order_change.rb', line 21

validates :queue_account_id, presence: true, inclusion: { in: PhoneQueue::REGISTRY.keys }

#sourceString

Returns How the change originated.

Returns:

  • (String)

    How the change originated.



24
# File 'app/models/phone_queue_order_change.rb', line 24

validates :source, presence: true, inclusion: { in: SOURCES }

Instance Method Details

#actor_nameString

Returns who or what made the change, for display.

Returns:

  • (String)

    who or what made the change, for display



50
51
52
53
54
55
56
57
58
# File 'app/models/phone_queue_order_change.rb', line 50

def actor_name
  if worker?
    'Weekly rotation'
  elsif external?
    'Switchvox (direct edit)'
  else
    employee&.full_name.to_s
  end
end

#employeeEmployee

Returns:

Validations (if => -> { source == 'manual' } ):



17
# File 'app/models/phone_queue_order_change.rb', line 17

belongs_to :employee, optional: true

#external?Boolean

Returns true when the order was changed directly in Switchvox
(detected by PullPhoneQueueStatusWorker's drift check).

Returns:

  • (Boolean)

    true when the order was changed directly in Switchvox
    (detected by PullPhoneQueueStatusWorker's drift check)



34
35
36
# File 'app/models/phone_queue_order_change.rb', line 34

def external?
  source == 'external-switchvox'
end

#source_labelString

Returns short badge label for the change source.

Returns:

  • (String)

    short badge label for the change source



39
40
41
42
43
44
45
46
47
# File 'app/models/phone_queue_order_change.rb', line 39

def source_label
  if worker?
    'auto'
  elsif external?
    'external'
  else
    'manual'
  end
end

#worker?Boolean

Returns true when the weekly rotation worker made the change.

Returns:

  • (Boolean)

    true when the weekly rotation worker made the change



28
29
30
# File 'app/models/phone_queue_order_change.rb', line 28

def worker?
  source == 'worker'
end