Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
tddd96-grupp1
teknikattan-scoring-system
Commits
6f6c2ea4
Commit
6f6c2ea4
authored
3 years ago
by
Victor Löfgren
Browse files
Options
Downloads
Patches
Plain Diff
Remove decorator dependency
parent
5a0d8e83
No related branches found
No related tags found
1 merge request
!161
Resolve "replace-restx-with-smorest"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/app/core/sockets.py
+32
-23
32 additions, 23 deletions
server/app/core/sockets.py
server/requirements.txt
+0
-0
0 additions, 0 deletions
server/requirements.txt
with
32 additions
and
23 deletions
server/app/core/sockets.py
+
32
−
23
View file @
6f6c2ea4
...
...
@@ -3,8 +3,8 @@ Contains all functionality related sockets. That is starting, joining, ending,
disconnecting from and syncing active competitions.
"""
import
logging
from
functools
import
wraps
from
decorator
import
decorator
from
flask.globals
import
request
from
flask_jwt_extended
import
verify_jwt_in_request
from
flask_jwt_extended.utils
import
get_jwt
...
...
@@ -55,8 +55,7 @@ def _get_sync_variables(active_competition, sync_values):
return
{
key
:
value
for
key
,
value
in
active_competition
.
items
()
if
key
in
sync_values
}
@decorator
def
authorize_client
(
f
,
allowed_views
=
None
,
require_active_competition
=
True
,
*
args
,
**
kwargs
):
def
authorization
(
allowed_views
=
None
,
require_active_competition
=
True
):
"""
Decorator used to authorize a client that sends socket events. Check that
the client has authorization headers, that client view gotten from claims
...
...
@@ -64,31 +63,41 @@ def authorize_client(f, allowed_views=None, require_active_competition=True, *ar
if require_active_competition is True.
"""
try
:
verify_jwt_in_request
()
except
:
logger
.
error
(
f
"
Won
'
t call function
'
{
f
.
__name__
}
'
: Missing Authorization Header
"
)
return
def
decorator
(
func
):
@wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
try
:
verify_jwt_in_request
()
except
:
logger
.
error
(
f
"
Won
'
t call function
'
{
func
.
__name__
}
'
: Missing Authorization Header
"
)
return
def
_is_allowed
(
allowed
,
actual
):
return
actual
and
"
*
"
in
allowed
or
actual
in
allowed
def
_is_allowed
(
allowed
,
actual
):
return
actual
and
"
*
"
in
allowed
or
actual
in
allowed
competition_id
,
view
=
_unpack_claims
()
competition_id
,
view
=
_unpack_claims
()
if
require_active_competition
and
not
is_active_competition
(
competition_id
):
logger
.
error
(
f
"
Won
'
t call function
'
{
func
.
__name__
}
'
: Competition
'
{
competition_id
}
'
is not active
"
)
return
nonlocal
allowed_views
allowed_views
=
allowed_views
or
[]
if
not
_is_allowed
(
allowed_views
,
view
):
logger
.
error
(
f
"
Won
'
t call function
'
{
func
.
__name__
}
'
: View
'
{
view
}
'
is not
'
{
'
or
'
.
join
(
allowed_views
)
}
'"
)
return
if
require_active_competition
and
not
is_active_competition
(
competition_id
):
logger
.
error
(
f
"
Won
'
t call function
'
{
f
.
__name__
}
'
: Competition
'
{
competition_id
}
'
is not active
"
)
return
return
func
(
*
args
,
**
kwargs
)
allowed_views
=
allowed_views
or
[]
if
not
_is_allowed
(
allowed_views
,
view
):
logger
.
error
(
f
"
Won
'
t call function
'
{
f
.
__name__
}
'
: View
'
{
view
}
'
is not
'
{
'
or
'
.
join
(
allowed_views
)
}
'"
)
return
return
wrapper
return
f
(
*
args
,
**
kwargs
)
return
decorator
@sio.event
@authoriz
e_client
(
require_active_competition
=
False
,
allowed_views
=
[
"
*
"
])
@authoriz
ation
(
require_active_competition
=
False
,
allowed_views
=
[
"
*
"
])
def
connect
()
->
None
:
"""
Connect to a active competition. If competition with competition_id is not active,
...
...
@@ -122,7 +131,7 @@ def connect() -> None:
@sio.event
@authoriz
e_client
(
allowed_views
=
[
"
*
"
])
@authoriz
ation
(
allowed_views
=
[
"
*
"
])
def
disconnect
()
->
None
:
"""
Remove client from the active_competition it was in. Delete active_competition if no
...
...
@@ -139,7 +148,7 @@ def disconnect() -> None:
@sio.event
@authoriz
e_client
(
allowed_views
=
[
"
Operator
"
])
@authoriz
ation
(
allowed_views
=
[
"
Operator
"
])
def
end_presentation
()
->
None
:
"""
End a presentation by sending end_presentation to all connected clients.
...
...
@@ -150,7 +159,7 @@ def end_presentation() -> None:
@sio.event
@authoriz
e_client
(
allowed_views
=
[
"
Operator
"
])
@authoriz
ation
(
allowed_views
=
[
"
Operator
"
])
def
sync
(
data
)
->
None
:
"""
Update all values from data thats in an active_competitions. Also sync all
...
...
This diff is collapsed.
Click to expand it.
server/requirements.txt
-36 B (-1%)
View file @
6f6c2ea4
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
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