-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: make the studio user_id the actual anonymous_user_id #30248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,11 @@ | |
| from xmodule.util.xmodule_django import add_webpack_to_fragment | ||
| from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem | ||
| from cms.djangoapps.xblock_config.models import StudioConfig | ||
| from cms.djangoapps.contentstore.toggles import individualize_anonymous_user_id | ||
| from cms.lib.xblock.field_data import CmsFieldData | ||
| from common.djangoapps.static_replace.services import ReplaceURLService | ||
| from common.djangoapps.static_replace.wrapper import replace_urls_wrapper | ||
| from common.djangoapps.student.models import anonymous_id_for_user | ||
| from common.djangoapps.edxmako.shortcuts import render_to_string | ||
| from common.djangoapps.edxmako.services import MakoService | ||
| from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService | ||
|
|
@@ -194,6 +196,17 @@ def _preview_module_system(request, descriptor, field_data): | |
| # stick the license wrapper in front | ||
| wrappers.insert(0, partial(wrap_with_license, mako_service=mako_service)) | ||
|
|
||
| preview_anonymous_user_id = 'student' | ||
| if individualize_anonymous_user_id(course_id): | ||
| # There are blocks (capa, html, and video) where we do not want to scope | ||
| # the anonymous_user_id to specific courses. These are captured in the | ||
| # block attribute 'requires_per_student_anonymous_id'. Please note, | ||
| # the course_id field in AnynomousUserID model is blank if value is None. | ||
| if getattr(descriptor, 'requires_per_student_anonymous_id', False): | ||
| preview_anonymous_user_id = anonymous_id_for_user(request.user, None) | ||
| else: | ||
| preview_anonymous_user_id = anonymous_id_for_user(request.user, course_id) | ||
|
|
||
| return PreviewModuleSystem( | ||
| static_url=settings.STATIC_URL, | ||
| # TODO (cpennington): Do we want to track how instructors are using the preview problems? | ||
|
|
@@ -216,8 +229,8 @@ def _preview_module_system(request, descriptor, field_data): | |
| "settings": SettingsService(), | ||
| "user": DjangoXBlockUserService( | ||
| request.user, | ||
| anonymous_user_id='student', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schenedx This is not enough to fix the issue.. you'll need to actually compute the Alternatively, you can move the logic for computing this value into a new function on the UserService (it will need access to the module
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nudge @schenedx :) Do you have an estimate for when you'll be able to address my comments?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pomegranited This fell off my radar last week. I apologize. I thought the DjangoXBlockUserService instance already have the get_anynomous_user_id that returns the calculated value, no? Also, this is on CMS. The LMS side has the correct value returned.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries @schenedx :)
Yes. What I'm saying above is the CMS needs to return the same value as the LMS, and this requires some code changes.
Yes it does have that method, but there's some issues with using it directly:
All of these issues can be solved, but they require code changes to implement them.
Ah ok.. I misunderstood. Do you have time and interest in making this change? If not, then we should find someone who does. OpenCraft could do it (for a fee), if there's no one in the community who wants to do it?
Yep, if you want to implement this change, you'll need a devstack. You can test it manually, but we'd also want some automated tests to protect the change, and ensure that future code changes don't break it.
Yep, that's worth doing, and can be done as part of the OSPR too. It's always easier to see the effects of a change when the code is in place so it can be tested. |
||
| user_role=get_user_role(request.user, course_id), | ||
| anonymous_user_id=preview_anonymous_user_id, | ||
| ), | ||
| "partitions": StudioPartitionService(course_id=course_id), | ||
| "teams_configuration": TeamsConfigurationService(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working great @schenedx , exactly as expected.
But to make sure your change doesn't get broken somewhere down the line, we need to update the unit tests to test these different cases. Here's what I'd recommend: schen/MST-1455...open-craft:jill/schen/MST-1455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. I made a PR on the unit tests you wrote above and merged it. Once this PR is going green, I plan to merge as well.