Sha256: 7ea6fc57eaf0bc535a29abc90f4c3f57475abe363145950264968bfffe7c38b8

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'pagy'

module Emailbutler
  class UiController < Emailbutler::ApplicationController
    include ::Pagy::Backend

    http_basic_authenticate_with name: ::Emailbutler.configuration.ui_username,
                                 password: ::Emailbutler.configuration.ui_password,
                                 if: -> { basic_auth_enabled? }

    def index
      @summary = ::Emailbutler.count_messages_by_status
    end

    def show
      @pagy, @messages = pagy(::Emailbutler.find_messages_by(search_condition))
    end

    private

    def search_condition
      {
        status: params[:id] == 'all' ? nil : params[:id],
        mailer: params[:mailer_name].presence,
        action: params[:action_name].presence,
        send_to: [params[:receiver].presence].compact.presence
      }.compact
    end

    def basic_auth_enabled?
      configuration = ::Emailbutler.configuration

      return false if configuration.ui_username.blank?
      return false if configuration.ui_password.blank?

      configuration.ui_secured_environments.include?(Rails.env)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
emailbutler-0.8.8 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.7 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.6 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.5 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.4 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.3 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.2 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.8.1 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.6 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.5 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.4 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.3 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.2 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.1 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.7.0 app/controllers/emailbutler/ui_controller.rb
emailbutler-0.6.1 app/controllers/emailbutler/ui_controller.rb