Sha256: 7c6a22fe754ccd7b83d082939324239eaf1d76bce6b51da6428e70886e087b43

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

class Kaui::EngineController < ApplicationController
  before_filter :authenticate_user!

  layout :get_layout

  # Common options for the Kill Bill client
  def options_for_klient(options = {})
    {
        # TODO Kaui doesn't support multi-tenancy yet
        :api_key    => KillBillClient.api_key,
        :api_secret => KillBillClient.api_secret,
        :username   => current_user.kb_username || KillBillClient.username,
        :password   => current_user.password || KillBillClient.password,
        :session_id => current_user.kb_session_id
    }.merge(options)
  end

  # Used for auditing purposes
  def current_user
    super
  end

  def current_ability
    # Redefined here to namespace Ability in the correct module
    @current_ability ||= Kaui::Ability.new(current_user)
  end

  protected

  def as_string(e)
    if e.is_a?(KillBillClient::API::ResponseError)
      "Error #{e.response.code}: #{as_string_from_response(e.response.body)}"
    else
      e.message
    end
  end

  def as_string_from_response(response)
    error_message = response
    begin
      # BillingExceptionJson?
      error_message = JSON.parse response
    rescue => e
    end

    if error_message.respond_to? :[] and error_message['message'].present?
      # Likely BillingExceptionJson
      error_message = error_message['message']
    end
    # Limit the error size to avoid ActionDispatch::Cookies::CookieOverflow
    error_message[0..1000]
  end

  def get_layout
    layout ||= Kaui.config[:layout]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kaui-0.7.2 app/controllers/kaui/engine_controller.rb
kaui-0.7.1 app/controllers/kaui/engine_controller.rb
kaui-0.7.0 app/controllers/kaui/engine_controller.rb