mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
24 lines
701 B
Elixir
24 lines
701 B
Elixir
defmodule PhilomenaWeb.Admin.User.AvatarController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.Users.User
|
|
alias Philomena.Users
|
|
|
|
plug :verify_authorized
|
|
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
|
|
|
|
def delete(conn, _params) do
|
|
{:ok, _user} = Users.remove_avatar(conn.assigns.user)
|
|
|
|
conn
|
|
|> put_flash(:info, "Successfully removed avatar.")
|
|
|> redirect(to: Routes.admin_user_path(conn, :edit, conn.assigns.user))
|
|
end
|
|
|
|
defp verify_authorized(conn, _opts) do
|
|
case Canada.Can.can?(conn.assigns.current_user, :index, User) do
|
|
true -> conn
|
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
|
end
|
|
end
|
|
end
|