Class: MassSearch::OutgoingPaymentApproveCheckWorker

Inherits:
Object
  • Object
show all
Includes:
MassSearchWorker
Defined in:
app/workers/mass_search/outgoing_payment_approve_check_worker.rb

Overview

Approves each selected OutgoingPayment check and sends a notification email.
Requires current user to have :approve_check permission on OutgoingPayment.

Instance Method Summary collapse

Instance Method Details

#build_enumerator(args, cursor:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/workers/mass_search/outgoing_payment_approve_check_worker.rb', line 8

def build_enumerator(args, cursor:)
  super
  unless @user&.&.can?(:approve_check, OutgoingPayment)
    @unauthorised = true
    return active_record_records_enumerator(@search.search_results.none, cursor: cursor)
  end

  @approved_payments = []
  active_record_records_enumerator(@search.search_results, cursor: cursor)
end

#on_completeObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/mass_search/outgoing_payment_approve_check_worker.rb', line 19

def on_complete
  if @unauthorised
    store error_message: "You don't have permission to approve checks.",
          redirect_to:   UrlHelper.instance.accounts_payable_dashboard_path
    return
  end

  checks = (@approved_payments || []).select { |p| p.category == 'check' }
  InternalMailer.checks_approved_notification(checks).deliver_later if checks.any?

  super
end