-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abilities for multiple models #52
Comments
Well, here we go:
Isn't that possible? Just create the multiple files and define each protocol implementation on the separated files.
Well, if the resource is not found, shouldn't you return a 404? |
I think not. The
Not really. Because the lib return Am I missing something? |
Well, I didn't understand why not. If you have person, company and company_member, you can define
What I tried to say is that, you can check the resource existence first, and if it does not exist, just return a 404, and only if it exists, run the canary authorize. |
I did the same but as @edmaarcosta mentions, it's only taking in the first file.
In each file, the plug is defined as
But while the api hits right, the plug it goes to is the user_abilities.ex if that's defined first. IMP NOTE : However! it doesn't matter what model: I fill in, for multiple models, if I put the same So maybe i should consolidate all multiple model abilities file into a single |
The (non really satisfying) I had for this was to wright a defmodule Resource1Abilities do
def can?(%User{} = user, action, %Resource1{} = resource1) do
ability_logic(user, action, resource)
end
end
defmodule Resource2Abilities do
def can?(%User{} = user, action, %Resource2{} = resource1) do
ability_logic(user, action, resource)
end
end
defimpl Canada.Can, for: User do
def can?(%User{} = user, action, %Resource1{} = resource1) do
Resource1Abilities.can?(user, action, resource1)
end
def can?(%User{} = user, action, %Resource2{} = resource2) do
Resource2Abilities.can?(user, action, resource2)
end
end |
In the little spare time I have these days, I've been working on a different spin to authorization logic; which I call Access Decision Manager. Instead of "abilities", it uses "voters". The voters take the subjects and attributes (aka "actions") and decide whether or not to Curious if anyone has any thoughts on it. Still very alpha, but maybe it'd help you out. |
Thanks for the lib.
I got a little problem to work with multiple models in me project.
I want work with one file for each model abilities. For example:
person_abilities.ex
andproduct_abilities.ex
.Today I have permission for two controllers:
PersonController
andProductController
. Inabilities.ex
I have permission only forPerson
. That's works if I add%Product{}
, but I have some pattern matching for nil models because when the user search for a information that not exists the last argument incan?
is always nil so I can't blocking the process for him. So, a have the following: https://gist.github.com/edmaarcosta/a26b60932e2e5b06ea6db1fb4506209fWith this approach to control the pattern matching for
Product
doesn't works because the Canada don't know what model should manipulate.Thoughts?
Sorry my english is terrible.
The text was updated successfully, but these errors were encountered: