Module: SuperAuth::ActiveRecord::ByCurrentUser

Defined in:
lib/super_auth/active_record/by_current_user.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/super_auth/active_record/by_current_user.rb', line 2

def self.included(base)
  base.has_many :super_auth_authorizations

  base.send(:default_scope, **{all_queries: true}) do
    raise "SuperAuth.current_user not set" if SuperAuth.current_user.blank?

    if SuperAuth.current_user.system?
      self
    else
      # Important:
      # We use a subquery here instead of a inner join because we don't want
      # to potentially affect break on queries issue count queries in their app.
      where(id: SuperAuth::ActiveRecord::Authorization.where(super_auth_user_id: SuperAuth.current_user.id).select(:resource_id))
    end
  end
end

Instance Method Details

#system?Boolean

Returns:

  • (Boolean)


19
# File 'lib/super_auth/active_record/by_current_user.rb', line 19

def system? = false