Sha256: 5865c98615ae1e4207863a053f0745313ecc361c4fcca548a671b51e94b9857b

Contents?: true

Size: 1.54 KB

Versions: 102

Compression:

Stored size: 1.54 KB

Contents

class Platform::Application < BulletTrain::Api.base_class.constantize
  self.table_name = "oauth_applications"

  include Doorkeeper::Orm::ActiveRecord::Mixins::Application
  # 🚅 add concerns above.

  belongs_to :team, optional: true
  # 🚅 add belongs_to associations above.

  # 🚅 add has_many associations above.

  # 🚅 add oauth providers above.

  has_one :membership, foreign_key: :platform_agent_of_id, dependent: :nullify
  has_one :user, foreign_key: :platform_agent_of_id
  # 🚅 add has_one associations above.

  # 🚅 add scopes above.

  # 🚅 add validations above.

  after_create :create_user_and_membership
  after_create :create_access_token
  after_update :update_user_and_membership
  before_destroy :destroy_user
  # 🚅 add callbacks above.

  # 🚅 add delegations above.

  def label_string
    name
  end

  def create_user_and_membership
    faux_password = SecureRandom.hex
    create_user(email: "noreply+#{SecureRandom.hex}@bullettrain.co", password: faux_password, password_confirmation: faux_password, first_name: label_string)
    create_membership(team: team, user: user, user_email: user.email, platform_agent: true)
    membership.roles << Role.admin
  end

  def create_access_token
    access_tokens.create(resource_owner_id: user.id, description: "Default Access Token", provisioned: true)
  end

  def update_user_and_membership
    user.update(first_name: label_string)
  end

  def destroy_user
    former_user = membership.user
    membership.nullify_user
    former_user.destroy
  end

  # 🚅 add methods above.
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
bullet_train-api-1.7.18 app/models/platform/application.rb
bullet_train-api-1.7.17 app/models/platform/application.rb
bullet_train-api-1.7.16 app/models/platform/application.rb
bullet_train-api-1.7.15 app/models/platform/application.rb
bullet_train-api-1.7.14 app/models/platform/application.rb
bullet_train-api-1.7.13 app/models/platform/application.rb
bullet_train-api-1.7.12 app/models/platform/application.rb
bullet_train-api-1.7.11 app/models/platform/application.rb
bullet_train-api-1.7.10 app/models/platform/application.rb
bullet_train-api-1.7.9 app/models/platform/application.rb
bullet_train-api-1.7.3 app/models/platform/application.rb
bullet_train-api-1.7.2 app/models/platform/application.rb
bullet_train-api-1.7.1 app/models/platform/application.rb
bullet_train-api-1.7.0 app/models/platform/application.rb
bullet_train-api-1.6.38 app/models/platform/application.rb
bullet_train-api-1.6.37 app/models/platform/application.rb
bullet_train-api-1.6.36 app/models/platform/application.rb
bullet_train-api-1.6.35 app/models/platform/application.rb
bullet_train-api-1.6.34 app/models/platform/application.rb
bullet_train-api-1.6.33 app/models/platform/application.rb