Skip to content

Conversation

@tecoholic
Copy link
Contributor

@tecoholic tecoholic commented Apr 25, 2022

Description

The hostname attribute was needed for OAuth in the LTI Module and was
being passed via the x_module.ModuleSystem class as a mixin. This attribute has been removed.
It has been replaced in the xmodule.lti_module with get_current_request_hostname utility function.

This change affects only the module_renderer module of the LMS which is also updated to initialize the XBlocks without passing the hostname attribute anymore.

This shouldn't cause any changes for any users and should continue to work just as usual.

Supporting information

Testing instructions

  1. Set your dev environment to master branch.
  2. Add "lti" to the Advanced Module List in the Advanced Settings. (NOT lti_consumer which is an independent xblock, this PR deals with the old lti module)
  3. Scroll down to LTI Passports and add a new entry "saltire:consumer_key:secret". We will be using the Saltire Tool Emulator to test the changes
  4. Save Changes
  5. Add a new new unit to your test course and select Advanced -> LTI
  6. Click Edit and enter the following details and save the block
    • LTI ID: saltire
    • LTI URL: https://saltire.lti.app/tool
    • Open in New Page: False
  7. Once Saltire loads in the block, make sure Verification is show as Passed
  8. Save and publish the unit.
  9. Open the unit in LMS and expand the Message Parameters in the Saltire Block. Note the value of resource_link_id. It should be something like {hostname}-{random-hash-value}. Eg., when testing from local devstack localhost%3A18000-71e809b7a55442afaa590a477145bb6c
  10. Now checkout the edx-platform to the PR branch open-craft:tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem
  11. Restart your studio & lms services to make sure they are loading the changes from PR.
  12. Refresh the LMS page with Saltire and expand the Message Parameters once again
  13. Compare the resource_link_id show with the old value. Both should have the same {hostname} part.
  14. You can create a new Unit + LTI Block after the PR branch has been checked out to ensure hostname value is populated as expected.

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Apr 25, 2022
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 25, 2022

Thanks for the pull request, @tecoholic! I've created BLENDED-1215 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.

@tecoholic tecoholic force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 19b233c to cd7d8bc Compare April 25, 2022 04:14
@tecoholic tecoholic changed the title [WIP] [BD-13] [BB-6144] deprecate hostname attribute from xmodule ModuleSystem [BD-13] [BB-6144] deprecate hostname attribute from xmodule ModuleSystem Apr 25, 2022
@openedx-webhooks openedx-webhooks added needs triage and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Apr 25, 2022
@Agrendalath Agrendalath force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from cd7d8bc to 9ba382e Compare April 29, 2022 12:58
@Agrendalath
Copy link
Member

Agrendalath commented Apr 29, 2022

@tecoholic, this PR:

Changes the existing behavior of the LTI XBlock in Studio and Preview

Assumptions:

  1. LMS URL is $DOMAIN.
  2. Studio URL is studio.$DOMAIN.
  3. Preview URL is preview.$DOMAIN.

The original LTIBlock provides the following Resource Link IDs:

  • LMS: $DOMAIN:$PORT-$HASH,
  • Studio: -$HASH,
  • Preview: $DOMAIN:$PORT-$HASH (same as LMS).

The version from this PR provides the following values:

  • LMS: $DOMAIN:$PORT-$HASH,
  • Studio: studio.$DOMAIN:$PORT-$HASH,
  • Preview: preview.$DOMAIN:$PORT-$HASH.

@giovannicimolin, would you mind commenting on this?

Breaks the LTI Consumer XBlock

Using the LTI Consumer XBlock (which is installed in the edx-platform by default) throws the AttributeError with the following message: 'CachingDescriptorSystem' object has no attribute 'hostname'
This XBlock is still using runtime.hostname for some reason. We should replace this call by creating a new service that will allow XBlocks to retrieve the hostname.

@tecoholic
Copy link
Contributor Author

@Agrendalath I was thinking using the get_current_request_hostname was probably not the best solution here after working on #30320. I think that reflects in your observations about the hostname changing when the view changes. I will try to see if there is a service already defined around the Django settings and use it to get the SITE_NAME just like the original code or create a new one to do that.

