Fix: update new runtime's runtime.anonymous_student_id to store in DB
This addresses a longstanding TODO item to make runtime.anonymous_student_id for content libraries v2 work the same way as it does for XBlocks in regular courses, persisting the "context ID" (equivalent to course ID) to the database. This way, if SECRET KEY is changed, existing anonymous IDs will continue to work unchanged. This is a potentially breaking change, but should mostly affect capa problems using external code graders or Matlab code input, and I'm not aware of any such usage of the new runtime / libraries v2.
This commit is contained in:
30
common/djangoapps/student/migrations/0039_anon_id_context.py
Normal file
30
common/djangoapps/student/migrations/0039_anon_id_context.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Convert the student.models.AnonymousUserId.course_id field from CourseKey to
|
||||
# the more generic LearningContextKey.
|
||||
#
|
||||
# This migration does not produce any changes at the database level.
|
||||
|
||||
from django.db import migrations
|
||||
import opaque_keys.edx.django.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('student', '0038_auto_20201021_1256'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.SeparateDatabaseAndState(
|
||||
# Do not actually make any changes to the database; the fields are identical string fields with the same
|
||||
# database properties.
|
||||
database_operations=[],
|
||||
# But update the migrator's view of the field to reflect the new field type.
|
||||
state_operations=[
|
||||
migrations.AlterField(
|
||||
model_name='anonymoususerid',
|
||||
name='course_id',
|
||||
field=opaque_keys.edx.django.models.LearningContextKeyField(blank=True, db_index=True, max_length=255),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -46,7 +46,7 @@ from edx_django_utils.cache import RequestCache
|
||||
from edx_rest_api_client.exceptions import SlumberBaseException
|
||||
from eventtracking import tracker
|
||||
from model_utils.models import TimeStampedModel
|
||||
from opaque_keys.edx.django.models import CourseKeyField
|
||||
from opaque_keys.edx.django.models import CourseKeyField, LearningContextKeyField
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from pytz import UTC
|
||||
from simple_history.models import HistoricalRecords
|
||||
@@ -143,7 +143,7 @@ class AnonymousUserId(models.Model):
|
||||
|
||||
user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE)
|
||||
anonymous_user_id = models.CharField(unique=True, max_length=32)
|
||||
course_id = CourseKeyField(db_index=True, max_length=255, blank=True)
|
||||
course_id = LearningContextKeyField(db_index=True, max_length=255, blank=True)
|
||||
|
||||
|
||||
def anonymous_id_for_user(user, course_id, save=True):
|
||||
|
||||
Reference in New Issue
Block a user