Sha256: dd4086d2c1e47ac1330e47d08675a72fbf741eef9cc5e0e540d847c8828ac654

Contents?: true

Size: 1.82 KB

Versions: 12

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

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

        # Syntactic sugar to initialize the class and return the queried objects.
        #
        # organization - an organization that needs to find its conference admins
        def self.for_organization(organization)
          new(nil, organization).query
        end

        # Initializes the class.
        #
        # conference - an conference that needs to find its conference admins
        # organization - an organization that needs to find its conference admins
        def initialize(conference, organization = nil)
          @conference = conference
          @organization = conference&.organization || organization
        end

        # Finds organization admins and the users with role admin for the given conference.
        #
        # Returns an ActiveRecord::Relation.
        def query
          organization.admins.or(conferences_user_admins)
        end

        private

        attr_reader :conference, :organization

        def conferences_user_admins
          Decidim::User.where(
            id: Decidim::ConferenceUserRole.where(conference: conferences, role: :admin)
                                           .select(:decidim_user_id)
          )
        end

        def conferences
          if conference
            [conference]
          else
            Decidim::Conference.where(organization: organization)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-conferences-0.27.9 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.8 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.7 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.6 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.5 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.4 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.3 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.2 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.1 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.0 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.0.rc2 app/queries/decidim/conferences/admin/admin_users.rb
decidim-conferences-0.27.0.rc1 app/queries/decidim/conferences/admin/admin_users.rb