From 5ab1a0f39c04f85d5cc30891cb624177079f19d7 Mon Sep 17 00:00:00 2001 From: tuxcoder Date: Fri, 22 Dec 2023 23:09:37 +0100 Subject: [PATCH] add function to delete user --- lenticular_cloud/cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lenticular_cloud/cli.py b/lenticular_cloud/cli.py index d796ba2..9ce894b 100644 --- a/lenticular_cloud/cli.py +++ b/lenticular_cloud/cli.py @@ -6,6 +6,7 @@ from werkzeug.middleware.proxy_fix import ProxyFix from flask_migrate import upgrade from pathlib import Path from flask import Flask +from uuid import UUID import logging import os @@ -19,6 +20,10 @@ def entry_point() -> None: parser_user = subparsers.add_parser('user') parser_user.set_defaults(func=cli_user) + subparsers_user = parser_user.add_subparsers() + parser_user_delete = subparsers_user.add_parser('delete') + parser_user_delete.add_argument('--id', type=str) + parser_user_delete.set_defaults(func=cli_user_delete) parser_signup = subparsers.add_parser('signup') parser_signup.add_argument('--signup_id', type=str) @@ -61,6 +66,16 @@ def cli_user(args) -> None: print(f'{user.id} - Enabled: {user.enabled} - Name:`{user.username}`') pass +def cli_user_delete(args) -> None: + user = User.query.get(UUID(args.id)) + if user is None: + print("user not found") + return + db.session.delete(user) + db.session.commit() + print(f"user {user.username} - {user.id} deleted") + pass + def cli_signup(args) -> None: if args.signup_id is not None: @@ -78,6 +93,7 @@ def cli_signup(args) -> None: print(f'') + def cli_run(app: Flask, args) -> None: print("running in debug mode") logging.basicConfig(level=logging.DEBUG)