Skip to content

Conversation

@marslanabdulrauf
Copy link
Contributor

@marslanabdulrauf marslanabdulrauf commented Nov 11, 2025

Related Ticket (Internal):

https://github.com/mitodl/hq/issues/9178

Description

This PR adds bidirectional sync for common settings that can be control from both "Pages & Resources" page and advanced settings page.
It updates:

  1. Advanced_settings PATCH request to update corresponding course_app status if exists
  2. Adds advance setting key/field in plugins to identify its related setting
  3. Adds a new function in PluginManager to return the mappings for course advance setting -> plugin app

Steps to Reproduce

  1. Go to the Pages & Resources section of a course
  2. Change the flags for Notes and Calculator each to be disabled.
  3. Go to Settings -> Advanced Settings
  4. Find "Enable student notes" - the field should read "false"
  5. Change the field to "true"
  6. Find "Show calculator" - the field should read "false"
  7. Change the field to "true"
  8. Save changes
  9. Go back to Content -> Pages & Resources
  10. Open the settings for Notes and Calculator - both will be disabled.
  11. View the course live and go to any unit.
  12. Both the calculator and Notes feature will be available.
  13. Go back to the Pages & Resources
  14. Change the setting on Notes to first be enabled (save), and then disabled again (save again)
  15. Viewing the advanced settings page will show that notes are now disabled.
  16. View the course live.
  17. Notes will be disabled.
  18. Repeat step 14-17 for calculator and it will also be disabled.

Expected Behavior

The two settings should match - changing the state of the setting in Advanced Settings should update the setting on Pages & Resources.

For a working example, see "Flexible peer grading for ORAs" - which links to "Force Flexible Grading for Peer ORAs" in the advanced settings. Changing the setting on Pages & Resources to disabled or enabled will change the setting in Advanced Settings to true or false.

Actual Behavior

Changing the settings for calculator and notes within Advanced Settings does not change the settings on Pages & Resources. The course will update based on what is in the Advanced Settings, meaning that there can be a mismatch between the two settings but the course will always follow the flag in the Advanced Setting.

Updating the flag in Pages & Resources will update the Advanced Settings.

Testing instructions

  1. Follow the steps to reproduce after checkout to this branch
  2. Verify that updating advance_settings also updates related/corresponding course app status as well

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 11, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @marslanabdulrauf!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Nov 11, 2025
@marslanabdulrauf marslanabdulrauf force-pushed the marslan/9178-setting-sync branch 2 times, most recently from c3a2979 to 9254e20 Compare November 13, 2025 11:17
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 13, 2025
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Nov 13, 2025
@marslanabdulrauf marslanabdulrauf force-pushed the marslan/9178-setting-sync branch 3 times, most recently from a5089b3 to 456a2db Compare November 17, 2025 20:22
@marslanabdulrauf marslanabdulrauf force-pushed the marslan/9178-setting-sync branch from 456a2db to 67a8d08 Compare November 17, 2025 20:22
except ValidationError:
# Failed to update the course app status,
# we ignore and let the normal flow handle updates
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that ValidationErrors are thrown by update_course_advanced_settings -- and not caught elsewhere. Shouldn't we follow the same pattern?

If not, then at the very least we should probably log a warning here? The silent catch makes it much harder to troubleshoot issues.

)
# enabling/disabling the course app setting also updates
# the advanced settings, so we remove it from the request data
request.data.pop(setting)
Copy link
Contributor

Choose a reason for hiding this comment

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

This side-effect is unfortunate and hard to understand.

raise ValidationError({"id": "Invalid app ID"})
is_enabled = set_course_app_enabled(course_key=course_key, app_id=app_id, enabled=enabled, user=request.user)

is_enabled = set_course_app_status(course_key=course_key, app_id=app_id, enabled=enabled, request=request)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why all the named arguments? The set_course_app_status function has only positional arguments.

(same for the other call to set_course_app_status above)

return enabled


def set_course_app_status(course_key, app_id, enabled, request):
Copy link
Contributor

Choose a reason for hiding this comment

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

The request object is only useful to capture the actual user. So instead of passing the full request object, I suggest we pass just the user.

except PluginError:
course_app = None
if not course_app or not course_app.is_available(course_key):
raise ValidationError({"id": "Invalid app ID"})
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest the following:

 try:
    course_app = CourseAppsPluginManager.get_plugin(app_id)
except PluginError:
    raise ValidationError({"id": f"Invalid app ID={app_id]"})
if not course_app.is_available(course_key):
    raise ValidationError({"id": f"Unavailable app ID={app_id}"})

settings_mapping = {}

for plugin in super().get_available_plugins().values():
if hasattr(plugin, 'advanced_setting_field') and plugin.advanced_setting_field:
Copy link
Contributor

Choose a reason for hiding this comment

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

if getattr(plugin, "advanced_setting_field", None):
    ...

if not course_app or not course_app.is_available(course_key):
raise ValidationError({"id": "Invalid app ID"})

return set_course_app_enabled(course_key=course_key, app_id=app_id, enabled=enabled, user=request.user)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why all the named arguments?

}
# Advanced setting field name that corresponds to this app (optional)
# Should be a string representing the field name in course advanced settings
advanced_setting_field = None
Copy link
Contributor

Choose a reason for hiding this comment

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

All the attributes in this class are typed, and this one should be as well:

advanced_setting_field: str | None = None

if not has_studio_write_access(request.user, course_key):
self.permission_denied(request)

course_app_settings_map = CourseAppsPluginManager.get_course_app_settings_mapping()
Copy link
Contributor

Choose a reason for hiding this comment

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

There are several issues here:

  1. Why is there a big piece of code right in the middle of this otherwise simple function for a change that would happen very infrequently? At the very least, this piece of code should be in a separate function.
  2. But then, this separate function should not modify the request object. This is a side effect that is too hard to understand.
  3. Why are we collecting all advanced settings in a single dictionary? This looks like the wrong API to me. Instead, we could write:
apps_to_toggle:: list[tuple[str, bool]] = []
for advanced_setting, setting_enabled in request.data.items():
    # note how get_advanced_app_id returns str | None
    if app_id := CourseAppsPluginManager.get_advanced_app_id(advanced_setting): 
        course_app_enabled = setting_enabled.get("value")
        if course_app_enabled is not None:
            apps_to_toggle.append((app_id, course_app_enabled))
for app_id, is_enabled in apps_to_toggle:
    set_course_app_status(course_key, app_id, is_enabled, request.user)

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

Labels

needs reviewer assigned PR needs to be (re-)assigned a new reviewer open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants