Class: AgentCode::OrganizationInvitation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/agentcode/models/organization_invitation.rb

Constant Summary collapse

STATUSES =
%w[pending accepted expired cancelled].freeze

Instance Method Summary collapse

Instance Method Details

#accept!(user) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/agentcode/models/organization_invitation.rb', line 30

def accept!(user)
  update!(
    status: "accepted",
    accepted_at: Time.current
  )

  # Add user to organization via pivot table
  if defined?(UserRole)
    UserRole.find_or_create_by!(
      user_id: user.id,
      organization_id: organization_id,
      role_id: role_id
    )
  end
end

#expired?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/agentcode/models/organization_invitation.rb', line 22

def expired?
  status == "pending" && expires_at.present? && expires_at <= Time.current
end

#pending?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/agentcode/models/organization_invitation.rb', line 26

def pending?
  status == "pending" && !expired?
end