2019-11-21 15:51:13 +01:00
|
|
|
defmodule Mix.Tasks.Mobilizon.Users.Show do
|
|
|
|
@moduledoc """
|
|
|
|
Task to display an user details
|
|
|
|
"""
|
2020-01-28 20:15:59 +01:00
|
|
|
|
2019-11-21 15:51:13 +01:00
|
|
|
use Mix.Task
|
2020-10-30 15:16:01 +01:00
|
|
|
import Mix.Tasks.Mobilizon.Common
|
2020-01-28 20:15:59 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-11-21 15:51:13 +01:00
|
|
|
alias Mobilizon.Users
|
|
|
|
alias Mobilizon.Users.User
|
|
|
|
|
|
|
|
@shortdoc "Show a Mobilizon user details"
|
|
|
|
|
|
|
|
@impl Mix.Task
|
|
|
|
def run([email]) do
|
2020-10-30 15:16:01 +01:00
|
|
|
start_mobilizon()
|
2019-11-21 15:51:13 +01:00
|
|
|
|
|
|
|
with {:ok, %User{} = user} <- Users.get_user_by_email(email),
|
|
|
|
actors <- Users.get_actors_for_user(user) do
|
2021-09-10 11:27:59 +02:00
|
|
|
status =
|
|
|
|
case user.confirmed_at do
|
|
|
|
%DateTime{} = confirmed_at ->
|
|
|
|
"Activated on #{DateTime.to_string(confirmed_at)} (UTC)"
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
"disabled"
|
|
|
|
end
|
|
|
|
|
2020-10-30 15:16:01 +01:00
|
|
|
shell_info("""
|
2019-11-21 15:51:13 +01:00
|
|
|
Informations for the user #{user.email}:
|
2021-09-10 11:27:59 +02:00
|
|
|
- account status: #{status}
|
2019-11-21 15:51:13 +01:00
|
|
|
- Role: #{user.role}
|
|
|
|
#{display_actors(actors)}
|
|
|
|
""")
|
|
|
|
else
|
|
|
|
{:error, :user_not_found} ->
|
2020-10-30 15:16:01 +01:00
|
|
|
shell_error("Error: No such user")
|
2019-11-21 15:51:13 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(_) do
|
2020-10-30 15:16:01 +01:00
|
|
|
shell_error("mobilizon.users.show requires an email as argument")
|
2019-11-21 15:51:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
defp display_actors([]), do: ""
|
|
|
|
|
|
|
|
defp display_actors(actors) do
|
|
|
|
"""
|
|
|
|
Identities (#{length(actors)}):
|
|
|
|
#{actors |> Enum.map(&display_actor/1) |> Enum.join("")}
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp display_actor(%Actor{} = actor) do
|
|
|
|
"""
|
|
|
|
- @#{actor.preferred_username} / #{actor.name}
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|