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 have this:
has_permission_on :missions, :to => [:manage] do
if_attribute :organization => { :affiliations => intersects_with { user.affiliates.type_admin } }
end
But I'm getting this error:
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>
The Mission and Organization are nil. I think that is because on the new, the mission.organization dosn't exists.
On the mission controller I have this:
def new
if(params[:organization_id])
session[:organization_id] = params[:organization_id]
@mission = Organization.find_by_id(params[:organization_id]).missions.build
end
end