Various typespec and compilation improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -71,9 +71,6 @@ defmodule Mix.Tasks.Mobilizon.Actors.Refresh do
|
||||
Actor #{preferred_username} refreshed
|
||||
""")
|
||||
|
||||
{:actor, nil} ->
|
||||
shell_error("Error: No such actor")
|
||||
|
||||
{:error, err} when is_binary(err) ->
|
||||
shell_error(err)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ defmodule Mix.Tasks.Mobilizon.Actors.Utils do
|
||||
end
|
||||
|
||||
# Profile from name
|
||||
@spec username_and_name(String.t() | nil, String.t() | nil) :: String.t()
|
||||
@spec username_and_name(String.t() | nil, String.t() | nil) :: {String.t(), String.t()}
|
||||
def username_and_name(nil, profile_name) do
|
||||
{generate_username(profile_name), profile_name}
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ defmodule Mix.Tasks.Mobilizon.Common do
|
||||
else: IO.puts(message)
|
||||
end
|
||||
|
||||
@spec shell_error(String.t()) :: :ok
|
||||
@spec shell_error(String.t(), Keyword.t()) :: nil | no_return
|
||||
def shell_error(message, options \\ []) do
|
||||
if mix_shell?() do
|
||||
Mix.shell().error(message)
|
||||
|
||||
@@ -35,6 +35,7 @@ defmodule Mix.Tasks.Mobilizon.Instance do
|
||||
@preferred_cli_env "prod"
|
||||
|
||||
@shortdoc "Generates a new config"
|
||||
@spec run(list(binary())) :: no_return
|
||||
def run(["gen" | options]) do
|
||||
{options, [], []} =
|
||||
OptionParser.parse(
|
||||
|
||||
@@ -54,13 +54,20 @@ defmodule Mix.Tasks.Mobilizon.Users.Modify do
|
||||
),
|
||||
{:makes_changes, true} <- {:makes_changes, attrs != %{}},
|
||||
{:ok, %User{} = user} <- Users.update_user(user, attrs) do
|
||||
status =
|
||||
case user.confirmed_at do
|
||||
%DateTime{} = confirmed_at ->
|
||||
"Activated on #{DateTime.to_string(confirmed_at)} (UTC)"
|
||||
|
||||
_ ->
|
||||
"disabled"
|
||||
end
|
||||
|
||||
shell_info("""
|
||||
An user has been modified with the following information:
|
||||
- email: #{user.email}
|
||||
- Role: #{user.role}
|
||||
- account status: #{if user.confirmed_at,
|
||||
do: "activated on #{DateTime.to_string(user.confirmed_at)} (UTC)",
|
||||
else: "disabled"}
|
||||
- account status: #{status}
|
||||
""")
|
||||
else
|
||||
{:makes_changes, false} ->
|
||||
|
||||
@@ -78,6 +78,8 @@ defmodule Mix.Tasks.Mobilizon.Users.New do
|
||||
shell_error("mobilizon.users.new requires an email as argument")
|
||||
end
|
||||
|
||||
@spec create_user(String.t(), String.t() | nil, String.t(), Keyword.t()) ::
|
||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
||||
defp create_user(email, provider, password, options) do
|
||||
role = get_role(options)
|
||||
|
||||
@@ -96,6 +98,8 @@ defmodule Mix.Tasks.Mobilizon.Users.New do
|
||||
end
|
||||
end
|
||||
|
||||
@spec create_database_user(String.t(), String.t(), role()) ::
|
||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
||||
defp create_database_user(email, password, role) do
|
||||
Users.register(%{
|
||||
email: email,
|
||||
@@ -107,6 +111,8 @@ defmodule Mix.Tasks.Mobilizon.Users.New do
|
||||
})
|
||||
end
|
||||
|
||||
@spec create_user_from_provider(String.t(), String.t(), role()) ::
|
||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
||||
defp create_user_from_provider(email, provider, role) do
|
||||
Users.create_external(email, provider, %{role: role})
|
||||
end
|
||||
@@ -137,6 +143,7 @@ defmodule Mix.Tasks.Mobilizon.Users.New do
|
||||
end
|
||||
end
|
||||
|
||||
@spec check_password_and_provider_options(Keyword.t()) :: nil | no_return()
|
||||
defp check_password_and_provider_options(options) do
|
||||
if Keyword.get(options, :password) != nil && Keyword.get(options, :provider) != nil do
|
||||
shell_error("""
|
||||
|
||||
@@ -17,11 +17,18 @@ defmodule Mix.Tasks.Mobilizon.Users.Show do
|
||||
|
||||
with {:ok, %User{} = user} <- Users.get_user_by_email(email),
|
||||
actors <- Users.get_actors_for_user(user) do
|
||||
status =
|
||||
case user.confirmed_at do
|
||||
%DateTime{} = confirmed_at ->
|
||||
"Activated on #{DateTime.to_string(confirmed_at)} (UTC)"
|
||||
|
||||
_ ->
|
||||
"disabled"
|
||||
end
|
||||
|
||||
shell_info("""
|
||||
Informations for the user #{user.email}:
|
||||
- account status: #{if user.confirmed_at,
|
||||
do: "Activated on #{DateTime.to_string(user.confirmed_at)} (UTC)",
|
||||
else: "disabled"}
|
||||
- account status: #{status}
|
||||
- Role: #{user.role}
|
||||
#{display_actors(actors)}
|
||||
""")
|
||||
|
||||
Reference in New Issue
Block a user