Skip to content
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

feat: Add REST APIs for course advanced settings and course tabs [BD-38] [TNL-8625] [BB-4132] #27608

Merged
merged 1 commit into from
Aug 31, 2021

Conversation

xitij2000
Copy link
Contributor

@xitij2000 xitij2000 commented May 12, 2021

This PR adds new APIs that allow MFEs to access and update course advanced settings, and to get the course tabs and show/hide/reorder them.

Sandbox URL:

Merge deadline: "None"

Testing instructions:

  1. Run the added unit tests.
  2. You can see the data about all available course advanced settings using the same format used by studio by visiting: http://localhost:18010/api/contentstore/v0/advanced_settings/course-v1:edX+DemoX+Demo_Course
  3. You can make a post request to the above using data formatted as:
{
  "disable_progress_graph": {
     "value": false  
   }
}
  1. Check that the list of tabs and their settings in the course using the tabs api: http://localhost:18010/api/contentstore/v0/tabs/course-v1:edX+DemoX+Demo_Course
  2. Try hiding a tab by posting ``{"is_hidden": true"}` to http://localhost:18010/api/contentstore/v0/tabs/course-v1:edX+DemoX+Demo_Course/settings?tab_id=progress
  3. The tab should be hidden from the UI
  4. Test rearranging tabs by posting a new tab order to http://localhost:18010/api/contentstore/v0/tabs/course-v1:edX+DemoX+Demo_Course/reorder eg:
[
    {
        "tab_id": "info"
    },
    {
        "tab_id": "courseware"
    },
    {
        "tab_id": "wiki"
    },
    {
        "tab_id": "discussion"
    },
    {
        "tab_id": "progress"
    }
]

Reviewers

  • (OpenCraft internal reviewer's GitHub username goes here)
  • edX reviewer[s] TBD

TNL-8625

@openedx-webhooks
Copy link

openedx-webhooks commented May 12, 2021

Thanks for the pull request, @xitij2000! I've created BLENDED-841 to keep track of it in Jira. More details are on the BD-38 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 May 12, 2021
@xitij2000 xitij2000 force-pushed the kshitij/bb-4132/studio-apis branch 2 times, most recently from e3668d1 to 6744cc4 Compare May 13, 2021 11:00
Copy link
Contributor

@stvstnfrd stvstnfrd left a comment

Choose a reason for hiding this comment

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

just passing by...

openedx/core/lib/api/view_utils.py Outdated Show resolved Hide resolved
@@ -4,10 +4,12 @@

from django.urls import include, re_path

from .v0 import urls as v0_urls
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're creating a new API endpoint, shouldn't that use a higher number instead of a lower number?
If the first/pre-existing value was 1, I'd assume the list was 1-indexed and the next number should be 2, not 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've called it v0 because in this case, the API is just exposing an existing endpoint without too much thought put into the structure of the response etc. It's so we can get started with using this from MFEs quicker. I'd expect a v1 of the API as the next iteration that optimises how this works in a way that works better for MFEs.

For instance, I'd expect this API to be split into multiple other APIs, one for each app that can be used to configure it, instead of one single API for all misc operations.

On the other hand, if we can maintain this API as-is, I don't see any reason to not call it v1, and just do the next iteration as v2.

if 'tab_id' in tab_id_locator:
tab = CourseTabList.get_tab_by_id(tab_list, tab_id_locator['tab_id'])
elif 'tab_locator' in tab_id_locator:
tab = get_tab_by_locator(tab_list, tab_id_locator['tab_locator'])
return tab


def get_tab_by_locator(tab_list, usage_key_string):
def get_tab_by_locator(tab_list: List[CourseTab], usage_key_string: str) -> Optional[CourseTab]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I dig all the added type hints!

@xitij2000 xitij2000 force-pushed the kshitij/bb-4132/studio-apis branch from 6744cc4 to 621a764 Compare May 14, 2021 06:25
Copy link
Contributor

@kewne kewne left a comment

Choose a reason for hiding this comment

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

LGTM, only minor suggestions.

@asadazam93
Copy link
Contributor

@xitij2000 Can you please add a more detailed description of this PR? There are a lot of changes and it seems to me it is exposing an api for advanced settings, but I have no context like, where will this api be used? what fields do we need in the API? etc

Copy link
Contributor

@awaisdar001 awaisdar001 left a comment

Choose a reason for hiding this comment

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

@xitij2000 I had a bunch of questions for this PR, sorry. I am missing some context and information about this PR and linked ticket.

@xitij2000 xitij2000 force-pushed the kshitij/bb-4132/studio-apis branch 4 times, most recently from 673bd1c to ac08deb Compare May 21, 2021 08:17
Copy link
Contributor

@awaisdar001 awaisdar001 left a comment

Choose a reason for hiding this comment

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

Hi @xitij2000 added a few questions and concerns, no major blockers.

@xitij2000 xitij2000 force-pushed the kshitij/bb-4132/studio-apis branch 2 times, most recently from 807e64c to 4fcce00 Compare June 7, 2021 08:42
@xitij2000
Copy link
Contributor Author

jenkins run python

@xitij2000
Copy link
Contributor Author

@awaisdar001 Is this good to merge?

@awaisdar001
Copy link
Contributor

@awaisdar001 Is this good to merge?

I am taking a look what have left here.

@xitij2000
Copy link
Contributor Author

@xitij2000 Is it possible to move the course tabs related apis to a separate PR? Since we do not need that right now.

It is definitely possible, but I think it's a fine balance whether it's more effort to split the PR or review it as is.

If it's a matter of review capacity, I think @Agrendalath can help with the review as a core committer.

Copy link
Contributor

@awaisdar001 awaisdar001 left a comment

Choose a reason for hiding this comment

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

I think we need to address the following concerns / questions before merging this.

  1. The size (in terms of data) of the v0/advanced_settings is a concern. Its 48kb call comparing with 1.7kb call for pages & resources. Do you think we can cap this call with list of fields/advance settings we need just how e.g. facebook cap the calls to the fields which are most-relevant/requested by end user? Do you think we need all these settings? Can this call be capped? This will help in decreasing the api call size as well as it'd be easier process the data.

we can keep the "Return all fields" feature as well if user doesn't specify any fields, but i think its a good-to-have feature given the data-size.

Screen Shot 2021-08-16 at 5 34 38 PM

  1. I have a question regarding the params passed for toggling the settings. there are 2 types of params used for the POST request. Query & Post Request params. Can you explain why its make more sense to pass tab_id=progress as query param and toggle settings is_hidden as request.post param Vs passing both as request.post params? v0/tabs/

  2. As python maintains ordering in the list, don't you think it'd be easier to pass ordering as a list of tab_ids? e.g. [tab_id_1, tab_id_2] rather the current list-of-objects?

@Agrendalath
Copy link
Member

If it's a matter of review capacity, I think @Agrendalath can help with the review as a core committer.

@xitij2000, sure, feel free to ping me if we need an additional review.

@xitij2000
Copy link
Contributor Author

xitij2000 commented Aug 18, 2021

@awaisdar001
I think the issue here is that we had a very specific scope for this PR, which is explained in the ADR I created for this work: https://github.com/edx/edx-platform/pull/27129

The idea was to speed up work on pages and resources, we can take the existing studio APIs for course advanced settings and tabs and expose them via new API endpoints that can be use by MFE.

So the aim was for this to be a stopgap v0 API, since it's a small bit of work, and unblocks further progress here. Future iterations of the APIs can be created with a new design. So the size of the API etc are the same as the existing APIs, since it was never the aim to change them.

I think the best time to advocate for such a change in approach would have been during the ADR phase, since once it was approved we started work on that basis, and at that stage it would have been easier to build the APIs with these changes in mind.

Do you think we need all these settings? Can this call be capped?

No we don't need all these settings, and this call can be capped, will update this to add that.

I have a question regarding the params passed for toggling the settings. there are 2 types of params used for the POST request. > Query & Post Request params. Can you explain why its make more sense to pass tab_id=progress as query param and toggle > settings is_hidden as request.post param Vs passing both as request.post params?

I've split them this way since the tab id or tab location is specifying the resource, while the actual data is part of the post body.

As python maintains ordering in the list, don't you think it'd be easier to pass ordering as a list of tab_ids? e.g. [tab_id_1, tab_id_2] rather the current list-of-objects?

Sure, however we can have a mix of tab ids and tab locations, which are usage keys, so we need to know if it's a tab_id or a tab_location, so we specify it in an object structure to be clear.

Copy link
Contributor

@asadazam93 asadazam93 left a comment

Choose a reason for hiding this comment

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

Looks good

@asadazam93
Copy link
Contributor

@xitij2000 Is this ready to be merged?

@xitij2000
Copy link
Contributor Author

@xitij2000 Is this ready to be merged?

I am currently working on updating the PR to allow partial queries. Will push that change soon.

@xitij2000 xitij2000 force-pushed the kshitij/bb-4132/studio-apis branch 3 times, most recently from 6af8912 to 090c727 Compare August 20, 2021 13:13
@xitij2000
Copy link
Contributor Author

@xitij2000 Is this ready to be merged?

I've updated the PR to add support for filtering fields.

@awaisdar001
Copy link
Contributor

thanks for the improvement @xitij2000 - i'll review the changes on my devstack today.

@awaisdar001
Copy link
Contributor

Looks good to me 👍

This commit adds new APIs that allow MFEs to modify a course's advanced settings
and to update tab settings to show/hide/move tabs.
@edx-status-bot
Copy link

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

@xitij2000
Copy link
Contributor Author

xitij2000 commented Aug 31, 2021

@awaisdar001 This is good to merge from my side.

@awaisdar001 awaisdar001 merged commit 8cf751a into openedx:master Aug 31, 2021
@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.

None yet