ability.rb 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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"
  33. # Cajas registradoras
  34. can :read, [CashRegister, Purchase, PaymentMethod, ProductsReturn]
  35. # Categorias
  36. can :manage, [Category, Customer, BillingInformation, Expensesconcept, Pointsale, Product, Supplier, Unit, Sale, PosConfig, Purchase, SpecialPrice, ProductWaste, Seller, CashOut, Transfer, Expense, User, Warehouse, Commission, Sellerscommission]
  37. cannot [:create, :delete, :liquidate_reserve], Sale
  38. elsif user.usertype == "G"
  39. # Cajas registradoras
  40. can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn]
  41. # Categorias
  42. can :read, [Category, SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
  43. # Clientes
  44. can :cru, [Customer, BillingInformation, Pointsale, User, Warehouse, Credit, CreditPayment, Commission, Sellerscommission]
  45. elsif user.usertype == "C"
  46. # Cajas registradoras
  47. can :read, [Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept, Credit, CreditPayment]
  48. # ventas
  49. can :cru, [Credit, CreditPayment]
  50. can :manage, [CashRegister, PreSale, OpenCashRegister, Sale, Customer, Credit, CreditPayment, CashOut, Expense, Transfer, ProductsReturn, ProductWaste]
  51. elsif user.usertype == "S"
  52. can :read, [CashRegister, Product, Pointsale, Customer, BillingInformation, Seller, SpecialPrice, Expensesconcept]
  53. can :manage, [Transfer, ProductWaste]
  54. end
  55. end
  56. end