Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Class User < ActiveRecord::Base
  2. rolify strict: true
  3. devise :database_authenticatable, :registerable,
  4. :recoverable, :rememberable, :trackable, :validatable
  5. has_many :companies, through: :users_companies
  6. has_many :users_companies
  7. has_and_belongs_to_many :roles, :join_table => :users_roles
  8. end
  9.  
  10.  
  11. class Role < ActiveRecord::Base
  12. resourcify
  13. has_and_belongs_to_many :users, :join_table => :users_roles
  14. belongs_to :resource, :polymorphic => true
  15.  
  16. scopify
  17. end
  18.  
  19. class Company < ActiveRecord::Base
  20. resourcify
  21. devise :database_authenticatable, :registerable
  22. has_many :users_companies
  23. has_many :users, through: :users_companies
  24. end
  25.  
  26. class Ability
  27. include CanCan::Ability
  28.  
  29. def initialize(user)
  30. user ||= User.new # in case of guest
  31. if user.has_role? :super_admin
  32. can :manage, :all
  33. else
  34. can :read, :all
  35. end
  36. if user.has_role? :admin
  37. can :manage, Company # не знаю как тут проверять есть ли у пользователя роль в этой компании и какая логика у проверки? что он делает и каким образом не понятно
  38. end
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement