Git Product home page Git Product logo

canada's People

Contributors

fishtreesugar avatar jarednorman avatar jayjun avatar jvantuyl avatar kennyballou avatar kianmeng avatar linjunpop avatar mbramson avatar mindreframer avatar samhamilton avatar samullen avatar sespindola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

canada's Issues

Compile warnings for elixir 1.4

warning: variable "package" does not exist and is being expanded to "package()", please use parentheses to remove the ambiguity or change the variable name

Docs for can?/3

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

HEX Package

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?

passing optional params to can?

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.

`canada` elixir version too restricted in hex.pm

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.