Module: PartyAccount
- Extended by:
- ActiveSupport::Concern
- Included in:
- Party
- Defined in:
- app/models/concerns/party_account.rb
Overview
Online account lifecycle for Party: CanCan ability, guarded build_account /
create_account (prevents silent replacement), invitations, and email-based party lookup.
Class Method Summary collapse
-
.search_for_authenticable_linked_party_by_email(email_input) ⇒ Party?
Finds a party that can authenticate via the given email (CRM login resolution).
Instance Method Summary collapse
-
#ability ⇒ Ability
Memoized CanCan ability for this party (used by
delegate :can?on Party). -
#build_account(attributes = nil) ⇒ Account
Builds a new Account but refuses if one already exists (prevents silent replacement).
-
#create_account(attributes = nil) ⇒ Account
Creates a new Account but refuses if one already exists (prevents silent replacement).
-
#online_account_invite(specific_email = nil, ignore_if_exist: true, return_path: nil) ⇒ Array
Sends (or refreshes) an online account invitation via Account::Inviter.
-
#refuse_silent_account_replacement!(caller_name) ⇒ void
Raises when an account already exists so callers cannot silently replace it.
Class Method Details
.search_for_authenticable_linked_party_by_email(email_input) ⇒ Party?
Finds a party that can authenticate via the given email (CRM login resolution).
83 84 85 |
# File 'app/models/concerns/party_account.rb', line 83 def search_for_authenticable_linked_party_by_email(email_input) PartyAuthenticableLinkedPartyFinder.call(email_input) end |
Instance Method Details
#ability ⇒ Ability
Memoized CanCan ability for this party (used by delegate :can? on Party).
15 16 17 |
# File 'app/models/concerns/party_account.rb', line 15 def ability @ability ||= Ability.new(self) end |
#build_account(attributes = nil) ⇒ Account
Builds a new Account but refuses if one already exists (prevents silent replacement).
The default has_one autosave would delete the previous row; see ticket BC-498301955.
26 27 28 29 |
# File 'app/models/concerns/party_account.rb', line 26 def build_account(attributes = nil, &) refuse_silent_account_replacement!('build_account') super end |
#create_account(attributes = nil) ⇒ Account
Creates a new Account but refuses if one already exists (prevents silent replacement).
36 37 38 39 |
# File 'app/models/concerns/party_account.rb', line 36 def create_account(attributes = nil, &) refuse_silent_account_replacement!('create_account') super end |
#online_account_invite(specific_email = nil, ignore_if_exist: true, return_path: nil) ⇒ Array
Sends (or refreshes) an online account invitation via Account::Inviter.
Preserves the legacy [account, message] tuple for existing callers.
:reek:BooleanParameter
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/concerns/party_account.rb', line 63 def online_account_invite(specific_email = nil, ignore_if_exist: true, return_path: nil) result = Account::Inviter.new.process( party: self, email: specific_email, return_path: return_path, force_reinvite: !ignore_if_exist ) = if result.invited? "Account created and invitation sent to: #{result.email}" else result..first end [result.account, ] end |
#refuse_silent_account_replacement!(caller_name) ⇒ void
This method returns an undefined value.
Raises when an account already exists so callers cannot silently replace it.
46 47 48 49 50 51 52 |
# File 'app/models/concerns/party_account.rb', line 46 def refuse_silent_account_replacement!(caller_name) return if account.blank? msg = "Refusing to #{caller_name} on party #{id} - account #{account.id} (login=#{account.login.inspect}) already exists. Destroy it explicitly if replacement is intended." logger&.warn "[party##{caller_name}] #{msg}" raise Party::ExistingAccountError, msg end |