Closed rlopzc closed 8 years ago
@romariolopez have you tried inspecting the state of the conn
at that point? (You can do this by putting an IEx.pry
binding before line 298 in deps/canary/lib/canary/plugs.ex
).
@cpjk Sorry, i've been busy. I just inspected conn
and it appears that current_user is loaded, i'm even using canary in another controller and is working fine, I want to use canary for an :admin_index
, and the model that i'm passing is Soranus.User
, i don't know if there are any inconveniences.
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{current_user: %Soranus.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
email: "admin@gmail.com", id: 1,
inserted_at: #Ecto.DateTime<2016-09-19 17:43:24>,
medical_informations: #Ecto.Association.NotLoaded<association :medical_informations is not loaded>,
password: nil,
password_hash: "$2b$12$Oiekzoz/el5fAktWQ9XgguHs2DMfWYIqAAvqh4aVDYsor9AoNnIi.",
updated_at: #Ecto.DateTime<2016-09-19 17:43:24>, user_type: :admin}},
before_send: [#Function<0.7834419/1 in Plug.CSRFProtection.call/2>,
#Function<4.55932481/1 in Phoenix.Controller.fetch_flash/2>,
#Function<0.82590416/1 in Plug.Session.before_send/2>,
#Function<1.73933339/1 in Plug.Logger.call/2>,
#Function<0.131639940/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>],
body_params: %{},
...
In my case = :error
at line 297
get_map_args = %{id: nil}
and this is the error, my params = %{}
, but i don't know why canary expects an id
in params
, i'm just using authorize_resource/2
, why does canary expects an id?, i'm trying to authorize an index with this canada config
def can?(%User{id: user_id, user_type: :admin}, _action, User), do: true
I found the error, my action is :admin_index
but canary
is expecting the action names
action in [:index, :new, :create] ->
opts[:model]
at line 199, i thought that i could authorize any action without using a persisted model.
How do i authorize a user to execute any action (different from :index, :new, :create
without a related PERSISTED model?
For example, :admin_index
, :sales_report
, and those actions are only visible for the :admin
user.
@cpjk
This is solved by #45
In my page controller
In my router
My test
The function
guardian_login
sets the user in conn, and in my piplinebrowser_auth
i use a Plug to set the current_user to conn fromGuardian.Plug.current_resource(conn)
Like thisError in
conn = get conn, admin_page_path(conn, :admin_index)
in my tests (above)Error: