Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
eba6af3b
Commit
eba6af3b
authored
4 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Replace the default function decorators with new socketio specific ones
parent
257600a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/corpora/events.py
+6
-5
6 additions, 5 deletions
app/corpora/events.py
app/decorators.py
+25
-10
25 additions, 10 deletions
app/decorators.py
app/events.py
+5
-7
5 additions, 7 deletions
app/events.py
with
36 additions
and
22 deletions
app/corpora/events.py
+
6
−
5
View file @
eba6af3b
from
app
import
db
,
logger
,
socketio
from
app
import
db
,
logger
,
socketio
from
app.decorators
import
socketio_login_required
from
app.events
import
connected_sessions
from
app.events
import
connected_sessions
from
app.models
import
Corpus
,
User
from
app.models
import
Corpus
,
User
from
.cqi
import
CQiClient
from
.cqi
import
CQiClient
from
flask
import
current_app
,
request
from
flask
import
current_app
,
request
from
flask_login
import
current_user
,
login_required
from
flask_login
import
current_user
import
math
import
math
...
@@ -23,13 +24,13 @@ corpus_analysis_clients_status = {}
...
@@ -23,13 +24,13 @@ corpus_analysis_clients_status = {}
@socketio.on
(
'
send_analysis_status_cli
'
)
@socketio.on
(
'
send_analysis_status_cli
'
)
@login_required
@
socketio_
login_required
def
update_status
(
response
):
def
update_status
(
response
):
update_analysis_status
(
response
[
'
status
'
])
update_analysis_status
(
response
[
'
status
'
])
@socketio.on
(
'
corpus_analysis_init
'
)
@socketio.on
(
'
corpus_analysis_init
'
)
@login_required
@
socketio_
login_required
def
init_corpus_analysis
(
corpus_id
):
def
init_corpus_analysis
(
corpus_id
):
logger
.
warning
(
'
Initiating corpus analysis.
'
)
logger
.
warning
(
'
Initiating corpus analysis.
'
)
socketio
.
start_background_task
(
corpus_analysis_session_handler
,
socketio
.
start_background_task
(
corpus_analysis_session_handler
,
...
@@ -39,7 +40,7 @@ def init_corpus_analysis(corpus_id):
...
@@ -39,7 +40,7 @@ def init_corpus_analysis(corpus_id):
@socketio.on
(
'
corpus_analysis_query
'
)
@socketio.on
(
'
corpus_analysis_query
'
)
@login_required
@
socketio_
login_required
def
corpus_analysis_query
(
query
):
def
corpus_analysis_query
(
query
):
update_analysis_status
(
'
running
'
)
update_analysis_status
(
'
running
'
)
logger
.
warning
(
'
Recieved a query.
'
)
logger
.
warning
(
'
Recieved a query.
'
)
...
@@ -113,7 +114,7 @@ def get_analysis_status():
...
@@ -113,7 +114,7 @@ def get_analysis_status():
@socketio.on
(
'
inspect_match
'
)
@socketio.on
(
'
inspect_match
'
)
@login_required
@
socketio_
login_required
def
inspect_match
(
message
):
def
inspect_match
(
message
):
client
=
corpus_analysis_clients
.
get
(
request
.
sid
)
client
=
corpus_analysis_clients
.
get
(
request
.
sid
)
if
client
is
None
:
if
client
is
None
:
...
...
This diff is collapsed.
Click to expand it.
app/decorators.py
+
25
−
10
View file @
eba6af3b
from
functools
import
wraps
from
functools
import
wraps
from
flask
import
abort
from
flask
import
abort
from
flask_login
import
current_user
from
flask_login
import
current_user
from
flask_socketio
import
disconnect
from
.models
import
Permission
from
.models
import
Permission
def
permission_required
(
permission
):
def
admin_required
(
f
):
def
decorator
(
f
):
@wraps
(
f
)
@wraps
(
f
)
def
wrapped
(
*
args
,
**
kwargs
):
def
decorated_function
(
*
args
,
**
kwargs
):
if
not
current_user
.
can
(
Permission
.
ADMIN
):
if
not
current_user
.
can
(
permission
):
abort
(
403
)
abort
(
403
)
return
f
(
*
args
,
**
kwargs
)
return
wrapped
def
socketio_login_required
(
f
):
@wraps
(
f
)
def
wrapped
(
*
args
,
**
kwargs
):
if
not
current_user
.
is_authenticated
:
disconnect
()
else
:
return
f
(
*
args
,
**
kwargs
)
return
f
(
*
args
,
**
kwargs
)
return
decorated_function
return
wrapped
return
decorator
def
admin_required
(
f
):
def
socketio_admin_required
(
f
):
return
permission_required
(
Permission
.
ADMIN
)(
f
)
@wraps
(
f
)
def
wrapped
(
*
args
,
**
kwargs
):
if
not
current_user
.
can
(
Permission
.
ADMIN
):
disconnect
()
else
:
return
f
(
*
args
,
**
kwargs
)
return
wrapped
This diff is collapsed.
Click to expand it.
app/events.py
+
5
−
7
View file @
eba6af3b
from
flask
import
current_app
,
request
from
flask
import
current_app
,
request
from
flask_login
import
current_user
,
login_required
from
flask_login
import
current_user
from
.
import
socketio
from
.
import
socketio
from
.decorators
import
admin_required
from
.decorators
import
socketio_
admin_required
,
socketio_login_required
from
.models
import
User
from
.models
import
User
import
json
import
json
import
jsonpatch
import
jsonpatch
...
@@ -16,7 +16,6 @@ connected_sessions = []
...
@@ -16,7 +16,6 @@ connected_sessions = []
@socketio.on
(
'
connect
'
)
@socketio.on
(
'
connect
'
)
@login_required
def
connect
():
def
connect
():
'''
'''
'
The Socket.IO module creates a session id (sid) for each request.
'
The Socket.IO module creates a session id (sid) for each request.
...
@@ -26,7 +25,6 @@ def connect():
...
@@ -26,7 +25,6 @@ def connect():
@socketio.on
(
'
disconnect
'
)
@socketio.on
(
'
disconnect
'
)
@login_required
def
disconnect
():
def
disconnect
():
'''
'''
'
On disconnect the session id gets removed from the connected sessions
'
On disconnect the session id gets removed from the connected sessions
...
@@ -36,7 +34,7 @@ def disconnect():
...
@@ -36,7 +34,7 @@ def disconnect():
@socketio.on
(
'
user_ressources_init
'
)
@socketio.on
(
'
user_ressources_init
'
)
@login_required
@
socketio_
login_required
def
subscribe_user_ressources
():
def
subscribe_user_ressources
():
socketio
.
start_background_task
(
user_ressource_session_handler
,
socketio
.
start_background_task
(
user_ressource_session_handler
,
current_app
.
_get_current_object
(),
current_app
.
_get_current_object
(),
...
@@ -44,8 +42,8 @@ def subscribe_user_ressources():
...
@@ -44,8 +42,8 @@ def subscribe_user_ressources():
@socketio.on
(
'
foreign_user_ressources_init
'
)
@socketio.on
(
'
foreign_user_ressources_init
'
)
@login_required
@
socketio_
login_required
@admin_required
@
socketio_
admin_required
def
subscribe_foreign_user_ressources
(
user_id
):
def
subscribe_foreign_user_ressources
(
user_id
):
socketio
.
start_background_task
(
user_ressource_session_handler
,
socketio
.
start_background_task
(
user_ressource_session_handler
,
current_app
.
_get_current_object
(),
current_app
.
_get_current_object
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment