mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-05 00:57:59 +01:00
24 lines
765 B
Elixir
24 lines
765 B
Elixir
|
defmodule PhilomenaWeb.Admin.Donation.UserController do
|
||
|
use PhilomenaWeb, :controller
|
||
|
|
||
|
alias Philomena.Users.User
|
||
|
alias Philomena.Donations.Donation
|
||
|
alias Philomena.Donations
|
||
|
|
||
|
plug :verify_authorized
|
||
|
plug :load_resource, model: User, id_field: "slug", persisted: true, preload: [donations: :user]
|
||
|
|
||
|
def show(conn, _params) do
|
||
|
user = conn.assigns.user
|
||
|
changeset = Donations.change_donation(%Donation{})
|
||
|
render(conn, "index.html", title: "Donations for User `#{user.name}'", donations: user.donations, changeset: changeset)
|
||
|
end
|
||
|
|
||
|
defp verify_authorized(conn, _opts) do
|
||
|
case Canada.Can.can?(conn.assigns.current_user, :index, Donation) do
|
||
|
true -> conn
|
||
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
||
|
end
|
||
|
end
|
||
|
end
|