ability.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. class Ability
  2. include CanCan::Ability
  3. def initialize(user)
  4. # Define abilities for the passed in user here. For example:
  5. #
  6. # user ||= User.new # guest user (not logged in)
  7. # if user.admin?
  8. # can :manage, :all
  9. # else
  10. # can :read, :all
  11. # end
  12. #
  13. # The first argument to `can` is the action you are giving the user
  14. # permission to do.
  15. # If you pass :manage it will apply to every action. Other common actions
  16. # here are :read, :create, :update and :destroy.
  17. #
  18. # The second argument is the resource the user can perform the action on.
  19. # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  20. # class of the resource.
  21. #
  22. # The third argument is an optional hash of conditions to further filter the
  23. # objects.
  24. # For example, here the user can only update published articles.
  25. #
  26. # can :update, Article, :published => true
  27. #
  28. # See the wiki for details:
  29. # https://github.com/ryanb/cancan/wiki/Defining-Abilities
  30. alias_action :create, :read, :update, to: :cru
  31. user ||= User.new
  32. if user.usertype == "A" || user.usertype == "SS"
  33. # Cajas registradoras
  34. can :read, [CashRegister, Purchase, PaymentMethod, ProductsReturn, CashOut]
  35. # Categorias
  36. can :manage, [Category, Customer, BillingInformation, Expensesconcept, Pointsale, Product, Supplier, Unit, Sale, PosConfig, Purchase, SpecialPrice, ProductWaste, Seller, Transfer, Expense, User, Warehouse, Commission, Sellerscommission]
  37. can [:opened_cash_registers, :find_cash_outs_by_date], CashOut
  38. cannot [:create, :delete, :liquidate_reserve], Sale
  39. cannot :create, ProductWaste
  40. elsif user.usertype == "G"
  41. # Cajas registradoras
  42. can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn, Category]
  43. # Categorias
  44. can :read, [SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
  45. # Clientes
  46. can :cru, [Customer, BillingInformation, Pointsale, User, Warehouse, Credit, CreditPayment, Commission, Sellerscommission]
  47. cannot :opened_cash_registers, CashOut
  48. elsif user.usertype == "C"
  49. # Cajas registradoras
  50. can :read, [Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept, Credit, CreditPayment]
  51. # ventas
  52. can :cru, [Credit, CreditPayment]
  53. can :manage, [CashRegister, PreSale, OpenCashRegister, Sale, Customer, Credit, CreditPayment, CashOut, Expense, Transfer, ProductsReturn, ProductWaste]
  54. cannot :opened_cash_registers, CashOut
  55. elsif user.usertype == "S"
  56. can :read, [CashRegister, Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept]
  57. can :manage, [Transfer, ProductWaste]
  58. end
  59. end
  60. end