1 # frozen_string_literal: true
 
   3 # == Schema Information
 
   5 # Table name: oauth_applications
 
   7 #  id           :bigint           not null, primary key
 
   8 #  owner_type   :string           not null
 
   9 #  owner_id     :bigint           not null
 
  10 #  name         :string           not null
 
  11 #  uid          :string           not null
 
  12 #  secret       :string           not null
 
  13 #  redirect_uri :text             not null
 
  14 #  scopes       :string           default(""), not null
 
  15 #  confidential :boolean          default(TRUE), not null
 
  16 #  created_at   :datetime         not null
 
  17 #  updated_at   :datetime         not null
 
  21 #  index_oauth_applications_on_owner_type_and_owner_id  (owner_type,owner_id)
 
  22 #  index_oauth_applications_on_uid                      (uid) UNIQUE
 
  26 #  fk_rails_...  (owner_id => users.id)
 
  28 class Oauth2Application < Doorkeeper::Application
 
  29   belongs_to :owner, :polymorphic => true
 
  31   validate :allowed_scopes
 
  33   def authorized_scopes_for(user)
 
  34     authorized_tokens.where(:resource_owner_id => user).sum(Doorkeeper::OAuth::Scopes.new, &:scopes)
 
  40     return if owner.administrator?
 
  42     errors.add(:scopes) if scopes.any? { |scope| Oauth::PRIVILEGED_SCOPES.include?(scope) }