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

Instance Method Summary collapse

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).

Parameters:

  • email_input (String)

    raw email from login form

Returns:



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

#abilityAbility

Memoized CanCan ability for this party (used by delegate :can? on Party).

Returns:



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.

Parameters:

  • attributes (Hash, nil) (defaults to: nil)

    passed to super

Returns:

Raises:



26
27
28
29
# File 'app/models/concerns/party_account.rb', line 26

def (attributes = nil, &)
  ('build_account')
  super
end

#create_account(attributes = nil) ⇒ Account

Creates a new Account but refuses if one already exists (prevents silent replacement).

Parameters:

  • attributes (Hash, nil) (defaults to: nil)

    passed to super

Returns:

Raises:



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

def (attributes = nil, &)
  ('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

Parameters:

  • specific_email (String, nil) (defaults to: nil)

    optional override email

  • ignore_if_exist (Boolean) (defaults to: true)

    when false, forces re-invite flow

  • return_path (String, nil) (defaults to: nil)

    post-acceptance redirect path

Returns:

  • (Array)

    two-element array: invited or existing Account (may be nil), then status String



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/concerns/party_account.rb', line 63

def (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
  )
  message = if result.invited?
              "Account created and invitation sent to: #{result.email}"
            else
              result.messages.first
            end
  [result., message]
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.

Parameters:

  • caller_name (String)

    calling method name for logging (e.g. "build_account")

Raises:



46
47
48
49
50
51
52
# File 'app/models/concerns/party_account.rb', line 46

def (caller_name)
  return if .blank?

  msg = "Refusing to #{caller_name} on party #{id} - account #{.id} (login=#{..inspect}) already exists. Destroy it explicitly if replacement is intended."
  logger&.warn "[party##{caller_name}] #{msg}"
  raise Party::ExistingAccountError, msg
end