Compare commits

..

No commits in common. "delete-a-user" and "main" have entirely different histories.

3 changed files with 0 additions and 63 deletions

View File

@ -3,4 +3,3 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
from ki.actions.seed import seed # noqa
from ki.actions.delete_profile import delete_profile # noqa

View File

@ -1,52 +0,0 @@
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from sqlalchemy.exc import NoResultFound
from app import app, db
from ki.models import User
import sys
def delete_profile(nickname: str):
# Getting the user
try:
user = User.query.filter(User.auth_id.__eq__(nickname)).one()
except NoResultFound:
sys.exit(f'Username »{nickname}« not found')
app.logger.info(f'Starting to delete user »{nickname}.')
# Deleting associated languages skills
try:
for language in (user.profile.languages):
print(language.language_id)
app.logger.info(f'Deleting language skil »{language.language_id}« for »{nickname}«.')
db.session.delete(language)
db.session.commit()
except AttributeError:
# No languages left over
pass
# Deleting associated skills
try:
app.logger.info(f'Deleting skils for »{nickname}«.')
for skill in user.profile.skills:
db.session.delete(skill)
db.session.commit()
except AttributeError:
# No skills left over
pass
# Cleaning up profile
try:
app.logger.info(f'Deleting profile for »{nickname}«.')
db.session.delete(user.profile)
except:
# No profile to be deleted
pass
# Deleting the user
app.logger.info(f'Delete user »{nickname}«.')
db.session.delete(user)
db.session.commit()

View File

@ -6,19 +6,9 @@ import click
from app import app
from ki.actions import seed
from ki.actions import delete_profile
@app.cli.command("seed")
@click.option("--dev", is_flag=True)
def seed_command(dev):
seed(dev)
@app.cli.command("delete", help="Delete a user profile")
@click.option(
"--profile",
help="Username of profile",
)
def delete_command(profile):
delete_profile(profile)