Sha256: 1a3356148f0af24c000cf3dff2ed21cec8245e9d5b74e73cb4aedb24c5247b75

Contents?: true

Size: 1.5 KB

Versions: 23

Compression:

Stored size: 1.5 KB

Contents

class Platform::Application < ApplicationRecord
  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, 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

23 entries across 23 versions & 1 rubygems

Version Path
bullet_train-api-1.2.27 app/models/platform/application.rb
bullet_train-api-1.2.26 app/models/platform/application.rb
bullet_train-api-1.2.25 app/models/platform/application.rb
bullet_train-api-1.2.24 app/models/platform/application.rb
bullet_train-api-1.2.23 app/models/platform/application.rb
bullet_train-api-1.2.22 app/models/platform/application.rb
bullet_train-api-1.2.21 app/models/platform/application.rb
bullet_train-api-1.2.20 app/models/platform/application.rb
bullet_train-api-1.2.19 app/models/platform/application.rb
bullet_train-api-1.2.18 app/models/platform/application.rb
bullet_train-api-1.2.17 app/models/platform/application.rb
bullet_train-api-1.2.16 app/models/platform/application.rb
bullet_train-api-1.2.15 app/models/platform/application.rb
bullet_train-api-1.2.14 app/models/platform/application.rb
bullet_train-api-1.2.13 app/models/platform/application.rb
bullet_train-api-1.2.12 app/models/platform/application.rb
bullet_train-api-1.2.11 app/models/platform/application.rb
bullet_train-api-1.2.10 app/models/platform/application.rb
bullet_train-api-1.2.9 app/models/platform/application.rb
bullet_train-api-1.2.8 app/models/platform/application.rb