if_attribute on declarative authorization
Posted
by Victor Martins
on Stack Overflow
See other posts from Stack Overflow
or by Victor Martins
Published on 2010-03-13T19:41:58Z
Indexed on
2010/03/13
20:45 UTC
Read the original article
Hit count: 562
ruby-on-rails
|declarative-authorization
I have a many-to-many relationship like this: A user has_many organizations through affiliations and vice-versa.
I'm using declarative organizations and I only want a user to edit a particular organization if he is affiliated and the affiliationtype attribute of affiliation is a particular value.
So affiliations has 3 columns , user_id, organization_id and affiliationtype_id
I can do:
o = Organization.find(:first)
o.affiliatons[0].user and get the user
now I wish to do this:
has_permission_on [:organizations], :to => :edit do
if_attribute (...)
end
That if_attribute should see if the current user is the organization.affiliation[?].user and if the organization.affiliation[?].affiliationtype_id = "3"
I hope this is syntax issue ... I really need to get this working.
© Stack Overflow or respective owner