ability.rb 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. class Ability
  2. include CanCan::Ability
  3. D_ENUM = []
  4. def initialize(user)
  5. # Define abilities for the passed in user here. For example:
  6. #
  7. # user ||= User.new # guest user (not logged in)
  8. # if user.admin?
  9. # can :manage, :all
  10. # else
  11. # can :read, :all
  12. # end
  13. if user
  14. can :dashboard # allow access to dashboard
  15. can :access, :rails_admin # only allow admin users to access Rails Admin
  16. cannot :history, :all
  17. cannot :import, :all
  18. cannot :export, :all
  19. cannot :destroy, :all
  20. if user.email == AdminUser::SUPER_ADMIN
  21. can :manage, :all
  22. can :import, :all
  23. # can :export, :all
  24. # can :read, :all
  25. # can :destroy, :all
  26. # can :create, :all
  27. # can :update, :all
  28. else
  29. user.permissions.each do |permission|
  30. if permission.model=="Order111"
  31. D_ENUM.clear
  32. departs = DepartRecord.find_by_sql("select id from depart_records ")
  33. departs.each do |dep|
  34. D_ENUM.push(dep.id)
  35. end
  36. can :update, Order, :depart => D_ENUM
  37. can :read, Order, :depart => D_ENUM
  38. else
  39. eval "can :#{permission.can}, #{permission.model}"
  40. end
  41. end
  42. can :update, AdminUser, :id => user.id
  43. can :read, AdminUser, :id => user.id
  44. cannot :history, :all
  45. # cannot :destroy, ChannelQrcode
  46. # cannot :refund_at_once, Project
  47. # cannot :destroy, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  48. # cannot :delete, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  49. # cannot :export, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  50. end
  51. #cannot :destroy, DianshiOrder
  52. # cannot :new, DianbiOrder
  53. # cannot :new, VipOrder
  54. # cannot :new, DianshiOrder
  55. # cannot :update, User
  56. # cannot :generate_analyze_report_record, AnalyzeReport
  57. # can :generate_analyze_report_record, AnalyzeReport, :remark => "当前汇总"
  58. end
  59. #
  60. # The first argument to `can` is the action you are giving the user
  61. # permission to do.
  62. # If you pass :manage it will apply to every action. Other common actions
  63. # here are :read, :create, :update and :destroy.
  64. #
  65. # The second argument is the resource the user can perform the action on.
  66. # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  67. # class of the resource.
  68. #
  69. # The third argument is an optional hash of conditions to further filter the
  70. # objects.
  71. # For example, here the user can only update published articles.
  72. #
  73. # can :update, Article, :published => true
  74. #
  75. # See the wiki for details:
  76. # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  77. end
  78. end