Class: Rhino::OrganizationInvitation

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#accept!(user) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rhino/models/organization_invitation.rb', line 32

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

  # Add user to the group (and organization, for tenant groups) via the
  # user_roles pivot. The membership carries the invitation's route_group
  # so group-membership enforcement (GROUP_AUTH_DESIGN.md §6/§8) can match.
  if defined?(UserRole)
    attrs = {
      user_id: user.id,
      organization_id: organization_id,
      role_id: role_id
    }

    invite_group = respond_to?(:route_group) ? route_group : nil
    if invite_group.present? && UserRole.column_names.include?("route_group")
      attrs[:route_group] = invite_group
    end

    UserRole.find_or_create_by!(attrs)
  end
end

#expired?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rhino/models/organization_invitation.rb', line 24

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

#pending?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rhino/models/organization_invitation.rb', line 28

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