Class: Pageflow::InvitationForm Private

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/pageflow/invitation_form.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, available_accounts) ⇒ InvitationForm

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of InvitationForm.

API:

  • private



8
9
10
11
12
13
14
15
16
17
# File 'app/models/pageflow/invitation_form.rb', line 8

def initialize(attributes, available_accounts)
  @attributes = attributes
  @available_accounts = available_accounts

  @invited_user = InvitedUser.new(attributes[:user])
  @target_user = existing_user || @invited_user

  @membership = @target_user.memberships.build(entity: ,
                                               role: initial_role)
end

Instance Attribute Details

#available_accountsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'app/models/pageflow/invitation_form.rb', line 6

def available_accounts
  @available_accounts
end

#membershipObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'app/models/pageflow/invitation_form.rb', line 6

def membership
  @membership
end

#target_userObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'app/models/pageflow/invitation_form.rb', line 6

def target_user
  @target_user
end

Instance Method Details

#existing_memberObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



35
36
37
38
# File 'app/models/pageflow/invitation_form.rb', line 35

def existing_member
  @existing_member ||=
    &.users&.find_by_email(user.email)
end

#initial_accountObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



40
41
42
43
44
45
46
47
# File 'app/models/pageflow/invitation_form.rb', line 40

def 
   ||=
    if 
      available_accounts.find_by_id()
    else
      available_accounts.first
    end
end

#saveObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



23
24
25
26
27
28
29
# File 'app/models/pageflow/invitation_form.rb', line 23

def save
  return false unless valid?

  Pageflow.config.quotas.get(:users, ).verify_available!

  membership.save!
end

#userObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



19
20
21
# File 'app/models/pageflow/invitation_form.rb', line 19

def user
  @invited_user.becomes(User)
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



31
32
33
# File 'app/models/pageflow/invitation_form.rb', line 31

def valid?
  (existing_user || @invited_user.valid?) && membership.valid?
end