|
|
@ -1,5 +1,5 @@ |
|
|
|
from functools import wraps |
|
|
|
from functools import wraps |
|
|
|
from flask import request, jsonify |
|
|
|
from flask import request, jsonify, g |
|
|
|
from sqlalchemy import select, and_ |
|
|
|
from sqlalchemy import select, and_ |
|
|
|
from ..db.model import User, Session, db |
|
|
|
from ..db.model import User, Session, db |
|
|
|
from ..constants import UserRole |
|
|
|
from ..constants import UserRole |
|
|
@ -23,9 +23,12 @@ def requires_role(roles=None): |
|
|
|
).scalar() |
|
|
|
).scalar() |
|
|
|
if not session: |
|
|
|
if not session: |
|
|
|
return jsonify({'error': 'Invalid or expired session'}), 401 |
|
|
|
return jsonify({'error': 'Invalid or expired session'}), 401 |
|
|
|
user = session.user |
|
|
|
|
|
|
|
|
|
|
|
user: User = session.user |
|
|
|
if not user: |
|
|
|
if not user: |
|
|
|
return jsonify({'error': 'User not found for the Access token'}), 401 |
|
|
|
return jsonify({'error': 'User not found for the Access token'}), 401 |
|
|
|
|
|
|
|
g.current_session = session |
|
|
|
|
|
|
|
g.current_user = user |
|
|
|
# If no roles specified, allow access |
|
|
|
# If no roles specified, allow access |
|
|
|
if not roles: |
|
|
|
if not roles: |
|
|
|
return f(*args, **kwargs) |
|
|
|
return f(*args, **kwargs) |
|
|
|