ability.rb 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. departs = DepartRecord.find_by_sql("select id from depart_records ")
  15. departs.each do |dep|
  16. D_ENUM.push(dep.id)
  17. end
  18. can :dashboard # allow access to dashboard
  19. can :access, :rails_admin # only allow admin users to access Rails Admin
  20. cannot :history, :all
  21. cannot :import, :all
  22. cannot :export, :all
  23. cannot :destroy, :all
  24. if user.email == AdminUser::SUPER_ADMIN
  25. can :manage, :all
  26. can :import, :all
  27. # can :export, :all
  28. # can :read, :all
  29. # can :destroy, :all
  30. # can :create, :all
  31. # can :update, :all
  32. else
  33. user.permissions.each do |permission|
  34. if permission.model=="Order"
  35. can :update, Order, :depart => D_ENUM
  36. can :read, Order, :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