Skip to content

Conversation

@sundarthapa2u
Copy link

@sundarthapa2u sundarthapa2u commented Oct 23, 2025

Dual call for gating content logic

  • One with None (to fetch all blocks).
  • One with request.user (to fetch only visible blocks).
    Compared both trees to identify which units/sections are hidden for the current user.

Previous API example

{
    "blocks": {
        "block-v1:edx+ORA101+2025_09+type@course+block@course": {
            "children": [
                "block-v1:edx+ORA101+2025_09+type@chapter+block@1530cc5e2c1e471fa07c7e9abf9ed5f9"
            ],
            "complete": false,
            "description": null,
            "display_name": "test  course",
            "due": null,
            "effort_activities": null,
            "effort_time": null,
            "icon": null,
            "id": "block-v1:edx+ORA101+2025_09+type@course+block@course",
            "lms_web_url": null,
            "resume_block": false,
            "type": "course",
            "has_scheduled_content": null,
            "hide_from_toc": false,
            "completion_stat": {
                "completion": 0,
                "completable_children": 1
            }
        }
}

After API example

{
    "blocks": {
        "block-v1:edx+ORA101+2025_09+type@course+block@course": {
            "children": [
                "block-v1:edx+ORA101+2025_09+type@chapter+block@1530cc5e2c1e471fa07c7e9abf9ed5f9"
            ],
            "complete": false,
            "description": null,
            "display_name": "test  course",
            "due": null,
            "effort_activities": null,
            "effort_time": null,
            "icon": null,
            "id": "block-v1:edx+ORA101+2025_09+type@course+block@course",
            "lms_web_url": null,
            "resume_block": false,
            "type": "course",
            "has_scheduled_content": null,
            "hide_from_toc": false,
            "ïs_gated": false
            "completion_stat": {
                "completion": 0,
                "completable_children": 1
            }
        }
}

NOTE: is_gated flag

'type': block_type,
'has_scheduled_content': block.get('has_scheduled_content'),
'hide_from_toc': block.get('hide_from_toc'),
'is_gated': block.get('is_gated', False),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would rethink the name is_gated as it doesn't have as much intrinsic meaning / it differs from the other teminology we use across the platform. Perhaps something like is_restricted or access_restricted which is more explicit.

Comment on lines +479 to +482
def collect_ids(block):
visible_ids.add(block['id'])
for child in block.get('children', []):
collect_ids(child)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be made significantly more efficient. This PR changes from traversing the entire course tree twice to traversing four times times. I'm going to challenge you to think about modifying the get or filter steps to preserve the metadata you want.

@nsprenkle
Copy link
Contributor

Another comment: this should (probably) be feature-flagged or have some other way of selectively including / excluding these fields for use-cases that don't want them.

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.

2 participants