Add --yes option for skipping the confirmation prompt while deleting the user via CLI for scripting purpose. #7204

This commit is contained in:
octo-dama 2024-02-14 06:50:44 +01:00 committed by GitHub
parent 96ed38292f
commit 6adae46a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -187,11 +187,12 @@ Delete User
***********
To delete the user, invoke ``setup.py`` with ``delete-user`` command line option, followed by
username and auth_source. For Internal users, email adress will be used instead of username.
username and auth_source. For Internal users, email adress will be used instead of username. the option ``--yes`` is available to skip the confirmation prompt before deleting the user.
.. code-block:: bash
/path/to/python /path/to/setup.py delete-user user1@gmail.com --auth-source internal
/path/to/python /path/to/setup.py delete-user user2@gmail.com --auth-source internal --yes
/path/to/python /path/to/setup.py delete-user ldapuser --auth-source ldap

View File

@ -180,11 +180,15 @@ class ManageUsers:
ManageUsers.create_user(data, console, json)
@app.command()
def delete_user(username: str, auth_source: AuthType = AuthType.internal):
def delete_user(username: str,
auth_source: AuthType = AuthType.internal,
auto_confirm: Annotated[Optional[bool],
typer.Option(
"--yes")] = False
):
"""Delete the user. """
delete = typer.confirm("Are you sure you want to delete it?")
if delete:
confirm_msg = "Are you sure you want to delete it?"
if auto_confirm or typer.confirm(confirm_msg):
app = create_app(config.APP_NAME + '-cli')
with app.test_request_context():
uid = ManageUsers.get_user(username=username,