Delete files in db model methods.

This commit is contained in:
Patrick Jentsch
2020-07-10 11:36:54 +02:00
parent f86f3f4fd5
commit 7f8797d227
8 changed files with 84 additions and 93 deletions

View File

@ -1,16 +1,13 @@
from .. import db
from ..decorators import background
from ..models import User
import os
import shutil
@background
def delete_user(user_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
with kwargs['app'].app_context():
user = User.query.get(user_id)
if user is None:
raise Exception('User {} not found!'.format(user_id))
path = os.path.join(app.config['NOPAQUE_STORAGE'], str(user.id))
shutil.rmtree(path, ignore_errors=True)
raise Exception('User {} not found'.format(user_id))
user.delete()
db.session.commit()