views:

139

answers:

1

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?

A: 

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
Corey
The DSL compiled but it didn't gave me the permission to manage the mission.On the server window I saw that the mission and organization was nil:Permission denied: new not allowed for #<User id: 2, firstname: "Miguel", lastname: "Alho", email: "[email protected]", birthday: "2010-07-05 20:24:00", crypted_password: "...", password_salt: "...", persistence_token: "...", perishable_token: "...", created_at: "2010-03-05 20:25:34", updated_at: "2010-03-30 15:45:36"> on #<Mission id: nil, user_id: nil, organization_id: nil, name: nil, objectives: nil, created_at: nil, updated_at: nil>.
Victor Martins
If i force a miss spell on organization, I get an expected error and see that the mission and organization objects are present...Error when calling organization_ on #<Mission id: 1, user_id: 1, organization_id: 1, name: "Mission Name", (... ) for validating attribute: undefined method `organization_' for #<Mission:0x1031329b0>
Victor Martins
I get it... it's a new mission, so there is no organizaton associated to it. It will only be when the mission is saved. But that doesn't explain why on the error The missin and organization exists...
Victor Martins