@tecoholic tecoholic force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 9ba382e to 30af6be Compare April 30, 2022 06:39
@tecoholic
Copy link
Contributor Author

tecoholic commented Apr 30, 2022

@Agrendalath I reworked the solution to use a new service called hostname which just returns the value of django.conf.settings.SITE_NAME.

  1. This is passed independently to the LMS module system and the CMS module system, which means, we will see different values for the resource id in studio, preview & LMS. I am not sure how to get around this.
  2. The service resolves to a string - which works fine for the requirement. However it is not a "service" in the sense as it is not a custom class with other methods.

Since there is already a SettingsService for fetching XBlock settings, I didn't want to create another one on top of the full "django.conf.settings". Also, it might be a security loophole for external XBlocks to simply import it. However if you think we should have something like

class HostnameService:
    def get_hostname(self):
        return settings.SITE_NAME

let me know. I will make the changes and update the PR.

@Agrendalath
Copy link
Member

@tecoholic,

This is passed independently to the LMS module system and the CMS module system, which means, we will see different values for the resource id in studio, preview & LMS. I am not sure how to get around this.

I am not sure how this affects the LTI functionality. Maybe it doesn't have any impact here. We should check this with @giovannicimolin.

The service resolves to a string - which works fine for the requirement. However it is not a "service" in the sense as it is not a custom class with other methods.

While the approach seems to be fine for a one-liner, I haven't found a service that would not return an instance of its class. I believe we should follow the official API here, and create the HostnameService(Service) instead. We should also make sure it can be accessed by pure XBlocks and add it here.

@tecoholic
Copy link
Contributor Author

@Agrendalath Agreed. I will update the PR with a proper service class.

@tecoholic tecoholic force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 30af6be to 87d5c55 Compare May 4, 2022 00:16
@tecoholic
Copy link
Contributor Author

@Agrendalath I have replaced the one-liner with HostnameService in xmodule.services with tests and also have included it in the XBlock Runtime.

@giovannicimolin
Copy link
Contributor

giovannicimolin commented May 5, 2022

@Agrendalath

The original LTIBlock provides the following Resource Link IDs:
LMS: $DOMAIN:$PORT-$HASH,
Studio: -$HASH,
Preview: $DOMAIN:$PORT-$HASH (same as LMS).
The version from this PR provides the following values:
LMS: $DOMAIN:$PORT-$HASH,
Studio: studio.$DOMAIN:$PORT-$HASH,
Preview: preview.$DOMAIN:$PORT-$HASH.
giovannicimolin, would you mind commenting on this?

The LTI spec, under section 3 mentions:

resource_link_id This is an opaque unique identifier that the TC guarantees will be unique within the TC for every placement of the link. If the tool / activity is placed multiple times in the same context, each of those placements will be distinct. This value will also change if the item is exported from one system or context and imported into another system or context. This parameter is required.

So, this implementation is more consistent and correct than the previous implementation, but there's a gotcha still: ideally, they should all be the same value since they represent the same placement in a course.

Studio and Preview values are not that important to keep the same, just make sure the LMS value doesn't change, otherwise students will lose their progress in the LTI tool.

@giovannicimolin
Copy link
Contributor

@schenedx Some changes are incoming to LTI consumer - should not impact end users though. See my comment above ^

@giovannicimolin
Copy link
Contributor

For reference: there's a thread open on the discussion forums about this parameter mismatch.

@schenedx
Copy link
Contributor

schenedx commented May 5, 2022

@giovannicimolin Thank you for the heads up. I read the comment above your comment. The consistency make sense to me because, through my own testing, I also noticed the value on the resource_link_id on Studio preview is missing hostname. I am supportive of this change.
I also want to make you and maybe others who are reviewing this change aware, that I have a sister PR that would make the attribute user_id on LTI to have the unique anonymous_user_id value on Studio Preview.

@Agrendalath
Copy link
Member

@ormsbee, this one is almost ready - we just need to replace one variable. mentioned here. Would you like to take a look at this before we merge it?

We'll also open a PR to the LTI Consumer XBlock, but it is going to be as small as openedx/xblock-lti-consumer#249.

@tecoholic tecoholic force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch 2 times, most recently from 4205f56 to 59c8a60 Compare May 10, 2022 20:45
@Agrendalath Agrendalath force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 59c8a60 to 004213c Compare May 11, 2022 16:53
@Agrendalath
Copy link
Member

