Sha256: 18c6399e8c3a4bb73cf1713e257b1dba4a7c01382e961a867e3a8e9167d212e5

Contents?: true

Size: 1.07 KB

Versions: 84

Compression:

Stored size: 1.07 KB

Contents

module Invitations::Base
  extend ActiveSupport::Concern

  included do
    belongs_to :team
    belongs_to :from_membership, class_name: "Membership"
    belongs_to :invitation_list, class_name: "Account::Onboarding::InvitationList", optional: true
    has_one :membership, dependent: :nullify

    accepts_nested_attributes_for :membership

    validates :email, presence: true, uniqueness: {scope: :team}

    after_create :set_added_by_membership
    after_create :send_invitation_email

    attribute :uuid, default: -> { SecureRandom.hex }

    def roles
      membership.roles
    end
  end

  def set_added_by_membership
    membership.update(added_by: from_membership)
  end

  def send_invitation_email
    UserMailer.invited(uuid).deliver_later
  end

  def accept_for(user)
    User.transaction do
      user.memberships << membership
      user.update(current_team: team, former_user: false)
      destroy
    end
  end

  def name
    I18n.t("invitations.values.name", team_name: team.name)
  end

  def is_for?(user)
    user.email.downcase.strip == email.downcase.strip
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
bullet_train-1.6.32 app/models/concerns/invitations/base.rb
bullet_train-1.6.31 app/models/concerns/invitations/base.rb
bullet_train-1.6.30 app/models/concerns/invitations/base.rb
bullet_train-1.6.29 app/models/concerns/invitations/base.rb
bullet_train-1.6.28 app/models/concerns/invitations/base.rb
bullet_train-1.6.27 app/models/concerns/invitations/base.rb
bullet_train-1.6.26 app/models/concerns/invitations/base.rb
bullet_train-1.6.25 app/models/concerns/invitations/base.rb
bullet_train-1.6.24 app/models/concerns/invitations/base.rb
bullet_train-1.6.23 app/models/concerns/invitations/base.rb
bullet_train-1.6.22 app/models/concerns/invitations/base.rb
bullet_train-1.6.21 app/models/concerns/invitations/base.rb
bullet_train-1.6.20 app/models/concerns/invitations/base.rb
bullet_train-1.6.19 app/models/concerns/invitations/base.rb
bullet_train-1.6.18 app/models/concerns/invitations/base.rb
bullet_train-1.6.17 app/models/concerns/invitations/base.rb
bullet_train-1.6.16 app/models/concerns/invitations/base.rb
bullet_train-1.6.15 app/models/concerns/invitations/base.rb
bullet_train-1.6.14 app/models/concerns/invitations/base.rb
bullet_train-1.6.13 app/models/concerns/invitations/base.rb