2019-12-17 06:44:24 +01:00
|
|
|
defmodule PhilomenaWeb.Admin.User.WipeController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2020-12-06 17:42:14 +01:00
|
|
|
alias Philomena.UserWipeWorker
|
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 create(conn, _params) do
|
2020-12-06 17:42:14 +01:00
|
|
|
Exq.enqueue(Exq, "indexing", UserWipeWorker, [conn.assigns.user.id])
|
2019-12-17 06:44:24 +01:00
|
|
|
|
|
|
|
conn
|
2020-01-11 05:20:19 +01:00
|
|
|
|> put_flash(
|
2023-11-23 17:07:49 +01:00
|
|
|
:alert,
|
2020-12-06 17:42:14 +01:00
|
|
|
"PII wipe queued, please verify and then deactivate the account as necessary."
|
2020-01-11 05:20:19 +01:00
|
|
|
)
|
2019-12-17 06:44:24 +01:00
|
|
|
|> redirect(to: Routes.profile_path(conn, :show, conn.assigns.user))
|
|
|
|
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
|