Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Use through to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoack committed Mar 28, 2018
1 parent 75034f4 commit 297fda9
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions lib/right_on/role_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ module RoleModel
def self.included(base)
base.module_eval do
has_and_belongs_to_many :roles, class_name: 'RightOn::Role'
has_many :rights, through: :roles, class_name: 'RightOn::Right'
end
Role.module_eval do
has_and_belongs_to_many base.table_name.to_sym, dependent: :restrict
end
end

def rights
@rights ||=
Right
.select('distinct rights.*')
.joins(:roles)
.where('rights_roles.role_id IN (?)', role_ids)
end

def has_privileges_of?(other_user)
(other_user.rights - rights).empty?
end
Expand Down

0 comments on commit 297fda9

Please sign in to comment.