ability.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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], CashOut
  38. can :sales_reserved, Sale
  39. cannot [:delete, :liquidate_reserve], Sale
  40. cannot :create, [ProductWaste, Purchase, 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, PrePurchase, Product, Promotion, ProductsReturn, ProductWaste, Purchase, Sale, Seller, Sellerscommission, Supplier, Transfer]
  45. # Categorias
  46. can :read, [AvailableProduct, Credit, CreditPayment, Expensesconcept, 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, [BillingInformation, Credit, CreditPayment, Customer, Expensesconcept, Seller, SpecialPrice, Product, Promotion]
  55. # ventas
  56. can :cru, [Credit, CreditPayment]
  57. can :manage, [CashOut, CashRegister, Credit, CreditPayment, Customer, Expense, OpenCashRegister, PreSale, Sale, Transfer, ProductsReturn, ProductWaste]
  58. cannot :opened_cash_registers, CashOut
  59. cannot :sales_per_month_report, Sale
  60. elsif user.usertype == "S"
  61. can :read, [BillingInformation, CashRegister, Customer, Expensesconcept, Seller, SpecialPrice, Product, Promotion]
  62. can :manage, [ProductWaste, Transfer]
  63. cannot [:debtors, :customer_sales], Customer
  64. end
  65. end
  66. end