add function to delete user
This commit is contained in:
parent
3775c8eace
commit
5ab1a0f39c
|
@ -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'<Signup id={user.id}, username={user.username}>')
|
||||
|
||||
|
||||
|
||||
def cli_run(app: Flask, args) -> None:
|
||||
print("running in debug mode")
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
Loading…
Reference in a new issue