mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 02:44:18 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
6459c9f064
@ -2,20 +2,20 @@ from app import db, socketio
|
|||||||
from app.events import connected_sessions
|
from app.events import connected_sessions
|
||||||
from app.models import Corpus
|
from app.models import Corpus
|
||||||
from flask import current_app, request
|
from flask import current_app, request
|
||||||
from flask_login import login_required
|
from flask_login import current_user, login_required
|
||||||
from .CQiWrapper.CQiWrapper import CQiWrapper
|
from .CQiWrapper.CQiWrapper import CQiWrapper
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
' A dictionary containing lists of with corpus ids associated Socket.IO session
|
' A dictionary containing lists of, with corpus ids associated, Socket.IO
|
||||||
' ids (sid). {<corpus_id>: [<sid>, ...], ...}
|
' session ids (sid). {<corpus_id>: [<sid>, ...], ...}
|
||||||
'''
|
'''
|
||||||
analysis_sessions = {}
|
analysis_sessions = {}
|
||||||
'''
|
'''
|
||||||
' A dictionary containing Socket.IO session id - CQi client pairs.
|
' A dictionary containing Socket.IO session id - CQi client pairs.
|
||||||
' {<sid>: CQi client, ...}
|
' {<sid>: CQiClient, ...}
|
||||||
'''
|
'''
|
||||||
analysis_clients = {}
|
analysis_clients = {}
|
||||||
|
|
||||||
@ -23,7 +23,13 @@ analysis_clients = {}
|
|||||||
@socketio.on('init_corpus_analysis')
|
@socketio.on('init_corpus_analysis')
|
||||||
@login_required
|
@login_required
|
||||||
def init_corpus_analysis(corpus_id):
|
def init_corpus_analysis(corpus_id):
|
||||||
''' TODO: Check if current_user is allowed to subscribe to this '''
|
corpus = Corpus.query.filter_by(id=corpus_id).first()
|
||||||
|
if corpus is None:
|
||||||
|
socketio.emit('init_corpus_analysis', '[ERROR 404]: Not Found',
|
||||||
|
room=request.sid)
|
||||||
|
if not (corpus.creator == current_user or current_user.is_administrator()):
|
||||||
|
socketio.emit('init_corpus_analysis', '[ERROR 403]: Forbidden',
|
||||||
|
room=request.sid)
|
||||||
if str(corpus_id) not in analysis_sessions:
|
if str(corpus_id) not in analysis_sessions:
|
||||||
analysis_sessions[str(corpus_id)] = [request.sid]
|
analysis_sessions[str(corpus_id)] = [request.sid]
|
||||||
socketio.start_background_task(observe_corpus_analysis_connection,
|
socketio.start_background_task(observe_corpus_analysis_connection,
|
||||||
@ -32,6 +38,7 @@ def init_corpus_analysis(corpus_id):
|
|||||||
|
|
||||||
|
|
||||||
@socketio.on('query_event')
|
@socketio.on('query_event')
|
||||||
|
@login_required
|
||||||
def recv_query(message):
|
def recv_query(message):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.warning(message)
|
logger.warning(message)
|
||||||
|
@ -73,16 +73,16 @@ def user_ressource_subscription_handler(app, user_id, session_id,
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
# Gather current values from database.
|
# Gather current values from database.
|
||||||
user = User.query.filter_by(id=user_id).first()
|
user = User.query.filter_by(id=user_id).first()
|
||||||
corpora = user.corpora_as_dict()
|
corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora}
|
||||||
jobs = user.jobs_as_dict()
|
jobs = {job.id: job.to_dict() for job in user.jobs}
|
||||||
# Send initial values to the user.
|
# Send initial values to the user.
|
||||||
socketio.emit(init_events['corpora'], json.dumps(corpora),
|
socketio.emit(init_events['corpora'], json.dumps(corpora),
|
||||||
room=session_id)
|
room=session_id)
|
||||||
socketio.emit(init_events['jobs'], json.dumps(jobs), room=session_id)
|
socketio.emit(init_events['jobs'], json.dumps(jobs), room=session_id)
|
||||||
while session_id in connected_sessions:
|
while session_id in connected_sessions:
|
||||||
# Get new values from the database
|
# Get new values from the database
|
||||||
new_corpora = user.corpora_as_dict()
|
new_corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora}
|
||||||
new_jobs = user.jobs_as_dict()
|
new_jobs = {job.id: job.to_dict() for job in user.jobs}
|
||||||
# Compute JSON patches.
|
# Compute JSON patches.
|
||||||
corpora_patch = jsonpatch.JsonPatch.from_diff(corpora, new_corpora)
|
corpora_patch = jsonpatch.JsonPatch.from_diff(corpora, new_corpora)
|
||||||
jobs_patch = jsonpatch.JsonPatch.from_diff(jobs, new_jobs)
|
jobs_patch = jsonpatch.JsonPatch.from_diff(jobs, new_jobs)
|
||||||
|
@ -208,18 +208,6 @@ class User(UserMixin, db.Model):
|
|||||||
"""
|
"""
|
||||||
return self.can(Permission.ADMIN)
|
return self.can(Permission.ADMIN)
|
||||||
|
|
||||||
def corpora_as_dict(self):
|
|
||||||
corpora = {}
|
|
||||||
for corpus in self.corpora:
|
|
||||||
corpora[str(corpus.id)] = corpus.to_dict()
|
|
||||||
return corpora
|
|
||||||
|
|
||||||
def jobs_as_dict(self):
|
|
||||||
jobs = {}
|
|
||||||
for job in self.jobs:
|
|
||||||
jobs[str(job.id)] = job.to_dict()
|
|
||||||
return jobs
|
|
||||||
|
|
||||||
def delete_user(self):
|
def delete_user(self):
|
||||||
"""
|
"""
|
||||||
Delete user from database. Also delete all associated jobs and corpora
|
Delete user from database. Also delete all associated jobs and corpora
|
||||||
|
Loading…
Reference in New Issue
Block a user