Agrendalath commented May 11, 2022

@tecoholic, please look into the following failing tests:

  • common/lib/xmodule/xmodule/tests/test_lti_unit.py::LTIBlockTest::test_lis_result_sourcedid
  • common/lib/xmodule/xmodule/tests/test_lti_unit.py::LTIBlockTest::test_successful_verify_oauth_body_sign

@tecoholic
Copy link
Contributor Author

@Agrendalath Talk about unintended consequences. The default SITE_NAME is just localhost but the LMS_BASE is localhost:18000. This changed the hash of the mock request body in the tests and a resource id to be URL encoded twice.

The tests are fixed now and pushed them as a separate commit.

@tecoholic
Copy link
Contributor Author

An unrelated test FAILED lms/djangoapps/discussion/django_comment_client/base/tests.py::TeamsPermissionsTestCase::test_update_thread_08___group_moderator____cohorted____course_commentable_id___200___cohort__ seems to be failing.

Maybe an effect of old code, should we rebase this onto master?

@natabene natabene assigned jristau1984 and unassigned jristau1984 May 14, 2022
tecoholic added a commit to open-craft/xblock-lti-consumer that referenced this pull request May 17, 2022
The hostname used to construct the resource link ID is moved from using
a runtime attribute to the new 'hostname' service as the former is
deprecated.

openedx/openedx-platform#30308
tecoholic added a commit to open-craft/xblock-lti-consumer that referenced this pull request May 20, 2022
The hostname used to construct the resource link ID is moved from using
a runtime attribute to the new 'hostname' service as the former is
deprecated.

openedx/openedx-platform#30308
@tecoholic tecoholic marked this pull request as draft May 26, 2022 06:42
@tecoholic
Copy link
Contributor Author

Moving this to draft as we found that this approach is not a good one.

@tecoholic tecoholic force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch 2 times, most recently from 52ab933 to bf1a72b Compare June 1, 2022 02:56
@Agrendalath Agrendalath marked this pull request as ready for review June 4, 2022 13:28
@Agrendalath Agrendalath force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from bf1a72b to bf8a158 Compare June 4, 2022 13:30
@Agrendalath
Copy link
Member

@ormsbee, would you like to take a look at this before we merge it?

@ormsbee
Copy link
Contributor

ormsbee commented Jun 6, 2022

@ormsbee, would you like to take a look at this before we merge it?

You can merge without me, just please make sure @jristau1984 is aware of when it's happening. Thank you.

Copy link
Contributor

@schenedx schenedx left a comment

Choose a reason for hiding this comment

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

👍

@Agrendalath Agrendalath force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 19e79fd to 6837930 Compare June 8, 2022 17:05
The hostname constructor argument of the XModule ModuleSystem is deprecated
in favour of directly accessing the LMS_BASE value from django.conf.settings.
@Agrendalath Agrendalath force-pushed the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch from 6837930 to 7b75183 Compare June 8, 2022 17:11
@Agrendalath Agrendalath merged commit aedcd79 into openedx:master Jun 8, 2022
@Agrendalath Agrendalath deleted the tecoholic/BB-6144-deprecate-hostname-in-ModuleSystem branch June 8, 2022 17:50
@openedx-webhooks
Copy link

@tecoholic 🎉 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.

xitij2000 pushed a commit to open-craft/xblock-lti-consumer that referenced this pull request Oct 27, 2022
The hostname used to construct the resource link ID is moved from using
a runtime attribute to the new 'hostname' service as the former is
deprecated.

openedx/openedx-platform#30308
xitij2000 pushed a commit to open-craft/xblock-lti-consumer that referenced this pull request Nov 4, 2022
The hostname used to construct the resource link ID is moved from using
a runtime attribute to the new 'hostname' service as the former is
deprecated.

openedx/openedx-platform#30308
xitij2000 pushed a commit to open-craft/xblock-lti-consumer that referenced this pull request Nov 16, 2022
The hostname used to construct the resource link ID is moved from using
a runtime attribute to the new 'hostname' service as the former is
deprecated.

openedx/openedx-platform#30308
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

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants