2021-11-30 15:22:16 +00:00
|
|
|
from app import hashids
|
2020-03-26 15:14:09 +00:00
|
|
|
from flask_login import current_user
|
2021-11-16 14:23:57 +00:00
|
|
|
from flask_socketio import join_room
|
2021-09-07 11:50:23 +00:00
|
|
|
from .. import socketio
|
|
|
|
from ..decorators import socketio_login_required
|
|
|
|
from ..models import User
|
2019-09-02 08:59:13 +00:00
|
|
|
|
2019-08-28 15:27:43 +00:00
|
|
|
|
2021-08-18 13:11:11 +00:00
|
|
|
###############################################################################
|
|
|
|
# Socket.IO event handlers #
|
|
|
|
###############################################################################
|
2021-11-30 15:22:16 +00:00
|
|
|
@socketio.on('users.user.get')
|
2021-02-01 11:51:07 +00:00
|
|
|
@socketio_login_required
|
2021-11-30 15:22:16 +00:00
|
|
|
def users_user_get(user_hashid):
|
|
|
|
user_id = hashids.decode(user_hashid)[0]
|
2021-02-01 11:51:07 +00:00
|
|
|
user = User.query.get(user_id)
|
|
|
|
if user is None:
|
|
|
|
response = {'code': 404, 'msg': 'Not found'}
|
|
|
|
elif not (user == current_user or current_user.is_administrator):
|
|
|
|
response = {'code': 403, 'msg': 'Forbidden'}
|
|
|
|
else:
|
2021-11-30 15:22:16 +00:00
|
|
|
response = {
|
|
|
|
'code': 200,
|
|
|
|
'msg': 'OK',
|
|
|
|
'payload': user.to_dict(backrefs=True, relationships=True)
|
|
|
|
}
|
|
|
|
join_room(f'users.{user.hashid}')
|
2021-09-22 11:52:51 +00:00
|
|
|
return response
|