if_attribute syntax problem on declarative_authori

2019-06-09 20:23发布

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条回答
老娘就宠你
2楼-- · 2019-06-09 21:04

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
查看更多
登录 后发表回答