Sha256: af7ec81d42035bb1fa67a87881cb91243fedf853de3a7dd811cb228d4d779edf

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

#
# Your user model must include this concern to send and receive invitations. Your user class must also be
# specified in the invitation configuration `Invitation.configure.user_model`.
#
# Your user model code is responsible for managing associations to any organizations you wish
# to issue invitations to. Your user model will probably also include an authentication model.
#
# For example, to make your user class `User` able to issue invitations to model `Account`:
#
#     class User < ActiveRecord::Base
#       include Invitation::User
#       include Authenticate::User
#
#       has_many :account_memberships
#       has_many :accounts, through: :account_memberships
#     end
#
module Invitation
  module User
    extend ActiveSupport::Concern

    included do
      has_many :invitations, class_name: 'Invite', foreign_key: :recipient_id
      has_many :sent_invites, class_name: 'Invite', foreign_key: :sender_id
    end

    def claim_invite(token)
      invite = Invite.find_by_token(token)
      return if invite.nil?
      invitable = invite.invitable
      invitable.add_invited_user self
      invite.recipient = self
      invite.save
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
invitation-0.1.1 lib/invitation/user.rb
invitation-0.1.0 lib/invitation/user.rb
invitation-0.0.2 lib/invitation/user.rb
invitation-0.0.1 lib/invitation/user.rb