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 ### Options
* `--assume_yes`/`-y` Don't ask for confirmation * `--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, rest,
strict: [ strict: [
assume_yes: :boolean, assume_yes: :boolean,
force: :boolean keep_email: :boolean
], ],
aliases: [ aliases: [
y: :assume_yes, y: :assume_yes,
f: :force f: :keep_email
] ]
) )
assume_yes? = Keyword.get(options, :assume_yes, false) 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") Mix.Task.run("app.start")
with {:ok, %User{} = user} <- Users.get_user_by_email(email), with {:ok, %User{} = user} <- Users.get_user_by_email(email),
true <- assume_yes? or Mix.shell().yes?("Continue with deleting user #{user.email}?"), true <- assume_yes? or Mix.shell().yes?("Continue with deleting user #{user.email}?"),
{:ok, %User{} = user} <- {:ok, %User{} = user} <-
Users.delete_user(user, reserve_email: !force?) do Users.delete_user(user, reserve_email: keep_email?) do
Mix.shell().info(""" Mix.shell().info("""
The user #{user.email} has been deleted The user #{user.email} has been deleted
""") """)