mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-23 01:18:00 +01:00
dfeefb1651
git grep -l 'defp log_details(_conn' | xargs sed -i -e 's/defp log_details(_conn, /defp log_details(/g' git grep -l '&log_details/3' | xargs sed -i -e 's|\&log_details/3|\&log_details/2|g'
44 lines
1.2 KiB
Elixir
44 lines
1.2 KiB
Elixir
defmodule PhilomenaWeb.Admin.User.VerificationController 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 create(conn, _params) do
|
|
{:ok, user} = Users.verify_user(conn.assigns.user)
|
|
|
|
conn
|
|
|> put_flash(:info, "User verification granted.")
|
|
|> moderation_log(details: &log_details/2, data: user)
|
|
|> redirect(to: ~p"/profiles/#{user}")
|
|
end
|
|
|
|
def delete(conn, _params) do
|
|
{:ok, user} = Users.unverify_user(conn.assigns.user)
|
|
|
|
conn
|
|
|> put_flash(:info, "User verification revoked.")
|
|
|> moderation_log(details: &log_details/2, data: user)
|
|
|> redirect(to: ~p"/profiles/#{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
|
|
|
|
defp log_details(action, user) do
|
|
body =
|
|
case action do
|
|
:create -> "Granted verification to #{user.name}"
|
|
:delete -> "Revoked verification from #{user.name}"
|
|
end
|
|
|
|
%{body: body, subject_path: ~p"/profiles/#{user}"}
|
|
end
|
|
end
|