ability.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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=="Order"
  31. D_ENUM.clear
  32. departs = AdminDepart.find_by_sql("select depart_id from depart_records where admin_user_id = #{user.id}")
  33. departs.each do |dep|
  34. D_ENUM.push(dep.id)
  35. end
  36. eval "can :#{permission.can}, #{permission.model},:depart => #{D_ENUM}"
  37. else
  38. eval "can :#{permission.can}, #{permission.model}"
  39. end
  40. end
  41. can :update, AdminUser, :id => user.id
  42. can :read, AdminUser, :id => user.id
  43. cannot :history, :all
  44. # cannot :destroy, ChannelQrcode
  45. # cannot :refund_at_once, Project
  46. # cannot :destroy, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  47. # cannot :delete, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  48. # cannot :export, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  49. end
  50. #cannot :destroy, DianshiOrder
  51. # cannot :new, DianbiOrder
  52. # cannot :new, VipOrder
  53. # cannot :new, DianshiOrder
  54. # cannot :update, User
  55. # cannot :generate_analyze_report_record, AnalyzeReport
  56. # can :generate_analyze_report_record, AnalyzeReport, :remark => "当前汇总"
  57. end
  58. #
  59. # The first argument to `can` is the action you are giving the user
  60. # permission to do.
  61. # If you pass :manage it will apply to every action. Other common actions
  62. # here are :read, :create, :update and :destroy.
  63. #
  64. # The second argument is the resource the user can perform the action on.
  65. # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  66. # class of the resource.
  67. #
  68. # The third argument is an optional hash of conditions to further filter the
  69. # objects.
  70. # For example, here the user can only update published articles.
  71. #
  72. # can :update, Article, :published => true
  73. #
  74. # See the wiki for details:
  75. # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  76. end
  77. end