mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
unify get_user event via socketio
This commit is contained in:
parent
87e2c2b484
commit
656eef17db
@ -75,9 +75,9 @@ def create_app(config: Config = Config) -> Flask:
|
||||
|
||||
from .corpora import bp as corpora_blueprint
|
||||
from .corpora.cqi_over_sio import CQiNamespace
|
||||
socketio.on_namespace(CQiNamespace('/cqi_over_sio'))
|
||||
default_breadcrumb_root(corpora_blueprint, '.corpora')
|
||||
app.register_blueprint(corpora_blueprint, cli_group='corpus', url_prefix='/corpora')
|
||||
socketio.on_namespace(CQiNamespace('/cqi_over_sio'))
|
||||
|
||||
from .errors import bp as errors_bp
|
||||
app.register_blueprint(errors_bp)
|
||||
|
@ -8,19 +8,19 @@ class App {
|
||||
this.socket.on('PATCH', (patch) => {this.onPatch(patch);});
|
||||
}
|
||||
|
||||
getUser(userId, backrefs=true, relationships=true) {
|
||||
getUser(userId) {
|
||||
if (userId in this.data.promises.getUser) {
|
||||
return this.data.promises.getUser[userId];
|
||||
}
|
||||
|
||||
this.data.promises.getUser[userId] = new Promise((resolve, reject) => {
|
||||
this.socket.emit('GET /users/<user_id>', userId, backrefs, relationships, (response) => {
|
||||
if (response.status !== 200) {
|
||||
reject(response);
|
||||
return;
|
||||
this.socket.emit('GET /users/<user_id>', userId, (response) => {
|
||||
if (response.status === 200) {
|
||||
this.data.users[userId] = response.body;
|
||||
resolve(this.data.users[userId]);
|
||||
} else {
|
||||
reject(`[${response.status}] ${response.statusText}`);
|
||||
}
|
||||
this.data.users[userId] = response.body;
|
||||
resolve(this.data.users[userId]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -7,7 +7,7 @@ from app.models import User
|
||||
|
||||
@socketio.on('GET /users/<user_id>')
|
||||
@socketio_login_required
|
||||
def get_user(user_hashid, backrefs=False, relationships=False):
|
||||
def get_user(user_hashid):
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get(user_id)
|
||||
if user is None:
|
||||
@ -15,12 +15,9 @@ def get_user(user_hashid, backrefs=False, relationships=False):
|
||||
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
|
||||
),
|
||||
'body': user.to_json_serializeable(backrefs=True, relationships=True),
|
||||
'status': 200,
|
||||
'statusText': 'OK',
|
||||
'statusText': 'OK'
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user