Sha256: 40aed94e3dd8ed4649e1cfd2a44c879ab1996801404e45d0ef7348d731735e05

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

module InvoiceBar
  class ApplicationController < ActionController::Base    
    protect_from_forgery
    
    helper InvoiceBar::InvoiceBarHelper
    layout 'invoice_bar/layouts/signed_in'
    
    protected
    
      # For InheritedResources
      def begin_of_association_chain
        current_user
      end
    
      def fetch_user_contacts
        @contacts = current_user.contacts
      end
    
      def fetch_user_invoice_templates
        @invoice_templates = current_user.invoice_templates
      end
    
      def fetch_user_receipt_templates
        @receipt_templates = current_user.receipt_templates
      end
      
      def fetch_user_accounts
        @accounts = current_user.accounts
        
        if @accounts.empty?
          flash[:alert] = t('messages.no_accounts')
        end
      end
    
      def fetch_currencies
        @currencies = Currency.order('priority DESC')
        
        if @currencies.empty?
          flash[:alert] = t('messages.no_currencies')
        end
      end
      
      def require_admin_rights
        if current_user
          unless current_user.administrator?
            redirect_to root_url, alert: t('messages.not_administrator')
          end
        else
          not_authenticated
        end
      end

      def not_authenticated
        redirect_to login_url, alert: t('messages.not_authenticated')
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
invoice_bar-0.0.6 app/controllers/invoice_bar/application_controller.rb
invoice_bar-0.0.5 app/controllers/invoice_bar/application_controller.rb
invoice_bar-0.0.4 app/controllers/invoice_bar/application_controller.rb
invoice_bar-0.0.3 app/controllers/invoice_bar/application_controller.rb
invoice_bar-0.0.2 app/controllers/invoice_bar/application_controller.rb
invoice_bar-0.0.1 app/controllers/invoice_bar/application_controller.rb