ability.rb 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, [AvailableProduct, CashOut, CashRegister, PaymentMethod, ProductsReturn]
  35. # Categorias
  36. can :manage, [BillingInformation, Category, Commission, Customer, Expense, Expensesconcept, Pointsale, PosConfig, Product, Promotion, ProductWaste, Purchase, Sale, Seller, Sellerscommission, SpecialPrice, Supplier, Transfer, Unit, User, Warehouse]
  37. can [:opened_cash_registers, :find_cash_outs_by_date, :print_receipt], CashOut
  38. can :sales_reserved, Sale
  39. cannot [:delete, :liquidate_reserve], Sale
  40. cannot :create, [ProductWaste, Sale]
  41. cannot [:debtors, :customer_sales], Customer
  42. elsif user.usertype == "G"
  43. # Cajas registradoras
  44. can :manage, [CashOut, CashRegister, Category, Credit, CreditPayment, Commission, Customer, Expense, OpenCashRegister, PreTransfer, PrePurchase, Product, Promotion, ProductsReturn, ProductWaste, Purchase, Sale, Seller, Sellerscommission, Supplier, Transfer]
  45. # Categorias
  46. can :read, [AvailableProduct, Credit, CreditPayment, Expensesconcept, PosConfig, SpecialPrice, Unit]
  47. # Clientes
  48. can :cru, [BillingInformation, Commission, Credit, CreditPayment, Customer, Sellerscommission, User, Warehouse]
  49. cannot :opened_cash_registers, CashOut
  50. cannot :sales_per_month_report, Sale
  51. cannot :product_track, Product
  52. elsif user.usertype == "C"
  53. # Cajas registradoras
  54. can :read, [AvailableProduct, BillingInformation, Credit, CreditPayment, Customer, SpecialPrice, Product, Promotion]
  55. # ventas
  56. can :cru, [Credit, CreditPayment]
  57. can :manage, [CashOut, Credit, CreditPayment, CashRegister, Customer, Expense, OpenCashRegister, PreSale, PreTransfer, ProductsReturn, ProductWaste, Sale, Transfer]
  58. cannot :opened_cash_registers, CashOut
  59. cannot :sales_per_month_report, Sale
  60. cannot :index, [CashRegister, Product]
  61. elsif user.usertype == "S"
  62. can :read, [AvailableProduct, BillingInformation, CashRegister, PosConfig, Product, Promotion]
  63. can :manage, [PreTransfer, ProductWaste, Transfer]
  64. cannot :index, [CashRegister, Product]
  65. end
  66. end
  67. end