Skip to content

feat: add use of new filter for instructor dash tabs#38499

Open
holaontiveros wants to merge 11 commits into
openedx:masterfrom
WGU-Open-edX:feat/add-filter-instructor-tabs
Open

feat: add use of new filter for instructor dash tabs#38499
holaontiveros wants to merge 11 commits into
openedx:masterfrom
WGU-Open-edX:feat/add-filter-instructor-tabs

Conversation

@holaontiveros
Copy link
Copy Markdown
Contributor

@holaontiveros holaontiveros commented May 1, 2026

Description

In order to achieve openedx/frontend-app-instructor-dashboard#86 this PR will add use the new filter for the instructor dash tabs

depens on: openedx/openedx-filters#355

Once this is in place any operator / plugin creator can do something like:

# Add the pipeline step to the LMS configuration
hooks.Filters.ENV_PATCHES.add_item(
    (
        "openedx-lms-common-settings",
        """
# Custom tabs plugin configuration and pipeline step
import logging
from django.conf import settings

# Define the pipeline step class
class CustomTabsStep:
    def __init__(self, filter_type, running_pipeline, **kwargs):
        self.filter_type = filter_type
        self.running_pipeline = running_pipeline

    def run_filter(self, tabs, user, course_key, **kwargs):
        logger = logging.getLogger(__name__)
        logger.error(f"DEBUG: CustomTabsStep.run_filter called for user {user.username if hasattr(user, 'username') else 'unknown'}")

        modified_tabs = tabs.copy()

        # Check if user has permission
        user_has_access = (
            getattr(user, 'is_staff', False) or 
            getattr(user, 'is_superuser', False)
        )
        logger.error(f"DEBUG: User access check - is_staff: {getattr(user, 'is_staff', False)}, is_superuser: {getattr(user, 'is_superuser', False)}, has_access: {user_has_access}")

        if not user_has_access:
            logger.error("DEBUG: User does not have access to custom tabs")
            return {"tabs": modified_tabs}

        # Add custom tab
        custom_tab = {
            'tab_id': 'custom_analytics',
            'title': 'Custom Analytics',
            'url': f"{getattr(settings, 'CUSTOM_TABS_URL', '/instructor-dashboard/course-v1:OpenedX+DemoX+DemoCourse/custom_analytics')}",
            'sort_order': 120,
        }

        modified_tabs.append(custom_tab)
        logger.error(f"DEBUG: Added custom tab. Total tabs: {len(modified_tabs)}")

        return {"tabs": modified_tabs}

# Add the class to sys.modules so it can be imported by string
import sys
import types

# Create a module for our custom class
custom_module = types.ModuleType('custom_tabs_module')
custom_module.CustomTabsStep = CustomTabsStep
sys.modules['custom_tabs_module'] = custom_module

# Register the filter configuration
if "OPEN_EDX_FILTERS_CONFIG" not in locals():
    OPEN_EDX_FILTERS_CONFIG = {}

OPEN_EDX_FILTERS_CONFIG.update({
    "org.openedx.learning.instructor.dashboard.tabs.requested.v1": {
        "pipeline": [
            "custom_tabs_module.CustomTabsStep",
        ],
        "fail_silently": False,
    },
})
""",
    )
)

in whichever shape fits their need to be able to conditionally add or modify data of the tabs for the instructor dashboard.

Testing instructions

Note: to test this through the API or the UI edx-filters changes need to be in place

  • While having instructor dashbboard app and openedx-platform working add the example tutor-plugin from the description
  • Save configs
  • Restart server
  • Go to instructor dashboard, the new tab should be available

Take in account that the frontend should have a slot to manage the URL that it's being returned for example a slot like this

{
    slotId: 'org.openedx.frontend.slot.instructorDashboard.routes.v1',
    id: 'org.openedx.frontend.widget.instructorDashboard.route.custom_analytics',
    op: WidgetOperationTypes.APPEND,
    element: <PlaceholderSlot tabId="custom_analytics" content={<div>Dynamic Content</div>} />,
  }

is added to the frontend-base build then the custom_analytics from the path from the plugin example will match the tabId custom_analytics from here and the tab will be displayed

The API request that uses this is: http://local.openedx.io:8000/api/instructor/v2/courses/{:courseId}

Deadline

None

Other information

Include anything else that will help reviewers and consumers understand the change.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels May 1, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented May 1, 2026

Thanks for the pull request, @holaontiveros!

This repository is currently maintained by @openedx/wg-maintenance-openedx-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.

