Sha256: 1722f193fafdf8eefa69ad9d7d2c4febf2ef4fead93e4155f59c2b8f4d5e4785

Contents?: true

Size: 2 KB

Versions: 7

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

module Decidim
  module Cdtb
    module Multitenants
      # Finds information about the Organization, or Organizations, searching by the :host_term argument ignorecase.
      # Set :full (second param) to `true` for full information
      #
      class OrgByHostLike < ::Decidim::Cdtb::Task
        def initialize(host_term, full_info)
          @host_term= host_term
          @show_full_info= full_info == "true"
          super("ORG BY HOST LIKE")
        end

        def prepare_execution(_ctx)
          @query = Decidim::Organization.where("host ilike ?", "%#{@host_term}%")
          log_task_info("Found #{@query.count} organizations")
        end

        def do_execution(_ctx)
          @query.find_each do |org|
            log_task_step("Organization [#{org.id}] #{org.name}:")
            if show_full_info?
              show_full_info(org)
            else
              h= {
                host: org.host,
                time_zone: org.time_zone,
                locales: "#{org.default_locale} + [#{org.available_locales&.join(", ")}]",
                available_authorizations: org.available_authorizations&.join(", ")
              }
              do_log_info(h.to_yaml)
            end
            do_log_info("---------------------------------------------------------")
          end
        end

        #----------------------------------------------------------------

        private

        #----------------------------------------------------------------

        def show_full_info?
          @show_full_info
        end

        def show_full_info(org)
          do_log_info(org.attributes.to_yaml)
        end

        def show_summary_info(org)
          h= {
            host: org.host,
            time_zone: org.time_zone,
            locales: "#{org.default_locale} + [#{org.available_locales&.join(", ")}]",
            available_authorizations: org.available_authorizations&.join(", ")
          }
          do_log_info(h.to_yaml)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-cdtb-0.3.0 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.2.1 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.1.8 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.1.7 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.1.6 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.1.4 lib/decidim/cdtb/multitenants/org_by_host_like.rb
decidim-cdtb-0.1.3 lib/decidim/cdtb/multitenants/org_by_host_like.rb