app/queries/decidim/consultations/admin/admin_users.rb in decidim-consultations-0.24.3 vs app/queries/decidim/consultations/admin/admin_users.rb in decidim-consultations-0.25.0.rc1
- old
+ new
@@ -1,40 +1,44 @@
# frozen_string_literal: true
module Decidim
module Consultations
module Admin
- # A class used to find the admins for a participatory process including
- # organization admins.
+ # A class used to find the admins for a consultation or an organization consultations.
class AdminUsers < Rectify::Query
# Syntactic sugar to initialize the class and return the queried objects.
#
- # consultation - a process that needs to find its process admins
+ # consultation - a consultation that needs to find its consultation admins
def self.for(consultation)
new(consultation).query
end
+ # Syntactic sugar to initialize the class and return the queried objects.
+ #
+ # organization - an organization that needs to find its consultation admins
+ def self.for_organization(organization)
+ new(nil, organization).query
+ end
+
# Initializes the class.
#
- # consultation - a consultation that needs to find its process admins
- def initialize(consultation)
+ # consultation - a consultation that needs to find its consultation admins
+ # organization - an organization that needs to find its consultation admins
+ def initialize(consultation, organization = nil)
@consultation = consultation
+ @organization = consultation&.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 consultation.
#
# Returns an ActiveRecord::Relation.
def query
- Decidim::User.where(id: organization_admins)
+ organization.admins
end
private
- attr_reader :consultation
-
- def organization_admins
- consultation.organization.admins
- end
+ attr_reader :organization
end
end
end
end