Module: ActsPermissive::PermissiveObject::InstanceMethods
- Defined in:
- lib/acts_permissive/permissive_object.rb
Instance Method Summary collapse
-
#all_who_can(*args) ⇒ Object
TODO: Refactor this shit! One way to do this.
- #is_used_permissively? ⇒ Boolean
Instance Method Details
#all_who_can(*args) ⇒ Object
TODO: Refactor this shit! One way to do this. Figure out a list of permission masks that would pass, then use that to do a straight SQL query using “perm.mask IN [list]”
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/acts_permissive/permissive_object.rb', line 35 def all_who_can *args # Get a list of users who can do whatever symbol based permissions are # listed. For instance # authors = @thing.all_who_can(:read, :write) warn "\nPermissiveObject::all_who_can works, yeah, but it's a time suck. Use Carefully!" if args.include?(:see) raise PermissiveError, "Can only use :see as an option by itself" if args.count > 1 return ActsPermissive::Grouping.who_can_see(self) end users = [] # Go through each user, go though each permission that user has for this object # (i.e. in all the objects circles), and if there's a permission that matches, # add the user to the list of users. ActsPermissive::Grouping.who_can_see(self).each do |user| user.(self).each do |perm| #add up the bits and do a bitwise and to check permissions bits = args.select{|o| o.class == Symbol}.map{|s| Permission.bit_for s}.inject(0){|sum, p| sum + p} users << user if perm.mask & bits == bits end end # we lazily add users in a loop, instead of using SQL, so we have to return only the unique set users.uniq end |
#is_used_permissively? ⇒ Boolean
28 29 30 |
# File 'lib/acts_permissive/permissive_object.rb', line 28 def is_used_permissively? true end |