Sha256: 6fe383d5d65542dfcb11dbc8e9f3e479bbeac922364c83592b94d0c0fe50b7ba

Contents?: true

Size: 1.3 KB

Versions: 22

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A class used to find the admins for an assembly.
      class AdminUsers < Rectify::Query
        # Syntactic sugar to initialize the class and return the queried objects.
        #
        # assembly - an assembly that needs to find its assembly admins
        def self.for(assembly)
          new(assembly).query
        end

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

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

        private

        attr_reader :assembly

        def organization_admins
          assembly.organization.admins
        end

        def assembly_user_admins
          assembly_user_admin_ids = Decidim::AssemblyUserRole
                                    .where(assembly: assembly, role: :admin)
                                    .pluck(:decidim_user_id)
          Decidim::User.where(id: assembly_user_admin_ids)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

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