Skip to content

fix: make the studio user_id the actual anonymous_user_id - #30248

Merged
schenedx merged 2 commits into
masterfrom
schen/MST-1455
May 16, 2022
Merged

fix: make the studio user_id the actual anonymous_user_id#30248
schenedx merged 2 commits into
masterfrom
schen/MST-1455

Conversation

@schenedx

@schenedx schenedx commented Apr 14, 2022

Copy link
Copy Markdown
Contributor

Description

MST-1455
Currently, during studio preview of the xblock, we would render the xblock using the anonymous_user_id with value student. Why not just render the xblock using the actual anonymous_user_id?
One uncertainty is that the anonymous_user_id for non edX staff user would be none. That might be a problem?

Testing instructions

  1. Create a course override waffle flag in the django admin on edx-platform. The name of the waffle flag is contentstore.individualize_anonymous_user_id
  2. Enable and activate the above waffle flag for a course in test
  3. Go into the studio website and go into the course where you had the waffle flag turned on
  4. Create a new LTI xblock
  5. Configure the xblock connecting against a TurnItIn content instance. You can find examples of it on stage or prod
  6. Preview the xblock instance upon save.
  7. During preview rendering, monitor the network tab of the Chrome developer tool and see the data posted into the LTI handler endpoint has user_id to be a unique value, instead of student value.

@schenedx

Copy link
Copy Markdown
Contributor Author

@pomegranited Can you think of any negative effects of this change?

@pomegranited

pomegranited commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

@schenedx These are the effects I can think of.. But note that I don't think they're a reason not to continue with this change, they may just require some communication.

In Studio:

  • Any previously-submitted answers to JS problems that rely on anonymous_student_id for randomization will be marked incorrect, as the anonymous_student_id will have changed.
  • Similarly, 2 different course authors which use Studio to test JS problems using anonymous_student_id will see different values and require different answers to randomized questions. (This can also be seen as a feature, as they can also test said randomization.)
  • Any previous integrations with LTIs or XBlocks that rely on the Studio student value in anonymous_student_id will lose access to their Studio user data in the LTI/XBlock.

Are any of these concerns a worry for you @pdpinch ? For context, see the Slack discussion.

"settings": SettingsService(),
"user": DjangoXBlockUserService(
request.user,
anonymous_user_id='student',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 anonymous_user_id for the current user, and pass it into the UserService as is done by the LMS ModuleSystem.

Alternatively, you can move the logic for computing this value into a new function on the UserService (it will need access to the module descriptor and the course_id) to avoid duplicating code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?
Just planning my week, and want to make sure I allow time for a 2nd review. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries @schenedx :)

Also, this is on CMS. The LMS side has the correct value returned.

Yes. What I'm saying above is the CMS needs to return the same value as the LMS, and this requires some code changes.

I thought the DjangoXBlockUserService instance already have the get_anynomous_user_id that returns the calculated value, no? ([sic: corrected source link])

Yes it does have that method, but there's some issues with using it directly:

  • performance: that method hits the database to get the User object for the given username, so we'd likely want to cache it
  • There's some subtleties of the LMS code -- some blocks expect a per-student anonymous ID, while some expect a per-course anonymous ID. The DjangoXBlockUserService currently has no knowledge of course_id, or of the block's requires_per_student_anonymous_id flag.

All of these issues can be solved, but they require code changes to implement them.

I have no developer experience in this area, so this is difficult for me to setup.

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?

How do we test the anynomous_user_id with randomized content? Do I just need to set it up on my local environment?

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.

Also, I think all the side effect of this change @pomegranited have listed is worth a heads up for 2U internal.

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.

@schenedx

Copy link
Copy Markdown
Contributor Author

@pomegranited I am grateful for your feedback. How do we test the anynomous_user_id with randomized content? Do I just need to set it up on my local environment? I have no developer experience in this area, so this is difficult for me to setup.

@schenedx

Copy link
Copy Markdown
Contributor Author

Also, I think all the side effect of this change @pomegranited have listed is worth a heads up for 2U internal. The true question is, should we manage the communication of these side effects? Or the current behavior/no fix, would be the better behavior going forward. I'll need sometime to have this conversation with 2U stakeholders.

@schenedx
schenedx force-pushed the schen/MST-1455 branch 3 times, most recently from bfeed04 to 4e9a35e Compare May 4, 2022 19:22
@schenedx

schenedx commented May 4, 2022

Copy link
Copy Markdown
Contributor Author

@pomegranited OK, with your explanation and a bit of my devstack testing, I now understand you better.
To limit the potential ramification of this change, I am putting the change behind a course waffle flag to test out on stage and prod.
If all goes well, I can slowly release it.
Please review again.


preview_anonymous_user_id = 'student'
if individualize_anonymous_user_id(course_id):
preview_anonymous_user_id = anonymous_id_for_user(request.user, course_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schenedx In order to ensure the same anonymous ID is used in Studio as in the LMS, you need to check the block descriptor to find out whether the anonymous user ID should be course-specific or not.

Suggested change
preview_anonymous_user_id = anonymous_id_for_user(request.user, course_id)
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you for pointing this out! This just points out my lack of knowledge in this area.
Made the change and please review again @pomegranited

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @schenedx -- I can review the code, but need a functional LTI provider in order to test it. And since Open edX no longer supports this with the new Learner MFE, I need your help with this step.

Can you provide a secret:key and URL that I can use to test this from my devstack?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited You can use https://saltire.lti.app/tool (check this URL for config parameters, but the values below should work).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the best @giovannicimolin !

@pomegranited

pomegranited commented May 11, 2022

Copy link
Copy Markdown
Contributor

@schenedx

To limit the potential ramification of this change, I am putting the change behind a course waffle flag to test out on stage and prod.

Great idea!

Could you flesh out your PR description to provide full Testing Instructions for how to verify this change? It'll be useful for anyone looking to figure out the history of this request.

@pomegranited pomegranited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provisional 👍 : Works perfectly! Just needs tests added, see schen/MST-1455...open-craft:jill/schen/MST-1455

  • I tested this on my devstack using the LTI Test tool described here.
  • I read through the code
  • I checked for accessibility issues N/A
  • Includes documentation for the new course waffle flag added.

@schenedx FYI, I don't have merge rights on edx-platform, so you'll still need a core committer or someone at 2U/edX to approve this.

preview_anonymous_user_id = anonymous_id_for_user(request.user, None)
else:
preview_anonymous_user_id = anonymous_id_for_user(request.user, course_id)

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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.

and the INDIVIDUALIZE_ANONYMOUS_USER_ID flag.

Co-authored-by: Jillian Vogel <jill@opencraft.com>
@schenedx
schenedx merged commit 4f339e2 into master May 16, 2022
@schenedx
schenedx deleted the schen/MST-1455 branch May 16, 2022 14:37
@schenedx

Copy link
Copy Markdown
Contributor Author

Merged! Once it deploys to prod. I'll start adding in CourseWaffleFlags and see what happens

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

1 similar comment
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@connorhaugh

Copy link
Copy Markdown
Contributor

Creating A Revert PR as this has potentially caused an outage in the content store.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

jawad-khan pushed a commit that referenced this pull request Jun 14, 2022
* feat: test out individualized anonymouse_user_id for studio preview on xblocks

* test: adds tests for the PreviewModuleSystem anonymous_user_id (#30400)

and the INDIVIDUALIZE_ANONYMOUS_USER_ID flag.

Co-authored-by: Jillian Vogel <jill@opencraft.com>

Co-authored-by: Simon Chen <schen@edX-C02FW0GUML85.local>
Co-authored-by: Jillian Vogel <jill@opencraft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants