Class: Account::Inviter
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
8
9
10
|
# File 'app/services/account/inviter.rb', line 8
def account
@account
end
|
#party ⇒ Object
Returns the value of attribute party.
8
9
10
|
# File 'app/services/account/inviter.rb', line 8
def party
@party
end
|
Class Method Details
.determine_login(email) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/services/account/inviter.rb', line 39
def self.determine_login(email)
login = email
if Account.where(login: login).exists?
name_part,domain = email.split('@')
base_login = name_part
counter = 0
login = base_login
while Account.where(login: login).exists?
counter += 1
login = "#{base_login}-#{counter}"
end
end
login
end
|
Instance Method Details
#destroy_existing_account!(party, existing_account, email) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'app/services/account/inviter.rb', line 56
def destroy_existing_account!(party, existing_account, email)
ErrorReporting.warning(
"[Account::Inviter] destroying existing account #{existing_account.id} on party #{party.id} before re-inviting",
party_id: party.id, account_id: existing_account.id, account_email: existing_account.email
)
existing_account.destroy
party.reload_account
end
|
#existing_account_result(existing_account) ⇒ Object
73
74
75
|
# File 'app/services/account/inviter.rb', line 73
def existing_account_result(existing_account)
Result.new(invited: false, account: existing_account, messages: ["This customer already has an online account (#{existing_account.login}). Use the existing account page to resend the invitation or reset their password."])
end
|
#login_in_use_result(login) ⇒ Object
69
70
71
|
# File 'app/services/account/inviter.rb', line 69
def login_in_use_result(login)
Result.new(invited: false, messages: ["The login you requested #{login} is already in use."])
end
|
#missing_email_result(party) ⇒ Object
65
66
67
|
# File 'app/services/account/inviter.rb', line 65
def missing_email_result(party)
Result.new(invited: false, messages: ["No Email for party #{party.id}"])
end
|
#process(party:, email: nil, login: nil, skip_invitation_delivery: false, return_path: nil, force_reinvite: false) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/services/account/inviter.rb', line 10
def process(party:, email: nil, login: nil, skip_invitation_delivery: false,
return_path: nil, force_reinvite: false)
email ||= party.email
return missing_email_result(party) unless email
existing = Account.find_by(party_id: party.id)
if existing
if force_reinvite
destroy_existing_account!(party, existing, email)
else
return existing_account_result(existing)
end
end
login = login || self.class.determine_login(email)
return login_in_use_result(login) if Account.where(login: login).exists?
account = Account.invite!(login: login, email: email, name: party.full_name) do |a|
a.party_id = party.id
a.return_path_for_invite = return_path
a.skip_invitation = true
a.set_default_marketing_preferences(I18n.locale)
end
account.deliver_invitation unless skip_invitation_delivery
Result.new(invited: account.persisted?, email: email, account: account, messages: account.errors.full_messages)
end
|