Class: Pageflow::InvitationForm Private

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

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.

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.



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.



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.



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.



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.



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

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.



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

def 
  @initial_account ||=
    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.



23
24
25
26
27
28
# 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.



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:

  • (Boolean)


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

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