Class: Decidim::ActionDelegator::AuthorizedResources

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/action_delegator/authorized_resources.rb

Instance Method Summary collapse

Constructor Details

#initialize(setting:) ⇒ AuthorizedResources

Finds all the resources that have configured the action delegator verifier Note that currently only returns elections (Decidim::Election) In the future components could be returned here as well



9
10
11
# File 'app/queries/decidim/action_delegator/authorized_resources.rb', line 9

def initialize(setting:)
  @setting = setting
end

Instance Method Details

#componentsObject



23
24
25
# File 'app/queries/decidim/action_delegator/authorized_resources.rb', line 23

def components
  Decidim::PublicComponents.for(@setting.organization, manifest_name: "elections")
end

#queryObject



13
14
15
16
17
18
19
20
21
# File 'app/queries/decidim/action_delegator/authorized_resources.rb', line 13

def query
  condition = [
    "(census_manifest = 'internal_users' AND census_settings -> 'authorization_handlers' -> 'delegations_verifier' -> 'options' -> 'setting' ? :setting_id) OR " \
    "(census_manifest = 'action_delegator_census' AND census_settings ->> 'setting_id' = :setting_id)",
    { setting_id: @setting.id.to_s }
  ]

  Decidim::Elections::Election.where(component: components).where(condition)
end