Class: Decidim::Verifications::Authorizations

Inherits:
Rectify::Query
  • Object
show all
Defined in:
app/queries/decidim/verifications/authorizations.rb

Overview

Finds authorizations by different criteria

Instance Method Summary collapse

Constructor Details

#initialize(user: nil, name: nil, granted: nil) ⇒ Authorizations

Initializes the class.

Parameters:

  • name (String) (defaults to: nil)

    The name of an authorization method

  • user (User) (defaults to: nil)

    A user to find authorizations for

  • granted (Boolean) (defaults to: nil)

    Whether the authorization is granted or not



12
13
14
15
16
# File 'app/queries/decidim/verifications/authorizations.rb', line 12

def initialize(user: nil, name: nil, granted: nil)
  @user = user
  @name = name
  @granted = granted
end

Instance Method Details

#queryObject

Finds the Authorizations for the given method

Returns an ActiveRecord::Relation.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/queries/decidim/verifications/authorizations.rb', line 21

def query
  scope = Decidim::Authorization.where(nil)

  scope = scope.where(name: name) unless name.nil?
  scope = scope.where(user: user) unless user.nil?

  if granted == true
    scope = scope.where.not(granted_at: nil)
  elsif granted == false
    scope = scope.where(granted_at: nil)
  end

  scope
end