From 30efdf557f071d5421d2ab698d052ce774016f07 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Fri, 27 Jan 2023 10:28:27 +0100 Subject: [PATCH] Re-enable cli action user_delete with "disable" as default --- core/admin/mailu/manage.py | 23 +++++++++++++++++++---- docs/cli.rst | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/admin/mailu/manage.py b/core/admin/mailu/manage.py index 68f3fcea..869f8348 100644 --- a/core/admin/mailu/manage.py +++ b/core/admin/mailu/manage.py @@ -304,6 +304,7 @@ def config_update(verbose=False, delete_objects=False): if verbose: print(f'Deleting domain: {domain.name}') db.session.delete(domain) + db.session.commit() @@ -351,7 +352,7 @@ def config_import(verbose=0, secrets=False, debug=False, quiet=False, color=Fals raise click.ClickException(msg) from exc raise - # don't commit when running dry + # do not commit when running dry if dry_run: log.changes('Dry run. Not committing changes.') db.session.rollback() @@ -400,15 +401,29 @@ def config_export(full=False, secrets=False, color=False, dns=False, output=None finally: os.umask(old_umask) + +@mailu.command() +@click.argument('email') +@click.option('-r', '--really', is_flag=True) +@with_appcontext +def user_delete(email, really=False): + """disable or delete user""" + if user := models.User.query.get(email): + if really: + db.session.delete(user) + else: + user.enabled = False + db.session.commit() + + @mailu.command() @click.argument('email') @with_appcontext def alias_delete(email): """delete alias""" - alias = models.Alias.query.get(email) - if alias: + if alias := models.Alias.query.get(email): db.session.delete(alias) - db.session.commit() + db.session.commit() @mailu.command() diff --git a/docs/cli.rst b/docs/cli.rst index 5bed6707..01f3a17f 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -9,6 +9,7 @@ Managing users and aliases can be done from CLI using commands: * password * user * user-import +* user-delete * config-update * config-export * config-import @@ -62,6 +63,19 @@ primary difference with simple `user` command is that password is being imported docker-compose run --rm admin flask mailu user-import myuser example.net '$6$51ebe0cb9f1dab48effa2a0ad8660cb489b445936b9ffd812a0b8f46bca66dd549fea530ce' 'SHA512-CRYPT' + +user-delete +----------- + +Although the action is called "user-delete" the user is only deactivated by default. +This is due to the fact mailu does not remove user-data (emails and webmail contacts) when a user is deleted. +Add the flag `-r` to really delete the user after you have deleted user-data manually. + +.. code-block:: bash + + docker-compose exec admin flask mailu user-delete foo@example.net + + config-update -------------