Details
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.

Copy link
Copy Markdown
Contributor

@wgu-taylor-payne wgu-taylor-payne left a comment

Choose a reason for hiding this comment

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

A couple of items to address, mostly around matching established conventions for filter consumers in this codebase. Also consider moving the filter call before the sort — currently plugin-added tabs will always appear at the end regardless of their sort_order, since the filter fires after sorting. No tests for the filter integration — other filter consumers in edx-platform have tests (e.g., test_instructor_dashboard.py tests InstructorDashboardRenderStarted).

Review assisted by Kiro

Comment thread lms/djangoapps/instructor/views/serializers_v2.py Outdated
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label May 7, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions May 7, 2026
@holaontiveros holaontiveros marked this pull request as ready for review May 11, 2026 16:17
@tonybusa tonybusa requested a review from a team May 12, 2026 19:03
Copy link
Copy Markdown
Contributor

@dwong2708 dwong2708 left a comment

Choose a reason for hiding this comment

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

I like how clever this PR is. Overall, it looks good — I just left a few comments.

Comment thread lms/djangoapps/instructor/views/serializers_v2.py Outdated
Comment thread lms/djangoapps/instructor/tests/views/test_api_v2.py Outdated
Comment thread lms/djangoapps/instructor/tests/test_api_v2.py Outdated
Comment thread common/djangoapps/util/tests/test_filters.py
Comment thread lms/djangoapps/instructor/views/serializers_v2.py Outdated
@kdmccormick
Copy link
Copy Markdown
Member

I see Taylor and Daniel are already reviewing. Did you need another reviewer or are you all set?

Comment thread lms/djangoapps/instructor/tests/views/test_api_v2.py
@holaontiveros
Copy link
Copy Markdown
Contributor Author

I see Taylor and Daniel are already reviewing. Did you need another reviewer or are you all set?

Taylor is on vacations and Daniel doesn't have CC rights (he is still taking the course) so I do need an approval and merge, the last round of changes from Daniel were addressed so I would expect to be ready

Copy link
Copy Markdown
Contributor

@dwong2708 dwong2708 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@kdmccormick kdmccormick requested review from kdmccormick and removed request for a team May 14, 2026 17:23
Comment on lines +312 to +317
filtered_tabs = InstructorDashboardTabsRequested.run_filter(
tabs=tabs,
user=request.user,
course_key=course_key
)
custom_tabs = filtered_tabs if filtered_tabs is not None else tabs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm pretty new to filters, so forgive me if I'm wrong, but my understanding is that the user and course_key params are also supposed to be passed through the filter as well. That way, other plugins can also add pipeline steps which all operate on the result of the previous pipeline steps.

Suggested change
filtered_tabs = InstructorDashboardTabsRequested.run_filter(
tabs=tabs,
user=request.user,
course_key=course_key
)
custom_tabs = filtered_tabs if filtered_tabs is not None else tabs
filtered_tabs, user, course_key = InstructorDashboardTabsRequested.run_filter(
tabs=tabs,
user=request.user,
course_key=course_key
)
custom_tabs = filtered_tabs if filtered_tabs is not None else tabs

I believe this would require fixing the upstream filter definition. Unlike the other filters I see in openedx-filters, InstructorDashboardTabsRequested.run_filter seems to just return the tabs. I'd expect it to return tabs, user, course_key.

Does that make sense, or am I off base here? @magajh , if you have a chance to look, let me know if you agree with my suggestion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I leav a quick link were Felipe Montoya also commented on that:

openedx/openedx-filters#355 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that the current code will superficially work in specific scenarios because of this clause in run_pipeline, which stops the filter if a non-dict is returned: https://github.com/openedx/openedx-filters/blob/8db18547dd8feb5c30e15e66e75c902388b267d0/openedx_filters/tooling.py#L211-L216.

So that will work OK if and only if:

  • the final InstructorDashboardTabsRequested pipeline step returns a just a list of tabs
  • the previous InstructorDashboardTabsRequested steps return the full (tabs, user, course_key) so that they can be passed on to the next filter pipeline steps

But we can't count on that always being the case. So in order to support multiple plugins adding pipeline steps to InstructorDashboardTabsRequested, I believe that the type signature of each pipeline step should take and return the same thing. That's why the convention exists, even if a bit cumbersome: it lets the pipeline steps flow together, ignorant to what filter step comes before or after them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now I'm in doubt myself. I'll need to dive deep into the pipeline definition to see how it behaves in this case.

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

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

7 participants