has_permission_on attribute can be nil or false

Skip to first unread message

Nicholas Martin

Jul 10, 2012, 5:59:26 AM7/10/12
to declarative_...@googlegroups.com
Firstly, thanks for such a great gem, it has saved me so much time and I am still discovering new ways to use it.

My question is as follows:

Our application has Events, which have many Event Participants.  
Event Participants gain access to Events based on a number of attributes, including a disable_access flag.  
The flag may have one of 3 values - false, nil or true.  I want to give access if flag is false or nil, but the SQL generated from my rule does not work correctly.

    has_permission_on :events, :to => [:demo_permission] do
      if_attribute :event_participants => {:user => is {user}, :disable_access => [false, nil]}
yields this SQL:   

SELECT `events`.* FROM `events` INNER JOIN `event_participants` ON `event_participants`.`event_id` = `events`.`id` WHERE ((`event_participants`.`user_id` = 2 AND `event_participants`.`disable_access` IN (0,NULL))) ORDER BY events.id desc

The SQL I would like to generate is something like:

SELECT `events`.* FROM `events` INNER JOIN `event_participants` ON `event_participants`.`event_id` = `events`.`id` WHERE ((`event_participants`.`user_id` = 2 AND (`event_participants`.`disable_access` IS NULL OR `event_participants`.`disable_access` IN (0)))) ORDER BY events.id desc

I can achieve the desired result by writing two if_attributes lines, but in the real application, there are a number of other attributes, which means I quickly end up with a very large number of permutations, each requiring a separate line.

Is there a way to write the if_attribute as a single line that will correctly handle NULL or FALSE?
Reply all
Reply to author
0 new messages