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
f5d556e7
Commit
f5d556e7
authored
Oct 18, 2016
by
Sven Marnach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to store multiple anonymous ids for each (user, course).
parent
00b11758
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
common/djangoapps/student/models.py
+3
-15
common/djangoapps/student/tests/tests.py
+14
-2
No files found.
common/djangoapps/student/models.py
View file @
f5d556e7
...
...
@@ -123,7 +123,6 @@ class AnonymousUserId(models.Model):
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
anonymous_user_id
=
models
.
CharField
(
unique
=
True
,
max_length
=
32
)
course_id
=
CourseKeyField
(
db_index
=
True
,
max_length
=
255
,
blank
=
True
)
unique_together
=
(
user
,
course_id
)
def
anonymous_id_for_user
(
user
,
course_id
,
save
=
True
):
...
...
@@ -161,22 +160,11 @@ def anonymous_id_for_user(user, course_id, save=True):
return
digest
try
:
anonymous_user_id
,
__
=
AnonymousUserId
.
objects
.
get_or_create
(
defaults
=
{
'anonymous_user_id'
:
digest
},
AnonymousUserId
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course_id
course_id
=
course_id
,
anonymous_user_id
=
digest
,
)
if
anonymous_user_id
.
anonymous_user_id
!=
digest
:
log
.
error
(
u"Stored anonymous user id
%(anonymous_user_id)
r for "
u"user
%(user)
r in course
%(course_id)
r doesn't match "
u"computed id
%(digest)
r"
,
{
"anonymous_user_id"
:
anonymous_user_id
.
anonymous_user_id
,
"user"
:
user
,
"course_id"
:
course_id
,
"digest"
:
digest
,
}
)
except
IntegrityError
:
# Another thread has already created this entry, so
# continue
...
...
common/djangoapps/student/tests/tests.py
View file @
f5d556e7
...
...
@@ -12,7 +12,7 @@ import ddt
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.core.urlresolvers
import
reverse
from
django.test
import
TestCase
from
django.test
import
TestCase
,
override_settings
from
django.test.client
import
Client
from
edx_oauth2_provider.tests.factories
import
ClientFactory
import
httpretty
...
...
@@ -863,7 +863,7 @@ class AnonymousLookupTable(ModuleStoreTestCase):
def
setUp
(
self
):
super
(
AnonymousLookupTable
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
()
self
.
user
=
UserFactory
()
self
.
user
=
UserFactory
.
create
()
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
'honor'
,
...
...
@@ -892,6 +892,18 @@ class AnonymousLookupTable(ModuleStoreTestCase):
self
.
assertEqual
(
self
.
user
,
real_user
)
self
.
assertEqual
(
anonymous_id
,
anonymous_id_for_user
(
self
.
user
,
course2
.
id
,
save
=
False
))
def
test_secret_key_changes
(
self
):
"""Test that a new anonymous id is returned when the secret key changes."""
CourseEnrollment
.
enroll
(
self
.
user
,
self
.
course
.
id
)
anonymous_id
=
anonymous_id_for_user
(
self
.
user
,
self
.
course
.
id
)
with
override_settings
(
SECRET_KEY
=
'some_new_and_totally_secret_key'
):
# Recreate user object to clear cached anonymous id.
self
.
user
=
User
.
objects
.
get
(
pk
=
self
.
user
.
id
)
new_anonymous_id
=
anonymous_id_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertNotEqual
(
anonymous_id
,
new_anonymous_id
)
self
.
assertEqual
(
self
.
user
,
user_by_anonymous_id
(
anonymous_id
))
self
.
assertEqual
(
self
.
user
,
user_by_anonymous_id
(
new_anonymous_id
))
@attr
(
shard
=
3
)
@httpretty.activate
...
...
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