Sha256: 7ee8f1c87173d1536c6eb22daa9b3711ca9f5122075357d88e6582be87c20903

Contents?: true

Size: 1.26 KB

Versions: 37

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A class used to find the users that can moderate the participatory
      # process.
      class Moderators < Rectify::Query
        # Syntactic sugar to initialize the class and return the queried objects.
        #
        # process - a process that needs to find its moderators
        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 + process_users)
        end

        private

        attr_reader :process

        def organization_admins
          process.organization.admins
        end

        def process_users
          Decidim::ParticipatoryProcessUserRole
            .where(participatory_process: process)
            .where.not(role: :collaborator)
            .pluck(:decidim_user_id)
            .uniq
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.24.3 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.6 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.24.2 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.5 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.24.1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.24.0 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.24.0.rc2 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.4 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.24.0.rc1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.3 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.2 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.1.rc1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.23.0 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.22.0 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.21.0 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.20.1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.20.0 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.19.1 app/queries/decidim/participatory_processes/admin/moderators.rb
decidim-participatory_processes-0.18.1 app/queries/decidim/participatory_processes/admin/moderators.rb