Sha256: a9c7b5f5bf6e425014fccf7d69bd70aea9a24f22eaf5f72522a0c8ac88251e37

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Emailbutler
  class UiController < Emailbutler::ApplicationController
    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
      @messages = Emailbutler.find_messages_by(search_condition)
    end

    private

    def search_condition
      {
        status: 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

1 entries across 1 versions & 1 rubygems

Version Path
emailbutler-0.4.0 app/controllers/emailbutler/ui_controller.rb