Sha256: 4e50e23dada7bfeccdbc3aaf1b2d4c984e1504fe0d3aaac1f80a1c34ae406d08

Contents?: true

Size: 1.31 KB

Versions: 25

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    module Admin
      # A class used to find the admins for an initiative or an organization initiatives.
      class AdminUsers < Decidim::Query
        # Syntactic sugar to initialize the class and return the queried objects.
        #
        # initiative - Decidim::Initiative
        def self.for(initiative)
          new(initiative).query
        end

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

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

        # Finds organization admins and the users with role admin for the given initiative.
        #
        # Returns an ActiveRecord::Relation.
        def query
          organization.admins
        end

        private

        attr_reader :initiative, :organization
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.4 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.9 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.29.0 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.3 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.8 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.29.0.rc4 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.29.0.rc3 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.29.0.rc2 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.29.0.rc1 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.2 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.7 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.1 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.6 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.0 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.5 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.0.rc5 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.28.0.rc4 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.4 app/queries/decidim/initiatives/admin/admin_users.rb
decidim-initiatives-0.27.3 app/queries/decidim/initiatives/admin/admin_users.rb