Concatenate if_attribute, if_permitted_to

25 views
Skip to first unread message

Eric Hu

unread,
Jan 9, 2012, 4:08:14 PM1/9/12
to declarative_authorization
I'd like to write something like the following:

has_permission_on [:videos], to: [:read] do
if_attribute attachment: is_not {nil},
if_permitted_to :show, :attachment
end

Currently there's similar behavior for chaining multiple if_attribute
statements, with the default behavior ANDing them together. It's
unclear to me whether these could somehow be combined.

For now, I'm just copying the conditions for :show on Attachments to
Videos, but that isn't DRY.

Steffen Bartsch

unread,
Jan 10, 2012, 3:43:17 AM1/10/12
to declarative_...@googlegroups.com
Am Montag, 9. Januar 2012 schrieb Eric Hu:
> Currently there's similar behavior for chaining multiple if_attribute
> statements, with the default behavior ANDing them together. It's
> unclear to me whether these could somehow be combined.

The :join_by parameter of has_permission_on should do this.

http://www.tzi.org/~sbartsch/declarative_authorization/master/classes/Authorization/Reader/AuthorizationRulesReader.html

Steffen

Eric Hu

unread,
Jan 10, 2012, 4:00:52 PM1/10/12
to declarative_...@googlegroups.com
So just to be clear, the solution should look like this

    has_permission_on [:videos], to: [:read], join_by: :and do
     if_attribute attachment: is_not {nil}
     if_permitted_to :show, :attachment
   end

Pretty straightforward.  Thanks!

2012/1/10 Steffen Bartsch <sbar...@tzi.de>

--
You received this message because you are subscribed to the Google Groups "declarative_authorization" group.
To post to this group, send email to declarative_...@googlegroups.com.
To unsubscribe from this group, send email to declarative_author...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/declarative_authorization?hl=en.


Reply all
Reply to author
Forward
0 new messages