mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 01:50:40 +00:00
Change how user data is get and subscribed
This commit is contained in:
@ -5,17 +5,55 @@ from app.decorators import socketio_login_required
|
||||
from app.models import User
|
||||
|
||||
|
||||
@socketio.on('GET /users/<user_id>')
|
||||
@socketio_login_required
|
||||
def get_user(user_hashid, backrefs=False, relationships=False):
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get(user_id)
|
||||
if user is None:
|
||||
return {'status': 404, 'statusText': 'Not found'}
|
||||
if not (user == current_user or current_user.is_administrator):
|
||||
return {'status': 403, 'statusText': 'Forbidden'}
|
||||
return {
|
||||
'body': user.to_json_serializeable(
|
||||
backrefs=backrefs,
|
||||
relationships=relationships
|
||||
),
|
||||
'status': 200,
|
||||
'statusText': 'OK',
|
||||
}
|
||||
|
||||
|
||||
# @socketio.on('GET /users/<user_id>')
|
||||
# @socketio_login_required
|
||||
# def get_user(user_hashid):
|
||||
# user_id = hashids.decode(user_hashid)
|
||||
# user = User.query.get(user_id)
|
||||
# if user is None:
|
||||
# return {'options': {'status': 404, 'statusText': 'Not found'}}
|
||||
# if not (user == current_user or current_user.is_administrator):
|
||||
# return {'options': {'status': 403, 'statusText': 'Forbidden'}}
|
||||
# return {
|
||||
# 'body': user.to_json_serializable2(),
|
||||
# 'options': {
|
||||
# 'status': 200,
|
||||
# 'statusText': 'OK',
|
||||
# 'headers': {'Content-Type: application/json'}
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
@socketio.on('SUBSCRIBE /users/<user_id>')
|
||||
@socketio_login_required
|
||||
def subscribe_user(user_hashid):
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get(user_id)
|
||||
if user is None:
|
||||
return {'code': 404, 'msg': 'Not found'}
|
||||
return {'status': 404, 'statusText': 'Not found'}
|
||||
if not (user == current_user or current_user.is_administrator):
|
||||
return {'code': 403, 'msg': 'Forbidden'}
|
||||
return {'status': 403, 'statusText': 'Forbidden'}
|
||||
join_room(f'/users/{user.hashid}')
|
||||
return {'code': 200, 'msg': 'OK'}
|
||||
return {'status': 200, 'statusText': 'OK'}
|
||||
|
||||
|
||||
@socketio.on('UNSUBSCRIBE /users/<user_id>')
|
||||
@ -24,8 +62,8 @@ def unsubscribe_user(user_hashid):
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get(user_id)
|
||||
if user is None:
|
||||
return {'code': 404, 'msg': 'Not found'}
|
||||
return {'status': 404, 'statusText': 'Not found'}
|
||||
if not (user == current_user or current_user.is_administrator):
|
||||
return {'code': 403, 'msg': 'Forbidden'}
|
||||
return {'status': 403, 'statusText': 'Forbidden'}
|
||||
leave_room(f'/users/{user.hashid}')
|
||||
return {'code': 200, 'msg': 'OK'}
|
||||
return {'status': 200, 'statusText': 'OK'}
|
||||
|
@ -1,4 +1,4 @@
|
||||
from flask import abort, current_app, request
|
||||
from flask import abort, current_app
|
||||
from flask_login import current_user, login_required
|
||||
from threading import Thread
|
||||
from app import db
|
||||
@ -9,13 +9,7 @@ from . import bp
|
||||
@bp.route('/<hashid:user_id>')
|
||||
@login_required
|
||||
def user(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
if not (user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
backrefs = request.args.get('backrefs', 'false').lower() == 'true'
|
||||
relationships = (
|
||||
request.args.get('relationships', 'false').lower() == 'true')
|
||||
return user.to_json_serializeable(backrefs=backrefs, relationships=relationships), 200
|
||||
abort(503)
|
||||
|
||||
|
||||
@bp.route('/<hashid:user_id>', methods=['DELETE'])
|
||||
|
Reference in New Issue
Block a user