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
ac2b5bcc
Commit
ac2b5bcc
authored
Nov 22, 2016
by
Calen Pennington
Committed by
GitHub
Nov 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13717 from open-craft/smarnach/anonymous-id
Allow to store multiple anonymous ids per (user, course)
parents
84c42ae1
f5d556e7
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 @
ac2b5bcc
...
...
@@ -121,7 +121,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
):
...
...
@@ -159,22 +158,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 @
ac2b5bcc
...
...
@@ -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
...
...
@@ -945,7 +945,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'
,
...
...
@@ -974,6 +974,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