Class: Decidim::Verifications::AuthorizationsBeforeDate
- Defined in:
- decidim-verifications/app/queries/decidim/verifications/authorizations_before_date.rb
Overview
Finds authorizations by different criteria
Instance Method Summary collapse
-
#initialize(organization:, date:, granted: true, impersonated_only: false) ⇒ AuthorizationsBeforeDate
constructor
Initializes the class.
-
#query ⇒ Object
Finds the Authorizations for the given method.
Methods inherited from Query
#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|
Constructor Details
#initialize(organization:, date:, granted: true, impersonated_only: false) ⇒ AuthorizationsBeforeDate
Initializes the class.
13 14 15 16 17 18 |
# File 'decidim-verifications/app/queries/decidim/verifications/authorizations_before_date.rb', line 13 def initialize(organization:, date:, granted: true, impersonated_only: false) @organization = organization @date = date @granted = granted @impersonated_only = impersonated_only end |
Instance Method Details
#query ⇒ Object
Finds the Authorizations for the given method
Returns an ActiveRecord::Relation.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'decidim-verifications/app/queries/decidim/verifications/authorizations_before_date.rb', line 23 def query return Decidim::Authorization.none unless organization query = Decidim::Authorization.left_outer_joins(:organization).where(decidim_organizations: { id: organization.id }) if impersonated_only query = query .left_outer_joins(:user) .where(decidim_users: { decidim_organization_id: organization.id }) .where(decidim_users: { managed: true }) end query = query.where("#{Decidim::Authorization.table_name}.created_at < ?", date) unless date.nil? if granted query.where.not(granted_at: nil) else query.where(granted_at: nil) end end |