ability.rb 3.0 KB

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