ability.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if user
  13. can :dashboard # allow access to dashboard
  14. can :access, :rails_admin # only allow admin users to access Rails Admin
  15. cannot :history, :all
  16. cannot :import, :all
  17. cannot :export, :all
  18. cannot :destroy, :all
  19. if user.email == AdminUser::SUPER_ADMIN
  20. can :manage, :all
  21. can :import, :all
  22. # can :export, :all
  23. # can :read, :all
  24. # can :destroy, :all
  25. # can :create, :all
  26. # can :update, :all
  27. else
  28. user.permissions.each do |permission|
  29. eval "can :#{permission.can}, #{permission.model}"
  30. end
  31. can :update, AdminUser, :id => user.id
  32. can :read, AdminUser, :id => user.id
  33. cannot :history, :all
  34. # cannot :destroy, ChannelQrcode
  35. # cannot :refund_at_once, Project
  36. # cannot :destroy, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  37. # cannot :delete, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  38. # cannot :export, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  39. end
  40. #cannot :destroy, DianshiOrder
  41. # cannot :new, DianbiOrder
  42. # cannot :new, VipOrder
  43. # cannot :new, DianshiOrder
  44. # cannot :update, User
  45. # cannot :generate_analyze_report_record, AnalyzeReport
  46. # can :generate_analyze_report_record, AnalyzeReport, :remark => "当前汇总"
  47. end
  48. #
  49. # The first argument to `can` is the action you are giving the user
  50. # permission to do.
  51. # If you pass :manage it will apply to every action. Other common actions
  52. # here are :read, :create, :update and :destroy.
  53. #
  54. # The second argument is the resource the user can perform the action on.
  55. # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  56. # class of the resource.
  57. #
  58. # The third argument is an optional hash of conditions to further filter the
  59. # objects.
  60. # For example, here the user can only update published articles.
  61. #
  62. # can :update, Article, :published => true
  63. #
  64. # See the wiki for details:
  65. # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  66. end
  67. end