Sha256: f1c40920fbd117ce0b4c8e70983fd1c6a3fd24be5229011ccddb0584ddd5045a

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A class used to find the admins for a participatory process including
    # organization admins.
    class ProcessAdmins < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # process - a process that needs to find its process admins
      def self.for(process)
        new(process).query
      end

      # Initializes the class.
      #
      # process - a process that needs to find its process admins
      def initialize(process)
        @process = process
      end

      # Finds organization admins and the users with role admin for the given process.
      #
      # Returns an ActiveRecord::Relation.
      def query
        Decidim::User.where(id: organization_admins).or(Decidim::User.where(id: process_admins))
      end

      private

      attr_reader :process

      def organization_admins
        process.organization.admins
      end

      def process_admins
        Decidim::ParticipatoryProcessUserRole
          .where(participatory_process: process, role: :admin)
          .pluck(:decidim_user_id)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
decidim-admin-0.5.1 app/queries/decidim/admin/process_admins.rb
decidim-0.5.1 decidim-admin/app/queries/decidim/admin/process_admins.rb
decidim-admin-0.5.0 app/queries/decidim/admin/process_admins.rb
decidim-0.5.0 decidim-admin/app/queries/decidim/admin/process_admins.rb
decidim-admin-0.4.4 app/queries/decidim/admin/process_admins.rb
decidim-0.4.4 decidim-admin/app/queries/decidim/admin/process_admins.rb
decidim-admin-0.4.3 app/queries/decidim/admin/process_admins.rb
decidim-admin-0.4.2 app/queries/decidim/admin/process_admins.rb
decidim-admin-0.4.1 app/queries/decidim/admin/process_admins.rb
decidim-0.4.3 decidim-admin/app/queries/decidim/admin/process_admins.rb
decidim-0.4.2 decidim-admin/app/queries/decidim/admin/process_admins.rb
decidim-0.4.1 decidim-admin/app/queries/decidim/admin/process_admins.rb