Class: AccountInvitedHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- AccountInvitedHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/account_invited_handler.rb
Overview
Handles Events::AccountInvited: sends the Devise invitation email off the
request path (published by Account::Inviter after an online-account invite).
deliver_invitation regenerates the raw invitation token in-process — only
the token's digest is persisted by invite!, so the raw value doesn't survive
the async boundary; regenerating here (and saving the fresh digest) keeps the
emailed accept link valid. Also stamps invitation_sent_at.
Runs asynchronously via ActiveJob so mail delivery doesn't block the invite
request (e.g. Www::LeadsController#create → the public lead form).
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/subscribers/account_invited_handler.rb', line 18 def perform(event) account = Account.find_by(id: event.data[:account_id]) return unless account # invited account destroyed between publish and perform → no-op # Idempotency across Sidekiq retries: deliver_invitation regenerates the raw # token and resends on every run, so a retry after a successful send would # invalidate the first email's accept link and deliver a duplicate. # `invitation_sent_at` is Devise's durable marker that delivery already # happened (also covers already-accepted invites) — skip if it's set. return if account.invitation_sent_at? account.deliver_invitation end |