Module: ContactDeactivationAndDefaults

Extended by:
ActiveSupport::Concern
Included in:
Contact
Defined in:
app/models/concerns/contact_deactivation_and_defaults.rb

Overview

Contact lifecycle: safe delete checks, reactivation, deactivation via ContactDeactivator,
support-case guards, and before_add defaults for opportunities and orders.

Instance Method Summary collapse

Instance Method Details

#deactivatevoid

This method returns an undefined value.

Deactivates through ContactDeactivator (CRM rules, nulling associations, etc.).



31
32
33
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 31

def deactivate
  ContactDeactivator.call(self)
end

#ok_to_delete?Boolean

Returns true when the contact has no blocking dependents and is not on a support case.

Returns:

  • (Boolean)

    true when the contact has no blocking dependents and is not on a support case



13
14
15
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 13

def ok_to_delete?
  dependents.blank? && !support_case_participant?
end

#open_support_case_participant?Boolean

Returns true when on at least one non-closed support case.

Returns:

  • (Boolean)

    true when on at least one non-closed support case



42
43
44
45
46
47
48
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 42

def open_support_case_participant?
  SupportCaseParticipant
    .joins(:support_case)
    .where(party_id: id)
    .where.not(support_cases: { state: 'closed' })
    .exists?
end

#reactivateBoolean

rubocop:disable Naming/PredicateMethod -- command method; boolean encodes success
Clears inactive when currently inactive.

Returns:

  • (Boolean)

    true on success, false when not inactive



21
22
23
24
25
26
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 21

def reactivate
  return false unless inactive

  update!(inactive: false)
  true
end

#set_default_for_opportunity(new_opp) ⇒ Opportunity

rubocop:disable Naming/AccessorMethodName -- Rails association before_add callback name
before_add hook: copies customer defaults onto a new opportunity.

Parameters:

Returns:

  • (Opportunity)

    the same instance (for the callback chain)



55
56
57
58
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 55

def set_default_for_opportunity(new_opp)
  assign_opportunity_defaults_from_customer(new_opp)
  new_opp
end

#set_default_for_order(new_order) ⇒ void

This method returns an undefined value.

before_add hook: applies customer/contact defaults to a new order.

Parameters:



64
65
66
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 64

def set_default_for_order(new_order)
  OrderCustomerDefaultsApplier.call(order: new_order, customer: customer, contact: self)
end

#support_case_participant?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/concerns/contact_deactivation_and_defaults.rb', line 37

def support_case_participant?
  SupportCaseParticipant.exists?(party_id: id)
end