if_attribute syntax problem on declarative_authori

2019-06-09 20:27发布

问题:

I have an Organization that has_many Affiliations And a mission that has_one Organization

So i can do this:

m = Mission.first
m.organization.affiliations 

A user also has_many affiliations so I can do:

u = User.first
u.affiliations

In declarative_authorization I want a user to be able to manage a mission if he is affiliated to the organization of the mission.

I'm trying this:

has_permission_on :missions, :to => [:manage] do
  if_attribute [:affiliations, {:mission => :organization} ]  => intersects_with {
    user.affiliations.type_admin
  }
end

But I get the error:

[:affiliations, {:mission=>:organization}] is not a symbol

What's wrong with the syntax?

回答1:

I think this might work for you

has_permission_on :missions, :to => [:manage] do
  if_attribute :organization => { :affiliations => intersects_with { user.affiliates.type_admin } }
end