I have two models (element and theme). They both belong to the third user model with the has_many association (the User has many topics and elements). Both Item and Theme are_many: images.
The image model is a polymorphic association, so the table has imageable_id and imageable_type columns. If I had both elements with id 1 and the theme with id 1, the table would look like
id imageable_id imageable_type ------------------------------------ 1 1 Item 2 1 Theme
I use declarative_authorization to re-record SQL queries in my database so that users do not access items outside their account. I would like to write an authorization rule that allows the user to read the image only if he can read the item that belongs to them. It seems I cannot get the correct syntax (maybe it is not supported):
has_permission_on [:images], :to => [:manage], :join_as => :and do if_attribute :imageable => is { "Item" } if_permitted_to :manage, :items
Then I will have another rule imitating above, but for those:
has_permission_on [:images], :to => [:manage], :join_as => :and do if_attribute :imageable => is { "Theme" } if_permitted_to :manage, :themes
Any ideas? Thanks in advance!
ruby ruby-on-rails polymorphic-associations declarative-authorization
Corith malin
source share