From fc2ace4b9e7fbac1c5ea6584fb0f4538bb31fe89 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 5 Nov 2024 14:55:48 +0100 Subject: [PATCH] Remove unused Socket.IO AdminNamespace --- app/blueprints/admin/events.py | 49 ---------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 app/blueprints/admin/events.py diff --git a/app/blueprints/admin/events.py b/app/blueprints/admin/events.py deleted file mode 100644 index 01cefa55..00000000 --- a/app/blueprints/admin/events.py +++ /dev/null @@ -1,49 +0,0 @@ -from flask_login import current_user -from flask_socketio import disconnect, Namespace -from app import db, hashids -from app.decorators import socketio_admin_required -from app.models import User - - -class AdminNamespace(Namespace): - def on_connect(self): - # Check if the user is authenticated and is an administrator - if not (current_user.is_authenticated and current_user.is_administrator): - disconnect() - - - @socketio_admin_required - def on_set_user_confirmed(self, user_hashid: str, confirmed_value: bool): - # Decode the user hashid - user_id = hashids.decode(user_hashid) - - # Validate user_id - if not isinstance(user_id, int): - return { - 'code': 400, - 'body': 'user_id is invalid' - } - - # Validate confirmed_value - if not isinstance(confirmed_value, bool): - return { - 'code': 400, - 'body': 'confirmed_value is invalid' - } - - # Load user from database - user = User.query.get(user_id) - if user is None: - return { - 'code': 404, - 'body': 'User not found' - } - - # Update user confirmed status - user.confirmed = confirmed_value - db.session.commit() - - return { - 'code': 200, - 'body': f'User "{user.username}" is now {"confirmed" if confirmed_value else "unconfirmed"}' - }