forked from kompetenzinventar/ki-backend
Compare commits
No commits in common. "delete-a-user" and "main" have entirely different histories.
delete-a-u
...
main
@ -3,4 +3,3 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
from ki.actions.seed import seed # noqa
|
from ki.actions.seed import seed # noqa
|
||||||
from ki.actions.delete_profile import delete_profile # noqa
|
|
||||||
|
@ -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()
|
|
@ -6,19 +6,9 @@ import click
|
|||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from ki.actions import seed
|
from ki.actions import seed
|
||||||
from ki.actions import delete_profile
|
|
||||||
|
|
||||||
|
|
||||||
@app.cli.command("seed")
|
@app.cli.command("seed")
|
||||||
@click.option("--dev", is_flag=True)
|
@click.option("--dev", is_flag=True)
|
||||||
def seed_command(dev):
|
def seed_command(dev):
|
||||||
seed(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)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user