Sha256: 8fc398828be3c4c702100518ae105681f31fbb1624911715f2d13d72a990e1e6

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

module Doorkeeper
  class Application
    include DoorkeeperMongodb::Compatible

    include MongoMapper::Document

    include DoorkeeperMongodb::Mixins::MongoMapper::ApplicationMixin

    safe
    timestamps!

    set_collection_name 'oauth_applications'

    many :authorized_tokens, class_name: 'Doorkeeper::AccessToken', dependent: :destroy

    key :name,         String
    key :uid,          String
    key :secret,       String
    key :redirect_uri, String
    key :confidential, Boolean, default: true
    key :scopes,       String

    def self.authorized_for(resource_owner)
      ids = AccessToken.where(
        resource_owner_id: resource_owner.id,
        revoked_at: nil
      ).map(&:application_id)

      find(ids)
    end

    def self.create_indexes
      ensure_index :uid, unique: true
    end

    def save!(options = {})
      if options.key?(:validate)
        super(options.merge(safe: options.delete(:validate)))
      else
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doorkeeper-mongodb-4.2.0 lib/doorkeeper/orm/mongo_mapper/application.rb