check if a group of ids is in array of ids of my user

37 views
Skip to first unread message

Jerome Lefeuvre

unread,
Nov 16, 2012, 6:04:09 AM11/16/12
to declarative_...@googlegroups.com
Hi,

let's say this:

user.foo_ids = [1,2]

object1.foo_ids = [1]    => permitted
object2.foo_ids = [1,2] => permitted

object3.foo_ids = [1,3]    => not permitted
object4.foo_ids = [1,2,3] => not permitted

What sort of key should I use for write permission rules ? is_in ? contains ? intersects_with ? a new one ?

has_permission_on :object, :to => :CRUD do
  if_attribute :foo_ids => .....{user.foo_ids}
end

Thanks

Andrea S.

unread,
Dec 6, 2012, 3:50:12 PM12/6/12
to declarative_...@googlegroups.com
I have a very similar question. For any given users I can determine 

user.accessible_foo_ids 
or 
user.non_accessible_foo_ids

As such a user should have permissions on an object with foo_ids if the object's foo_ids do not intersect with the user's non_accessible_foo_ids, so something like:

has_permission_on :object, :to => :CRUD do
  if_attribute :foo_ids => does_not_intersect_with { user.non_accessible_foo_ids }
end

Of course there is no "does_not_intersect_with" method. Is there another logical way to express that relationship that ALL object.foo_ids need to be in the user's foo_ids?

As far as I know does_not_contain / does_contain and is_in / is_not_in all compare a single value with an array, but in this case we're dealing with the relationship of two arrays.

Any help would be greatly appreciated. 
 

I don't think any of the existing permission rules works for a case like this one. 
Reply all
Reply to author
Forward
0 new messages