Sha256: 4245d67dfa1ebe8815ab960dc1ba2fe9e330a1def9cba63edbd8e054f2a00e25

Contents?: true

Size: 1.89 KB

Versions: 59

Compression:

Stored size: 1.89 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
        current_account.projects.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?
          if current_account.past_due?
            redirect_unusable_account account_billing_path(current_account),
                                      "past_due"
          end
          if current_account.expired?
            redirect_unusable_account edit_account_plan_path(current_account),
                                      "expired"
          end
        end
      end

      def redirect_unusable_account(path, failure)
        role = current_user.admin_of?(current_account) ? 'admin' : 'user'
        flash[:alert] = t("saucy.errors.#{failure}.#{role}")
        redirect_to path
      end

      def ensure_account_within_limit(limit_name)
        if !Limit.can_add_one?(limit_name, current_account)
          redirect_to :back, :alert => t("saucy.errors.limited", :default => "You are at your limit of %{name} for your current plan.", :name => limit_name)
        end
      end
    end
  end
end

Version data entries

59 entries across 59 versions & 2 rubygems

Version Path
saucy-0.10.10 lib/saucy/account_authorization.rb
saucy-0.14.2 lib/saucy/account_authorization.rb
saucy-0.14.1 lib/saucy/account_authorization.rb
saucy-0.14.0 lib/saucy/account_authorization.rb
saucy-0.13.3 lib/saucy/account_authorization.rb
saucy-0.13.2 lib/saucy/account_authorization.rb
saucy-0.10.9 lib/saucy/account_authorization.rb
saucy-0.10.8 lib/saucy/account_authorization.rb
saucy-0.13.1 lib/saucy/account_authorization.rb
saucy-0.13.0 lib/saucy/account_authorization.rb
saucy-0.12.5 lib/saucy/account_authorization.rb
saucy-0.12.4 lib/saucy/account_authorization.rb
saucy-0.12.3 lib/saucy/account_authorization.rb
saucy-0.12.2 lib/saucy/account_authorization.rb
saucy-0.12.1 lib/saucy/account_authorization.rb
saucy-0.12.0 lib/saucy/account_authorization.rb
saucy-0.11.5 lib/saucy/account_authorization.rb
saucy-0.11.3 lib/saucy/account_authorization.rb
saucy-0.11.2 lib/saucy/account_authorization.rb
saucy-0.10.7 lib/saucy/account_authorization.rb