Sha256: b49ee6d00d643fb7347d08e60d85bbe3c586c94afe2896faa3a2fe73a7e68d6b

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

module Saucy
  module AccountAuthorization
    extend ActiveSupport::Concern

    included do
      helper_method :current_account, :current_project, :current_account?, :current_project?
      include InstanceMethods
    end

    module InstanceMethods
      protected

      def current_account
        ::Account.find_by_keyword!(params[:account_id])
      end

      def current_project
        ::Project.find_by_keyword!(params[:project_id])
      end

      def current_project?
        params[:project_id].present?
      end

      def current_account?
        params[:account_id].present?
      end

      def authorize_admin
        unless current_user.admin_of?(current_account)
          deny_access("You must be an admin to access that page.")
        end
      end

      def authorize_member
        unless current_user.member_of?(current_project)
          deny_access("You do not have permission for this project.")
        end
      end

      def ensure_active_account
        if current_account? && current_account.past_due?
          if current_user.admin_of?(current_account)
            flash[:alert] = t('.account_past_due.admin', :default => "There was an issue processing the credit card you have on file. Please update your credit card information.")
          else
            flash[:alert] = t('.account_past_due.user', :default => "There was an issue processing the credit card on file for this account. Please have an administrator on the account update the credit card information.")
          end
          redirect_to account_billing_path(current_account)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
saucy-0.2.20 lib/saucy/account_authorization.rb
saucy-0.2.18 lib/saucy/account_authorization.rb
saucy-0.2.17 lib/saucy/account_authorization.rb
saucy-0.2.16 lib/saucy/account_authorization.rb
saucy-0.2.15 lib/saucy/account_authorization.rb
saucy-0.2.14 lib/saucy/account_authorization.rb
saucy-0.2.13 lib/saucy/account_authorization.rb
saucy-0.2.12 lib/saucy/account_authorization.rb
saucy-0.2.11 lib/saucy/account_authorization.rb
saucy-0.2.10 lib/saucy/account_authorization.rb
saucy-0.2.9 lib/saucy/account_authorization.rb
saucy-0.2.8.1 lib/saucy/account_authorization.rb
saucy-0.2.8 lib/saucy/account_authorization.rb
saucy-0.2.7 lib/saucy/account_authorization.rb
saucy-0.2.6.1 lib/saucy/account_authorization.rb
saucy-0.2.6 lib/saucy/account_authorization.rb
saucy-0.2.5 lib/saucy/account_authorization.rb
saucy-0.2.4.1 lib/saucy/account_authorization.rb
saucy-0.2.4 lib/saucy/account_authorization.rb
saucy-0.2.3 lib/saucy/account_authorization.rb