mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Move delete user method in users package
This commit is contained in:
		@@ -8,32 +8,6 @@ from app.models import Avatar, User, ProfilePrivacySettings
 | 
			
		||||
from . import bp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@bp.route('/<hashid:user_id>', methods=['DELETE'])
 | 
			
		||||
@login_required
 | 
			
		||||
@content_negotiation(produces='application/json')
 | 
			
		||||
def delete_user(user_id):
 | 
			
		||||
    def _delete_user(app, user_id):
 | 
			
		||||
        with app.app_context():
 | 
			
		||||
            user = User.query.get(user_id)
 | 
			
		||||
            user.delete()
 | 
			
		||||
            db.session.commit()
 | 
			
		||||
 | 
			
		||||
    user = User.query.get_or_404(user_id)
 | 
			
		||||
    if not (user == current_user or current_user.is_administrator()):
 | 
			
		||||
        abort(403)
 | 
			
		||||
    thread = Thread(
 | 
			
		||||
        target=_delete_user,
 | 
			
		||||
        args=(current_app._get_current_object(), user_id)
 | 
			
		||||
    )
 | 
			
		||||
    if user == current_user:
 | 
			
		||||
        logout_user()
 | 
			
		||||
    thread.start()
 | 
			
		||||
    response_data = {
 | 
			
		||||
        'message': f'User "{user.username}" marked for deletion'
 | 
			
		||||
    }
 | 
			
		||||
    return response_data, 202
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@bp.route('/<hashid:user_id>/avatar', methods=['DELETE'])
 | 
			
		||||
@content_negotiation(produces='application/json')
 | 
			
		||||
def delete_profile_avatar(user_id):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user