jarednorman / canada Goto Github PK
View Code? Open in Web Editor NEWEasy permission definitions in Elixir apps!
Home Page: https://github.com/jarednorman/canada
License: MIT License
Easy permission definitions in Elixir apps!
Home Page: https://github.com/jarednorman/canada
License: MIT License
hey join me on Discord! Invite expires in 7 days. https://discord.gg/qnNnKJXK
is this even a question ?
apologies, am just learning about the Channels vs Resources Phoenix issue
Hello, sometimes the macro can?/2
does not work properly for example when the method is a variable. Thus, something like this won't work:
import Canada, only: [can?: 2]
method = action_name(conn)
if %User{} |> can?(method(Authority)) do
However, I was able to make it work using the function can?/3
like this:
import Canada.Can, only: [can?: 3]
method = action_name(conn)
if %User{} |> can?(method, Authority) do
The thing is that I had to check out the source code of the library myself to find out of this; I propose adding a small section in the docs describing can?/3
.
TIA
Hey,
So I have this setup:
GroupController
=> /groups/:group_id
UserController
=> /groups/:group_id/users
AppController
=> /groups/:group_id/apps
I want to allow only admins access to users
:
defimpl Canada.Can, for: MyApp.User do
alias MyApp.{User, Group}
def can?(%User{} = user, _, %Group{} = group) do
Group.is_admin?(group, user)
end
def can?(_, _, User), do: false
end
This works well I use it with Canary so I add this plug to my UserController
defmodule UserController do
...
plug :authorize_resource, model: Group, persisted: true, id_name: "group_id"
...
Now if I want to limit access to AppController
to only the users that belongs to that group,
I can add same plug to AppController
:
defmodule AppController do
...
plug :authorize_resource, model: Group, persisted: true, id_name: "group_id"
...
end
And I need to add a new can?
to implemention:
defimpl Canada.Can, for: MyApp.User do
alias MyApp.{User, Group}
def can?(%User{} = user, _, %Group{} = group) do
Group.is_admin?(group, user)
end
def can?(%User{} = user, _, %Group{} = group) do
Group.is_memeber?(group, user)
end
def can?(_, _, User), do: false
end
But As you can see the new can?
has the same pattern as previous function.
What do you think if we add another optional param to to can?
Then I can use it like this:
defmodule UserController do
...
plug :authorize_resource, model: Group, persisted: true, id_name: "group_id", only_admin: true
...
end
defimpl Canada.Can, for: MyApp.User do
alias MyApp.{User, Group}
def can?(%User{} = user, _, %Group{} = group, %{only_admin: true}) do
Group.is_admin?(group, user)
end
def can?(%User{} = user, _, %Group{} = group, _) do
Group.is_memeber?(group, user)
end
def can?(_, _, User), do: false
end
I know that you are quite busy, let me know what do you think and if you agree with the change I will create PR.
The Elixir version constraint here throws warnings in Elixir 1.1.0. The constraint should probably be "~> 1.0"
.
Hi!
I can see Elixir 1.4 warnings are fixed in this commit ef0705c but the version hasn't changed yet in mix.exs
and Hex.
Could you update the package in HEX?
I created a issue in canary repository. But I'm not sure if there is the best place for it.
I appreciate it the help.
warning: variable "package" does not exist and is being expanded to "package()", please use parentheses to remove the ambiguity or change the variable name
The version needs to be bumped (1.0.1 perhaps?) and uploaded to hex.pm to add support for the more relaxed Elixir version requirement.
If you are still no longer doing Elixir dev then I could take over this library if you wished to add me to the package handling on hex.pm so I could take over package pushing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.