Change CLI delete user task to completly delete user by default

And document the new option

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-13 14:36:55 +02:00
parent f962563a9e
commit c7ddbc1162
2 changed files with 6 additions and 5 deletions

View File

@ -54,3 +54,4 @@ mix mobilizon.users.delete <email>
### Options
* `--assume_yes`/`-y` Don't ask for confirmation
* `--keep_email`/`-k` Keep user entry with just email information (to prevent future registrations with same email)

View File

@ -15,23 +15,23 @@ defmodule Mix.Tasks.Mobilizon.Users.Delete do
rest,
strict: [
assume_yes: :boolean,
force: :boolean
keep_email: :boolean
],
aliases: [
y: :assume_yes,
f: :force
f: :keep_email
]
)
assume_yes? = Keyword.get(options, :assume_yes, false)
force? = Keyword.get(options, :force, false)
keep_email? = Keyword.get(options, :keep_email, false)
Mix.Task.run("app.start")
with {:ok, %User{} = user} <- Users.get_user_by_email(email),
true <- assume_yes? or Mix.shell().yes?("Continue with deleting user #{user.email}?"),
{:ok, %User{} = user} <-
Users.delete_user(user, reserve_email: !force?) do
Users.delete_user(user, reserve_email: keep_email?) do
Mix.shell().info("""
The user #{user.email} has been deleted
""")