app/queries/decidim/votings/admin/admin_users.rb in decidim-elections-0.24.3 vs app/queries/decidim/votings/admin/admin_users.rb in decidim-elections-0.25.0.rc1

- old
+ new

@@ -1,39 +1,44 @@ # frozen_string_literal: true module Decidim module Votings module Admin - # A class used to find the admins for a voting including organization admins. + # A class used to find the admins for a voting or an organization votings. class AdminUsers < Rectify::Query # Syntactic sugar to initialize the class and return the queried objects. # # voting - a voting that needs to find its voting admins def self.for(voting) new(voting).query end + # Syntactic sugar to initialize the class and return the queried objects. + # + # organization - an organization that needs to find its voting admins + def self.for_organization(organization) + new(nil, organization).query + end + # Initializes the class. # - # voting - a voting that needs to find its process admins - def initialize(voting) + # voting - a voting that needs to find its voting admins + # organization - an organization that needs to find its voting admins + def initialize(voting, organization = nil) @voting = voting + @organization = voting&.organization || organization end - # Finds organization admins and the users with role admin for the given process. + # Finds organization admins and the users with role admin for the given voting. # # Returns an ActiveRecord::Relation. def query - Decidim::User.where(id: organization_admins) + organization.admins end private - attr_reader :voting - - def organization_admins - voting.organization.admins - end + attr_reader :voting, :organization end end end end