Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class User < ActiveRecord::Base
- rolify strict: true
- devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable
- has_many :companies, through: :users_companies
- has_many :users_companies
- has_and_belongs_to_many :roles, :join_table => :users_roles
- end
- class Role < ActiveRecord::Base
- resourcify
- has_and_belongs_to_many :users, :join_table => :users_roles
- belongs_to :resource, :polymorphic => true
- scopify
- end
- class Company < ActiveRecord::Base
- resourcify
- devise :database_authenticatable, :registerable
- has_many :users_companies
- has_many :users, through: :users_companies
- end
- class Ability
- include CanCan::Ability
- def initialize(user)
- user ||= User.new # in case of guest
- if user.has_role? :super_admin
- can :manage, :all
- else
- can :read, :all
- end
- if user.has_role? :admin
- can :manage, Company # не знаю как тут проверять есть ли у пользователя роль в этой компании и какая логика у проверки? что он делает и каким образом не понятно
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement