mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-15 18:40:40 +00:00
enhance modals and terms of use html
This commit is contained in:
@ -9,50 +9,83 @@ from app.models import User
|
||||
@socketio_login_required
|
||||
def subscribe(user_hashid: str) -> dict:
|
||||
if not isinstance(user_hashid, str):
|
||||
return {'status': 400, 'statusText': 'Bad Request'}
|
||||
return {
|
||||
'code': 400,
|
||||
'name': 'Bad Request',
|
||||
'description': 'Invalid User ID.'
|
||||
}
|
||||
|
||||
user_id = hashids.decode(user_hashid)
|
||||
|
||||
if not isinstance(user_id, int):
|
||||
return {'status': 400, 'statusText': 'Bad Request'}
|
||||
return {
|
||||
'code': 400,
|
||||
'name': 'Bad Request',
|
||||
'description': 'Invalid User ID.'
|
||||
}
|
||||
|
||||
user = User.query.get(user_id)
|
||||
|
||||
if user is None:
|
||||
return {'status': 404, 'statusText': 'Not Found'}
|
||||
return {
|
||||
'code': 404,
|
||||
'name': 'Not Found',
|
||||
'description': 'User not found.'
|
||||
}
|
||||
|
||||
if not (
|
||||
user == current_user
|
||||
or current_user.is_administrator
|
||||
):
|
||||
return {'status': 403, 'statusText': 'Forbidden'}
|
||||
return {
|
||||
'code': 403,
|
||||
'name': 'Forbidden',
|
||||
'description': 'Not allowed to subscribe to this user.'
|
||||
}
|
||||
|
||||
join_room(f'/users/{user.hashid}')
|
||||
|
||||
return {'status': 200, 'statusText': 'OK'}
|
||||
return {'code': 204, 'name': 'No Content'}
|
||||
|
||||
|
||||
@socketio.on('UNSUBSCRIBE User')
|
||||
@socketio_login_required
|
||||
def unsubscribe(user_hashid: str) -> dict:
|
||||
if not isinstance(user_hashid, str):
|
||||
return {'status': 400, 'statusText': 'Bad Request'}
|
||||
return {
|
||||
'code': 400,
|
||||
'name': 'Bad Request',
|
||||
'description': 'Invalid User ID.'
|
||||
}
|
||||
|
||||
user_id = hashids.decode(user_hashid)
|
||||
|
||||
if not isinstance(user_id, int):
|
||||
return {'status': 400, 'statusText': 'Bad Request'}
|
||||
return {
|
||||
'code': 400,
|
||||
'name': 'Bad Request',
|
||||
'description': 'Invalid User ID.'
|
||||
}
|
||||
|
||||
user = User.query.get(user_id)
|
||||
|
||||
if user is None:
|
||||
return {'status': 404, 'statusText': 'Not Found'}
|
||||
return {
|
||||
'code': 404,
|
||||
'name': 'Not Found',
|
||||
'description': 'User not found.'
|
||||
}
|
||||
|
||||
if not (
|
||||
user == current_user
|
||||
or current_user.is_administrator
|
||||
):
|
||||
return {'status': 403, 'statusText': 'Forbidden'}
|
||||
return {
|
||||
'code': 403,
|
||||
'name': 'Forbidden',
|
||||
'description': 'Not allowed to unsubscribe from this user.'
|
||||
}
|
||||
|
||||
leave_room(f'/users/{user.hashid}')
|
||||
|
||||
return {'status': 200, 'statusText': 'OK'}
|
||||
return {'code': 204, 'name': 'No Content'}
|
||||
|
Reference in New Issue
Block a user