Sha256: b72e592db54acbf5273aeeaf6dc627acba91c2dc34a2528741796445ce86ad68

Contents?: true

Size: 1.87 KB

Versions: 45

Compression:

Stored size: 1.87 KB

Contents

module Teams::Base
  extend ActiveSupport::Concern

  included do
    # super scaffolding
    has_many :scaffolding_absolutely_abstract_creative_concepts, class_name: "Scaffolding::AbsolutelyAbstract::CreativeConcept", dependent: :destroy, enable_cable_ready_updates: true

    # added_by_id is a foreign_key to other Memberships on the same team,
    # so we nullify this to remove the constraint to delete the team.
    before_destroy { Membership.where(team: self).update_all(added_by_id: nil) }

    # memberships and invitations
    has_many :memberships, dependent: :destroy
    has_many :users, through: :memberships
    has_many :invitations

    # oauth for grape api
    has_many :platform_applications, class_name: "Platform::Application", dependent: :destroy, foreign_key: :team_id

    # integrations
    has_many :integrations_stripe_installations, class_name: "Integrations::StripeInstallation", dependent: :destroy if stripe_enabled?

    # validations
    validates :name, presence: true
    validates :time_zone, inclusion: {in: ActiveSupport::TimeZone.all.map(&:name)}, allow_nil: true
  end

  def platform_agent_access_tokens
    Platform::AccessToken.joins(:application).where(resource_owner_id: users.where.not(platform_agent_of_id: nil), application: {team: nil})
  end

  def admins
    memberships.current_and_invited.admins
  end

  def admin_users
    admins.map(&:user).compact
  end

  def primary_contact
    admin_users.min { |user| user.created_at }
  end

  def formatted_email_address
    primary_contact.email
  end

  def invalidate_caches
    users.map(&:invalidate_ability_cache)
  end

  def team
    # some generic features appeal to the `team` method for security or scoping purposes, but sometimes those same
    # generic functions need to function for a team model as well, so we do this.
    self
  end

  ActiveSupport.run_load_hooks :bullet_train_teams_base, self
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
bullet_train-1.9.0 app/models/concerns/teams/base.rb
bullet_train-1.8.5 app/models/concerns/teams/base.rb
bullet_train-1.8.4 app/models/concerns/teams/base.rb
bullet_train-1.8.3 app/models/concerns/teams/base.rb
bullet_train-1.8.2 app/models/concerns/teams/base.rb
bullet_train-1.8.1 app/models/concerns/teams/base.rb
bullet_train-1.8.0 app/models/concerns/teams/base.rb
bullet_train-1.7.23 app/models/concerns/teams/base.rb
bullet_train-1.7.22 app/models/concerns/teams/base.rb
bullet_train-1.7.21 app/models/concerns/teams/base.rb
bullet_train-1.7.20 app/models/concerns/teams/base.rb
bullet_train-1.7.19 app/models/concerns/teams/base.rb
bullet_train-1.7.18 app/models/concerns/teams/base.rb
bullet_train-1.7.17 app/models/concerns/teams/base.rb
bullet_train-1.7.16 app/models/concerns/teams/base.rb
bullet_train-1.7.15 app/models/concerns/teams/base.rb
bullet_train-1.7.14 app/models/concerns/teams/base.rb
bullet_train-1.7.13 app/models/concerns/teams/base.rb
bullet_train-1.7.12 app/models/concerns/teams/base.rb
bullet_train-1.7.11 app/models/concerns/teams/base.rb