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 e90af944db
commit 1a3a3602d1
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
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
""")