Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
70a0c824
Commit
70a0c824
authored
Sep 25, 2014
by
Bertrand Marron
Committed by
Bertrand Marron
Nov 25, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ionisx_id and ionisx_session to tracking logs
parent
5bfcaa72
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
common/djangoapps/track/middleware.py
+27
-0
No files found.
common/djangoapps/track/middleware.py
View file @
70a0c824
...
...
@@ -6,6 +6,8 @@ import logging
from
django.conf
import
settings
from
social.apps.django_app.default
import
models
as
social_models
from
track
import
views
from
track
import
contexts
from
eventtracking
import
tracker
...
...
@@ -27,6 +29,7 @@ class TrackMiddleware(object):
Tracks all requests made, as well as setting up context for other server
emitted events.
"""
ionisx_session_re
=
re
.
compile
(
's
%3
A(
\
w*?)
\
..*'
)
def
process_request
(
self
,
request
):
try
:
...
...
@@ -100,6 +103,8 @@ class TrackMiddleware(object):
context
=
{
'session'
:
self
.
get_session_key
(
request
),
'user_id'
:
self
.
get_user_primary_key
(
request
),
'ionisx_id'
:
self
.
get_ionisx_user_id
(
request
),
'ionisx_session'
:
self
.
get_ionisx_session
(
request
),
'username'
:
self
.
get_username
(
request
),
}
for
header_name
,
context_key
in
META_KEY_TO_CONTEXT_KEY
.
iteritems
():
...
...
@@ -148,6 +153,28 @@ class TrackMiddleware(object):
except
AttributeError
:
return
''
def
get_ionisx_session
(
self
,
request
):
"""Gets the session id stored in the IONISx session cookie"""
cookie
=
request
.
COOKIES
.
get
(
'ionisx-sid'
)
if
cookie
:
try
:
m
=
self
.
ionisx_session_re
.
findall
(
cookie
)
if
len
(
m
)
==
1
:
return
m
[
0
]
except
Exception
:
# pylint: disable=broad-except
pass
return
''
def
get_ionisx_user_id
(
self
,
request
):
"""Gets the user id stored in the IONISx social auth"""
try
:
social_auth
=
social_models
.
DjangoStorage
.
user
.
get_social_auth_for_user
(
request
.
user
)
if
len
(
social_auth
)
==
1
:
return
social_auth
[
0
]
.
uid
return
''
except
AttributeError
:
return
''
def
get_username
(
self
,
request
):
"""Gets the username of the logged in Django user"""
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment