moser/foxtrot_mike

View on GitHub
app/models/ability.rb

Summary

Maintainability
A
3 hrs
Test Coverage
class Ability
  include CanCan::Ability

  def initialize(account)
    if account
      if account.admin?
        can :manage, :all
      else
        if account.reader? || account.controller? || account.treasurer || account.license_official?
          can :read, [Flight, TowFlight, :dashboards, :filtered_flights, :own_financial_account]
        end
        if account.controller?
          can [:read, :create], [LegalPlaneClass, CostHint, Group, Person, Plane, Airfield, WireLauncher, Flight, TowFlight, Liability]
          can :read, [FlightCostRule, WireLaunchCostRule]
          can [:update,:destroy], [Flight, TowFlight, Liability]
        end
        if account.treasurer?
          can :manage, [  Person, Plane, Airfield, Flight, TowFlight, Group,
                          PersonCostCategory, PlaneCostCategory, WireLauncherCostCategory,
                          FinancialAccount, :cost_rules, CostHint,
                          FlightCostRule, WireLaunchCostRule,
                          CostRuleCondition, FlightCostItem, WireLaunchCostItem,
                          PersonCostCategoryMembership, PlaneCostCategoryMembership,
                          WireLauncherCostCategoryMembership, AccountingSession, AdvancePayment,
                          :debitors
          ]
        end
        if account.license_official?
          can :manage, [Person, License, LegalPlaneClass]
        end
      end
    end
  end
end