2019-12-17 06:44:24 +01:00
|
|
|
defmodule PhilomenaWeb.Admin.User.VoteController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2020-12-06 17:42:14 +01:00
|
|
|
alias Philomena.UserUnvoteWorker
|
2019-12-17 06:44:24 +01:00
|
|
|
alias Philomena.Users.User
|
|
|
|
|
|
|
|
plug :verify_authorized
|
|
|
|
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
|
|
|
|
|
|
|
|
def delete(conn, _params) do
|
2020-12-06 17:42:14 +01:00
|
|
|
Exq.enqueue(Exq, "indexing", UserUnvoteWorker, [conn.assigns.user.id, true])
|
2019-12-17 06:44:24 +01:00
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Vote and fave wipe started.")
|
2024-04-29 02:55:27 +02:00
|
|
|
|> redirect(to: ~p"/profiles/#{conn.assigns.user}")
|
2019-12-17 06:44:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
defp verify_authorized(conn, _opts) do
|
|
|
|
case Canada.Can.can?(conn.assigns.current_user, :index, User) do
|
2020-01-11 05:20:19 +01:00
|
|
|
true -> conn
|
2019-12-17 06:44:24 +01:00
|
|
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|