philomena/lib/philomena_web/controllers/admin/donation/user_controller.ex

29 lines
787 B
Elixir
Raw Normal View History

2019-12-17 04:24:40 +01:00
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{})
2020-01-11 05:20:19 +01:00
render(conn, "index.html",
title: "Donations for User `#{user.name}'",
donations: user.donations,
changeset: changeset
)
2019-12-17 04:24:40 +01:00
end
defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :index, Donation) do
2020-01-11 05:20:19 +01:00
true -> conn
2019-12-17 04:24:40 +01:00
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
end
end
end