Skip to content

Conversation

@pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Nov 22, 2021

Description

Builds on the shim added by https://github.com/edx/edx-platform/pull/29190 to deprecate these remaining user-related ModuleSystem attributes in favour of the user service:

  • user_location
  • get_real_user
  • get_user_role

These properties are only used by a few XBlocks: LTI, LTI2.0, Video (CDN/branding), edxnotes

This change is only a refactoring, and should not affect Learners, Course Authors, or anyone else using edx-platform.

Supporting information

Testing instructions

Basic regression testing can be run on the sandbox.

To test the LTI 2.0 (consumer) component:

  1. View the LTI component in Studio.
    Note that the LTI URL points to a problem block on a different sandbox server's Demo course.
  2. Ensure you can edit the component, preview it, view it in the LMS, and submit answers to the problems shown.

To test edx-notes:

  1. Login to LMS as a student user.
  2. View the BD-13 test course in the LMS.
  3. Navigate to an HTML block, select some text, and ensure you can add/edit notes.
  4. Toggle the hide/show notes button in the lower right corner to hide/show notes.
  5. Click on the Notes tab and ensure your notes are visible there.

To test the video CDN/branding:

You need to view the site from one of the CDN-configured countries, currently Australia (AU), Pakistan (PK), or Poland (PL).

Note: I don't really have a valid CDN to use here, but enabling a CDN allows a configured branding logo to be shown under the video, so this at least is visible and can be tested.

  1. View the test Video in the LMS.
    Note that the configured branding logo is shown under the video when you view this content from one of the configured countries.

Deadline

None

Author Notes & Concerns

Setup for user location/CDN testing:

  1. Update EDXAPP_VIDEO_CDN_URLS or /edx/etc/lms.yml to provide a CDN URL for a given country code (doesn't matter what the URL is), eg.
    VIDEO_CDN_URL:
      AU: http://example.com/edx/video?s3_url=
  2. As a superuser, navigate to Django Admin > Branding > Branding Info Config, and add a branding url, logo, and logo_tag for your country, e.g.
    {
       "AU": {
         "url": "https://www.sa.gov.au",
         "logo_src": "https://www.sa.gov.au/__data/assets/image/0012/251013/sa-logo.png",
         "logo_tag": "Logo for South Australia"
       }
     }

@openedx-webhooks
Copy link

openedx-webhooks commented Nov 22, 2021

Thanks for the pull request, @pomegranited! I've created BLENDED-1020 to keep track of it in Jira. More details are on the BD-13 project page.

When this pull request is ready, tag your edX technical lead.

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program needs triage labels Nov 22, 2021
@pomegranited pomegranited marked this pull request as draft November 22, 2021 07:49
@pomegranited pomegranited marked this pull request as ready for review November 25, 2021 07:40
@pomegranited
Copy link
Contributor Author

Thanks for your detailed review @Agrendalath ! I've addressed your points, and deployed a new appserver. Could you activate that one and use it for your testing?

Also, I'd like to squash my commits before merging, so let me know when you're ready for me to do that?

Copy link
Member

@Agrendalath Agrendalath left a comment

Choose a reason for hiding this comment

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

👍

  • I tested this: verified that the refactored properties are working correctly
  • I read through the code
  • I checked for accessibility issues: n/a
  • Includes documentation
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository: n/a

@Agrendalath
Copy link
Member

@pomegranited, thank you for preparing the sandbox instance and nice testing instructions! Feel free to squash the commits.

I've noticed an odd behavior of the LTI provider, though it doesn't seem to be related to this PR. When I"m opening the LTI XBlock in the LMS as a "staff" user - it's working correctly. However, when I'm using the "audit", then I'm getting an error page. There is the following traceback on the pr29260 instance:

Traceback (most recent call last):
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/lti_provider/users.py", line 31, in authenticate_lti_user
    lti_user = LtiUser.objects.get(
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
lms.djangoapps.lti_provider.models.LtiUser.DoesNotExist: LtiUser matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/newrelic/hooks/framework_django.py", line 562, in wrapper
    return wrapped(*args, **kwargs)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/util/views.py", line 188, in inner
    response = view_func(request, *args, **kwargs)
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/lti_provider/views.py", line 91, in lti_launch
    authenticate_lti_user(request, params['user_id'], lti_consumer)
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/lti_provider/users.py", line 37, in authenticate_lti_user
    lti_user = create_lti_user(lti_user_id, lti_consumer)
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/lti_provider/users.py", line 59, in create_lti_user
    edx_user = User.objects.create_user(
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/contrib/auth/models.py", line 152, in create_user
    return self._create_user(username, email, password, **extra_fields)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/contrib/auth/models.py", line 146, in _create_user
    user.save(using=self._db)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 67, in save
    super().save(*args, **kwargs)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 726, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 774, in save_base
    post_save.send(
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 180, in send
    return [
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/enterprise/decorators.py", line 88, in wrapper
    signal_handler(*args, **kwargs)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/enterprise/signals.py", line 68, in handle_user_post_save
    for pending_ecu in pending_ecus:
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
    self._fetch_all()
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 78, in _execute
    self.db.validate_no_broken_transaction()
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/base/base.py", line 447, in validate_no_broken_transaction
    raise TransactionManagementError(
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

@pomegranited
Copy link
Contributor Author

pomegranited commented Dec 17, 2021

Thanks for your review @Agrendalath ! I've rebased and squashed my commits, so this should be ready to merge once tests pass again.

I've noticed an odd behavior of the LTI provider, though it doesn't seem to be related to this PR.

The sandbox for https://github.com/edx/edx-platform/pull/29260 is the LTI provider for the LTI problem used here. I rebased that PR on latest master and redeployed it -- and it's working now for student and staff users.

@pomegranited
Copy link
Contributor Author

@ormsbee Are you ok with @Agrendalath merging this PR (and https://github.com/edx/edx-platform/pull/29312), or would you rather deploy them on your timeline? I don't want to mess up anyone's holiday :) But it would be great to get these in soon.

Deprecates these ModuleSystem attributes in favor of the user service:

* user_location
* get_real_user
* get_user_role

Related changes:

* Stores the user location into DjangoXBlockUserService's optional attribute as request_country_code
* Uses the student model's user_by_anonymous_it to fetch the (cached) real user
* Updates affected tests
@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@Agrendalath
Copy link
Member

@jristau1984, I'm merging this, as discussed on Slack.

@Agrendalath Agrendalath merged commit f828d89 into openedx:master Dec 20, 2021
@Agrendalath Agrendalath deleted the jill/bd-13-real-user branch December 20, 2021 14:41
@openedx-webhooks
Copy link

@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
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
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blended PR is managed through 2U's blended developmnt program merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants